<commit_before>#!/bin/sh
# Generate eReuseOS ISO.
#
# Based on instructions from
# <https://help.ubuntu.com/community/LiveCDCustomization>.

set -e

# Configurable regional settings.
KB_LAYOUT=${KB_LAYOUT:-us}  # see available in ``/usr/share/X11/xkb/symbols``
LOCALE=${LOCALE:-en_US.UTF-8}
TIMEZONE=${TIMEZONE:-Etc/UTC}

# Configurable settings.
WORK_DIR=${WORK_DIR:-dist/iso}

# Version-specific settings.
VERSION=$(cd erwb && python -Bc 'from __init__ import get_version; print get_version()')
BASE_ISO_URL="http://ubuntu-mini-remix.mirror.garr.it/mirrors/ubuntu-mini-remix/15.10/ubuntu-mini-remix-15.10-i386.iso"
BASE_ISO_SHA256="e9985f0bcb05678d87d62c3d70191aab7a80540dc17523d93c313aa8515e173e"

# Other derived values.
SDIST=$(find "dist/ereuse-workbench-$VERSION.tar.gz")  # fail if missing
BASE_ISO_PATH="$WORK_DIR/$(basename "$BASE_ISO_URL")"
BASE_ISO_SHA256SUM="$BASE_ISO_SHA256  $BASE_ISO_PATH"
ISO_PATH="$WORK_DIR/eReuseOS-$VERSION.iso"


if [ "$(whoami)" != "root" ]; then
    echo "Please run this script as root." >&2
    exit 1
fi

cat << 'EOF'

