summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild_medkit.sh218
-rw-r--r--files/.keep0
-rw-r--r--l10n2
-rwxr-xr-xscripts/build_tools.sh53
-rwxr-xr-xscripts/updater-medkit.sh126
-rw-r--r--userlists4
6 files changed, 192 insertions, 211 deletions
diff --git a/build_medkit.sh b/build_medkit.sh
index c5c9951..acef1c4 100755
--- a/build_medkit.sh
+++ b/build_medkit.sh
@@ -1,54 +1,220 @@
#!/bin/sh
+# TODO add support for additional files
set -e
-cd `dirname $0`
-
+## Define variables with their default values ##
BRANCH=
-MODEL=omnia
+MODEL=
+L10N=en,cs
+LISTS=
+VERSION=
+
+## Parse arguments ##
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
- echo "This script generates Turris medkit using user lists and updater-ng."
- echo "Usage: $0 [OPTION]..."
+ 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 " --version VERSION"
- echo " --branch BRANCH"
- echo " --model MODEL"
+ echo " This option allows you to specify exact Turris OS version."
+ echo " If you do so then archive will be used for generating medkit"
+ echo " (this means that using latest version won't work with this"
+ echo " option)."
exit 0
;;
- --version)
+ --localization|-l)
shift
- VERSION="$1"
+ L10N="$1"
;;
- --branch)
+ --lists|-p)
shift
- BRANCH="$1"
+ LISTS="$1"
;;
- --model)
+ --version)
shift
- MODEL="$1"
+ VERSION="$1"
+ echo "Version option is not yet implemented."
+ exit 1
;;
*)
- echo "Unknown option: $1" >&2
- exit 1
+ if [ -z "$MODEL" ]; then
+ MODEL="$1"
+ elif [ -z "$BRANCH" ]; then
+ if [ "$1" == "deploy" ]; then
+ BRANCH=
+ else
+ BRANCH="-$1"
+ fi
+ else
+ echo "Unknown option: $1" >&2
+ exit 1
+ fi
;;
esac
shift
done
-# Get latest version if we didn't stated version explicitly
-if [ -z "$VERSION" ]; then
- [ -n "$BRANCH" ] && VBRANCH="-$BRANCH"
- VERSION="$(curl https://repo.turris.cz/"$MODEL$VBRANCH"/packages/base/Packages | sed -n 's/^Filename: turris-version_\([^_]*\)_.*/\1/p')"
+[ -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
+git_pull .usign git://git.openwrt.org/project/usign.git
+(
+cd .usign
+cmake .
+make
+)
+
+# Updater-ng
+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
+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 ROOT="$(readlink -f "root-$MODEL$BRANCH")"
+
+
+## Dump updater-ng entry script ##
+export UPDATER_CONFIG=".updater-$MODEL$BRANCH.lua"
+cat > "$UPDATER_CONFIG" <<EOF
+-- Load requested localizations
+l10n = {}
+for lang in os.getenv('L10N'):gmatch('[^,]+') do
+ table.insert(l10n, lang)
+end
+Export('l10n')
+
+-- This is helper function for including localization packages.
+-- (This is copy of standard entry function that can be found in pkgupdate entry.lua)
+function for_l10n(fragment)
+ for _, lang in pairs(l10n or {}) do
+ Install(fragment .. lang, {ignore = {'missing'}})
+ end
+end
+Export('for_l10n')
+
+local script_options = {
+ security = 'Remote',
+ ca = system_cas,
+ crl = no_crl,
+ pubkey = {
+ 'file://$PWD/.release.pub',
+ 'file://$PWD/.standby.pub',
+ 'file://$PWD/.test.pub'
+ }
+}
+base_url = 'https://repo.turris.cz/$MODEL$BRANCH/lists/'
+
+-- Aways include base script
+Script('base', base_url .. 'base.lua', script_options)
+
+-- Now include any additional lists
+local userlists_file = io.open('userlists', 'r')
+for list in os.getenv('LISTS'):gmatch('[^,]+') do
+ Script('userlist-' .. list, base_url .. list, script_options)
+end
+EOF
+
+# Create /tmp/sysinfo files
+# TODO we should use some internal option of updater it self
+mkdir -p /tmp/sysinfo
+if [ "$MODEL" = "omnia" ]; then
+ echo "Turris Omnia" > /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 ##
+fakeroot -- sh -s <<EOF
+set -e
+
+mkdir -p "$ROOT"
+## Create base filesystem for updater
+ln -sf tmp "$ROOT/var"
+# Create lock required by updater
+mkdir -p "$ROOT/tmp/lock"
+# Create opkg status file and info file
+mkdir -p "$ROOT/usr/lib/opkg/info"
+touch "$ROOT/usr/lib/opkg/status"
+# And updater directory
+mkdir -p "$ROOT/usr/share/updater"
-# Ensure that we have tools
-./scripts/build_tools.sh
+## Run updater it self
+.updater/bin/pkgupdate --out-of-root --usign=.usign/usign -R "$ROOT" \
+ --batch "file://$UPDATER_CONFIG"
-# Download api crl
-chmod +x .get-api-crl
-./.get-api-crl
+## Tar root in current directory
+(
+cd "$ROOT"
+# Do cleanups first
+rm -f var/lock/opkg.lock
+rm -f usr/share/updater/flags
+rm -rf usr/share/updater/unpacked
+rm -rf var/opkg-collided
+# Now create archive
+tar -czf "../medkit-$MODEL$BRANCH.tar.gz" .
+)
+EOF
-# Now build medkit
-fakeroot ./scripts/updater-medkit.sh --version "$VERSION" --branch "$BRANCH" --model "$MODEL"
+## Cleanup ##
+rm -rf "$ROOT"
+rm -f "$UPDATER_CONF"
diff --git a/files/.keep b/files/.keep
deleted file mode 100644
index e69de29..0000000
--- a/files/.keep
+++ /dev/null
diff --git a/l10n b/l10n
deleted file mode 100644
index 65acf69..0000000
--- a/l10n
+++ /dev/null
@@ -1,2 +0,0 @@
-cs
-de
diff --git a/scripts/build_tools.sh b/scripts/build_tools.sh
deleted file mode 100755
index 1bcabee..0000000
--- a/scripts/build_tools.sh
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/bin/sh
-# This tool pulls down and builds updater-ng and usign
-# It expects to be executed in root directory of this project
-set -e
-
-git_pull() {
- if [ ! -d $1 ]; then
- git clone $2 $1
- pushd $1 >/dev/null
- git submodule update --init --recursive
- popd >/dev/null
- else
- pushd $1 >/dev/null
- git fetch
- if ! git diff --quiet HEAD origin/HEAD; then
- git clean -Xdf
- git reset --hard origin/master
- git submodule update --init --recursive
- fi
- popd >/dev/null
- fi
-}
-
-wget_pull() {
- if [ ! -e $1 ] || [ $(expr $(date -u +%s) - $(stat -c %Z $1)) -gt 86400 ]; then
- wget $2 -O $1
- fi
-}
-
-## Usign ##
-git_pull .usign git://git.openwrt.org/project/usign.git
-
-if [ ! -x .usign/usign ]; then
- pushd .usign >/dev/null
- cmake .
- make
- popd >/dev/null
-fi
-
-## Updater-ng ##
-git_pull .updater https://gitlab.labs.nic.cz/turris/updater.git
-
-if [ ! -x .updater/bin/pkgupdate ]; then
- make -C .updater NO_DOC=1 LUA_COMPILE:=no
-fi
-
-## get-api-crl ##
-wget_pull .get-api-crl https://gitlab.labs.nic.cz/turris/misc/raw/master/cacerts/get-api-crl
-
-## Get certificates ##
-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
diff --git a/scripts/updater-medkit.sh b/scripts/updater-medkit.sh
deleted file mode 100755
index 6f7dc27..0000000
--- a/scripts/updater-medkit.sh
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/bin/sh
-# This script is real medkit generator using updater
-set -e
-
-MODEL=omnia
-BRANCH=
-while [ $# -gt 0 ]; do
- case "$1" in
- --version)
- shift
- VERSION="$1"
- ;;
- --model)
- shift
- MODEL="$1"
- ;;
- --branch)
- shift
- BRANCH="$1"
- ;;
- *)
- echo "Unknown option: $1" >&2
- exit 1
- ;;
- esac
- shift
-done
-
-if [ -z "$VERSION" ]; then
- echo "Missing --version argument!" >&2
- exit 1
-fi
-
-ROOT=root-$MODEL
-[ -n "$BRANCH" ] && ROOT=$ROOT-$BRANCH
-ROOT=$ROOT-$VERSION
-rm -rf $ROOT
-mkdir $ROOT
-
-OUTPUT=medkit-$MODEL
-[ -n "$BRANCH" ] && OUTPUT=$OUTPUT-$BRANCH
-OUTPUT=$PWD/$OUTPUT-$VERSION.tar.gz
-
-## Create base filesystem for updater
-ln -s tmp $ROOT/var
-# Create lock required by updater
-mkdir -p $ROOT/tmp/lock
-# Create opkg status file and info file
-mkdir -p $ROOT/usr/lib/opkg/info
-touch $ROOT/usr/lib/opkg/status
-# And updater directory
-mkdir -p $ROOT/usr/share/updater
-# Copy additional files
-[ -e files/* ] && cp -r files/* $ROOT/
-
-# Create fake reboot to not potentially reboot host if requested
-mkdir -p .fake_bin
-echo "#!/bin/sh
-echo Reboot faked!" > .fake_bin/reboot
-chmod +x .fake_bin/reboot
-export PATH="$(readlink -f $PWD/.fake_bin):$PATH"
-
-# TODO we migh need base files installed first
-
-ABSOUT="$(readlink -f $ROOT)"
-## Dump our entry file
-UPDATER_CONF=".entry-$MODEL-$BRANCH.lua"
-rm -f "$UPDATER_CONF" && touch "$UPDATER_CONF"
-if [ -e l10n ]; then
- echo "l10n = {" >> "$UPDATER_CONF"
- while read L; do
- echo "'$L'," >> "$UPDATER_CONF"
- done < l10n
- echo "}" >> "$UPDATER_CONF"
-else
- # Use no localizations
- echo "l10n = {} -- table with selected localizations" >> "$UPDATER_CONF"
-fi
-[ -n "$BRANCH" ] && CBRANCH="/$BRANCH"
-echo "Export 'l10n'
--- This is helper function for including localization packages.
-function for_l10n(fragment)
- for _, lang in pairs(l10n or {}) do
- Install(fragment .. lang, {ignore = {'missing'}})
- end
-end
-Export 'for_l10n'
-
-local script_options = {
- security = 'Remote',
- ca = 'file://$PWD/.updater/updater.pem',
- crl = 'file:///tmp/crl.pem',
- ocsp = false,
- pubkey = {
- 'file://$PWD/.release.pub',
- 'file://$PWD/.standby.pub',
- 'file://$PWD/.test.pub'
- }
-}
-base_url = 'https://api.turris.cz/updater-defs/$VERSION/$MODEL$CBRANCH/'
-
-Script('base', base_url .. 'base.lua', script_options)
-" >> "$UPDATER_CONF"
-if [ -e userlists ]; then
- while read L; do
- echo "Script('userlist-$L', base_url .. 'userlists/$L.lua', script_options)" >> "$UPDATER_CONF"
- done < userlists
-fi
-# Run updater to pull in packages from base list
-.updater/bin/pkgupdate --no-replan --usign=.usign/usign -R $ABSOUT --batch file://$UPDATER_CONF
-
-# Tar it to archive in current directory
-(
- cd $ROOT
- # Do cleanups first
- rm -f var/lock/opkg.lock
- rm -f usr/share/updater/flags
- rm -rf usr/share/updater/unpacked
- rm -rf var/opkg-collided
- # Now create archive
- tar -czf "$OUTPUT" *
-)
-
-# Do cleanups
-rm -rf .fake_bin
-rm -f $UPDATER_CONF
diff --git a/userlists b/userlists
deleted file mode 100644
index c48b5a2..0000000
--- a/userlists
+++ /dev/null
@@ -1,4 +0,0 @@
-luci-controls
-nas
-printserver
-netutils