#!/bin/sh # TODO add support for additional files set -e ## Define variables with their default values ## BRANCH= MODEL= L10N=en,cs LISTS= VERSION= OVERLAY= UPDATER_SCRIPT= TEST_BRANCH=false ## Parse arguments ## while [ $# -gt 0 ]; do case "$1" in -h|--help) echo "This script generates Turris medkit using packages lists and updater-ng." echo "Usage: $0 [OPTION].. MODEL [BRANCH]" echo echo "Model:" echo " Model is Turris device model. Only supported ones at the moment" echo " are 'turris' for Turris 1.x and 'omnia' for Turris Omnia." echo "Branch:" echo " This optionally specifies source branch for packages." echo " If no branch is specified then deploy is used (branch" echo " identified only just by model, no branch name appended)." echo "Options:" echo " --help, -h" echo " Print this text and exit." echo " --localization, -l LOCALIZATION,.." echo " After this argument a list of language codes to be added to" echo " medkit should be specified. Language codes should be" echo " separated by comma. In default en,cs is used." echo " --lists, -p PKGLIST,.." echo " What lists should be added to medkit. In default no" echo " additional lists will be added. Multiple lists can be" echo " specified by separating them by commas." echo " --updater-script FILE" echo " Run file as updater's script. It is executed after primary" echo " entry script of this tool." echo " --overlay PATH" echo " This allows you to overwrite or add some files to medkit." echo " PATH is expected to be directory and whole content is copied" echo " to newly generated root. This is handy if you want to change" echo " some default settings for example." exit 0 ;; --localization|-l) shift L10N="$1" ;; --lists|-p) shift LISTS="$1" ;; --updater-script) shift UPDATER_SCRIPT="$1" ;; --overlay) shift OVERLAY="$1" ;; *) if [ -z "$MODEL" ]; then MODEL="$1" elif [ -z "$BRANCH" ]; then if [ "$1" == "deploy" ]; then BRANCH= else BRANCH="-$1" TEST_BRANCH=true case "$1" in rc) TEST_BRANCH=false ;; esac fi else echo "Unknown option: $1" >&2 exit 1 fi ;; esac shift done [ -n "$MODEL" ] || { echo "You have to specify Turris router model." >&2 exit 1 } ## Build needed tools ## # Git puller helper function (git_pull output_path source_url) git_pull() { if [ ! -d $1 ]; then git clone $2 $1 ( cd $1 git submodule update --init --recursive ) else ( cd $1 git fetch if ! git diff --quiet HEAD origin/HEAD; then git clean -Xdf git reset --hard origin/master git submodule update --init --recursive fi ) fi } # Wget puller helper function (wget_pull output_file source_url) wget_pull() { if [ ! -e $1 ] || [ $(expr $(date -u +%s) - $(stat -c %Z $1)) -gt 86400 ]; then wget $2 -O $1 fi } # Usign echo "==== Getting usign up and running ====" git_pull .usign git://git.openwrt.org/project/usign.git ( cd .usign cmake . make ) # Updater-ng echo "==== Getting updater-ng up and running ====" git_pull .updater https://gitlab.labs.nic.cz/turris/updater.git make -C .updater NO_DOC=1 LUA_COMPILE:=no # Get public parts of signing keys echo "==== Checking public keys ====" for K in release standby test; do wget_pull .$K.pub https://gitlab.labs.nic.cz/turris/turris-os-packages/raw/test/cznic/cznic-repo-keys/files/$K.pub done ## Export some variables that are used by pkgupdate lua script export L10N export LISTS export OVERLAY export TEST_BRANCH export ROOT="$(readlink -f "root-$MODEL$BRANCH")" ## Dump updater-ng entry script ## export UPDATER_CONFIG=".updater-$MODEL$BRANCH.lua" cat > "$UPDATER_CONFIG" <> "$UPDATER_CONFIG" < /tmp/sysinfo/model else # Else Turris 1.x (yes this is wrong but it's just temporally) echo "Turris" > /tmp/sysinfo/model fi # We are only using board_name anyway atm. echo "rtunknown" > /tmp/sysinfo/board_name ## Generate root ## echo "==== Building new root ====" fakeroot -- sh -s <> "$ROOT/etc/config/updater" echo "config pkglists 'pkglists'" >> "$ROOT/etc/config/updater" while IFS=',' read LIST; do echo " list lists '\$LIST'" >> "$ROOT/etc/config/updater" done <<< "\$LISTS" echo >> "$ROOT/etc/config/updater" echo "config l10n 'l10n'" >> "$ROOT/etc/config/updater" while IFS=',' read LANG; do echo " list langs '\$LANG'" >> "$ROOT/etc/config/updater" done <<< "\$L10N" ## Overlay user's files if [ -n "$OVERLAY" ]; then cp -r "$OVERLAY/." "$ROOT/" fi ## Tar root in current directory ( cd "$ROOT" # Do cleanups rm -f var/lock/opkg.lock rm -f usr/share/updater/flags rm -rf usr/share/updater/unpacked rm -rf var/opkg-collided # Create archive tar -czf "../medkit-$MODEL$BRANCH.tar.gz" . ) EOF ## Cleanup ## echo "==== Cleaning up ====" rm -rf "$ROOT" rm -f "$UPDATER_CONF"