**WARNING:** Please run this script UNDER YOUR OWN RESPONSIBILITY.  Beware
that you may be exposed to security attacks if the base ISO image is
compromised (although the image's SHA256 hash is checked before using it).

EOF
read -p "Press Enter to continue, Ctrl+C to abort." dummy


if git submodule status | grep -q '^-'; then
    echo "Please check out Git submodules." >&2
    exit 1
fi
genisoimage --version > /dev/null  # fail if missing
mksquashfs -version > /dev/null  # fail if missing

mkdir -p "$WORK_DIR"

# Download the base ISO.
while ! echo "$BASE_ISO_SHA256SUM" | sha256sum -c --quiet --status; do
    wget -c -O $BASE_ISO_PATH "$BASE_ISO_URL"
done

# Mount a writable version of the ISO and the FS in it.
ISO_RO=$(mktemp -d -p"$WORK_DIR")
ISO_RW_DATA=$(mktemp -d -p"$WORK_DIR")
ISO_RW_WORK=$(mktemp -d -p"$WORK_DIR")
ISO_ROOT=$(mktemp -d -p"$WORK_DIR")

mount -t iso9660 -o loop,ro $BASE_ISO_PATH $ISO_RO
mount -t overlay -o lowerdir=$ISO_RO,upperdir=$ISO_RW_DATA,workdir=$ISO_RW_WORK base-iso $ISO_ROOT

FS_RO=$(mktemp -d -p"$WORK_DIR")
FS_RW_DATA=$(mktemp -d -p"$WORK_DIR")
FS_RW_WORK=$(mktemp -d -p"$WORK_DIR")
FS_ROOT=$(mktemp -d -p"$WORK_DIR")

mount -t squashfs -o loop,ro $ISO_RO/casper/filesystem.squashfs $FS_RO
mount -t overlay -o lowerdir=$FS_RO,upperdir=$FS_RW_DATA,workdir=$FS_RW_WORK ereuse $FS_ROOT

# To customize filesystem.
alias ch="chroot $FS_ROOT env HOME=/root LC_ALL=C"
alias chi="ch apt-get install -y --no-install-recommends"

# Customization prerequisites.
ch dbus-uuidgen > $FS_ROOT/var/lib/dbus/machine-id
ch dpkg-divert --local --rename --add /sbin/initctl
ch ln -s /bin/true /sbin/initctl

# Disable swapping to disk in a systemd-friendly way.
# See <https://tails.boum.org/contribute/design/#index34h3>.
ch dpkg-divert --local --rename --add /sbin/swapon
ch ln -s /bin/true /sbin/swapon

# TODO manually update resolv.conf
ch rm /etc/resolv.conf  # in case it's a link
echo "nameserver  208.67.222.222" > $FS_ROOT/etc/resolv.conf

# Enable universe repository (/etc/apt/sources.list)
chi software-properties-common
ch add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(ch lsb_release -sc) universe"

# installation tools requirements (could be removed)
ch apt-get update
chi python-pip  # vim
# Install git (Garito)
chi git
ch git clone https://github.com/Garito/WorkbenchSneaky.git /home/ubuntu/WorkbenchSneaky
ch cat > /etc/systemd/WorkbenchSneaky.conf << "EOF"
start on runlevel [2345]
stop on runlevel [!2345]

exec python /home/ubuntu/WorkbenchSneaky/sneaky.py http://192.168.2.2:5000
EOF

# ereuse-workbench requirements
# TODO read from requirements.txt
chi $(sed -rn 's/.*\bdeb:(.+)$/\1/p' requirements.txt requirements-full.txt)

# Install Reciclanet's image installation script
install -m 0755 reciclanet-scripts/instalar $FS_ROOT/usr/local/bin/erwb-install-image

cp $SDIST $FS_ROOT/tmp
ch pip install --upgrade /tmp/$(basename $SDIST)
install -m 0755 scripts/erwb-keyboard-layout scripts/erwb-disk-dump $FS_ROOT/usr/local/sbin

# Configure regional settings
ch ckbcomp "$KB_LAYOUT" | gzip -c > $FS_ROOT/etc/console-setup/cached.kmap.gz

echo "$TIMEZONE" > $FS_ROOT/etc/timezone
ch debconf-set-selections << EOF
locales locales/locales_to_be_generated multiselect $LOCALE ${LOCALE##*.}
locales locales/default_environment_locale select $LOCALE
EOF

ch dpkg-reconfigure -f noninteractive tzdata locales<commit_msg>The startup script for the sneaky is resisting but being hunted<commit_after>#!/bin/sh
# Generate eReuseOS ISO.
#
# Based on instructions from
# <https://help.ubuntu.com/community/LiveCDCustomization>.

set -e

# Configurable regional settings.
KB_LAYOUT=${KB_LAYOUT:-us}  # see available in ``/usr/share/X11/xkb/symbols``
LOCALE=${LOCALE:-en_US.UTF-8}
TIMEZONE=${TIMEZONE:-Etc/UTC}

# Configurable settings.
WORK_DIR=${WORK_DIR:-dist/iso}

# Version-specific settings.
VERSION=$(cd erwb && python -Bc 'from __init__ import get_version; print get_version()')
BASE_ISO_URL="http://ubuntu-mini-remix.mirror.garr.it/mirrors/ubuntu-mini-remix/15.10/ubuntu-mini-remix-15.10-i386.iso"
BASE_ISO_SHA256="e9985f0bcb05678d87d62c3d70191aab7a80540dc17523d93c313aa8515e173e"

# Other derived values.
SDIST=$(find "dist/ereuse-workbench-$VERSION.tar.gz")  # fail if missing
BASE_ISO_PATH="$WORK_DIR/$(basename "$BASE_ISO_URL")"
BASE_ISO_SHA256SUM="$BASE_ISO_SHA256  $BASE_ISO_PATH"
ISO_PATH="$WORK_DIR/eReuseOS-$VERSION.iso"


if [ "$(whoami)" != "root" ]; then
    echo "Please run this script as root." >&2
    exit 1
fi

cat << 'EOF'

**WARNING:** Please run this script UNDER YOUR OWN RESPONSIBILITY.  Beware
that you may be exposed to security attacks if the base ISO image is
compromised (although the image's SHA256 hash is checked before using it).

EOF
read -p "Press Enter to continue, Ctrl+C to abort." dummy


if git submodule status | grep -q '^-'; then
    echo "Please check out Git submodules." >&2
    exit 1
fi
genisoimage --version > /dev/null  # fail if missing
mksquashfs -version > /dev/null  # fail if missing

mkdir -p "$WORK_DIR"

# Download the base ISO.
while ! echo "$BASE_ISO_SHA256SUM" | sha256sum -c --quiet --status; do
    wget -c -O $BASE_ISO_PATH "$BASE_ISO_URL"
done

# Mount a writable version of the ISO and the FS in it.
ISO_RO=$(mktemp -d -p"$WORK_DIR")
ISO_RW_DATA=$(mktemp -d -p"$WORK_DIR")
ISO_RW_WORK=$(mktemp -d -p"$WORK_DIR")
ISO_ROOT=$(mktemp -d -p"$WORK_DIR")

mount -t iso9660 -o loop,ro $BASE_ISO_PATH $ISO_RO
mount -t overlay -o lowerdir=$ISO_RO,upperdir=$ISO_RW_DATA,workdir=$ISO_RW_WORK base-iso $ISO_ROOT

FS_RO=$(mktemp -d -p"$WORK_DIR")
FS_RW_DATA=$(mktemp -d -p"$WORK_DIR")
FS_RW_WORK=$(mktemp -d -p"$WORK_DIR")
FS_ROOT=$(mktemp -d -p"$WORK_DIR")

mount -t squashfs -o loop,ro $ISO_RO/casper/filesystem.squashfs $FS_RO
mount -t overlay -o lowerdir=$FS_RO,upperdir=$FS_RW_DATA,workdir=$FS_RW_WORK ereuse $FS_ROOT

# To customize filesystem.
alias ch="chroot $FS_ROOT env HOME=/root LC_ALL=C"
alias chi="ch apt-get install -y --no-install-recommends"

# Customization prerequisites.
ch dbus-uuidgen > $FS_ROOT/var/lib/dbus/machine-id
ch dpkg-divert --local --rename --add /sbin/initctl
ch ln -s /bin/true /sbin/initctl

# Disable swapping to disk in a systemd-friendly way.
# See <https://tails.boum.org/contribute/design/#index34h3>.
ch dpkg-divert --local --rename --add /sbin/swapon
ch ln -s /bin/true /sbin/swapon

# TODO manually update resolv.conf
ch rm /etc/resolv.conf  # in case it's a link
echo "nameserver  208.67.222.222" > $FS_ROOT/etc/resolv.conf

# Enable universe repository (/etc/apt/sources.list)
chi software-properties-common
ch add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(ch lsb_release -sc) universe"

# installation tools requirements (could be removed)
ch apt-get update
chi python-pip  # vim
# Install git (Garito)
chi git
ch git clone https://github.com/Garito/WorkbenchSneaky.git /home/ubuntu/WorkbenchSneaky
ch cat > $FS_ROOT/etc/systemd/WorkbenchSneaky.conf << "EOF"
start on runlevel [2345]
stop on runlevel [!2345]

exec python /home/ubuntu/WorkbenchSneaky/sneaky.py http://192.168.2.2:5000
EOF

# ereuse-workbench requirements
# TODO read from requirements.txt
chi $(sed -rn 's/.*\bdeb:(.+)$/\1/p' requirements.txt requirements-full.txt)

# Install Reciclanet's image installation script
install -m 0755 reciclanet-scripts/instalar $FS_ROOT/usr/local/bin/erwb-install-image

cp $SDIST $FS_ROOT/tmp
ch pip install --upgrade /tmp/$(basename $SDIST)
install -m 0755 scripts/erwb-keyboard-layout scripts/erwb-disk-dump $FS_ROOT/usr/local/sbin

# Configure regional settings
ch ckbcomp "$KB_LAYOUT" | gzip -c > $FS_ROOT/etc/console-setup/cached.kmap.gz

echo "$TIMEZONE" > $FS_ROOT/etc/timezone
ch debconf-set-selections << EOF
locales locales/locales_to_be_generated multiselect $LOCALE ${LOCALE##*.}
locales locales/default_environment_locale select $LOCALE
EOF

ch dpkg-reconfigure -f noninteractive tzdata locales
{'fraction_non_alphanumeric': 0.13296801610377992, 'fraction_numerical': 0.0281816148512637, 'mean_word_length': 4.620993086109365, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '489551', 'n_tokens_mistral': 3580, 'n_tokens_neox': 3289, 'n_words': 843}