diff --git a/schnapps.sh b/schnapps.sh index 2557e0ac2898a8863fba360fafd7fee233888318..800912a31b165ddd0d9c42f4d499ca99cd3cf176 100755 --- a/schnapps.sh +++ b/schnapps.sh @@ -41,6 +41,12 @@ GPG_PASS="" ROOT_DEV="$(btrfs fi show / | sed -n 's|.*\(/dev/[^[:blank:]]*\)$|\1|p' | head -n 1)" VERSION="@VERSION@" +die() { + echo "$@" >&2 + ERR="${ERR:-1}" + exit 1 +} + # Read uci configuration if available if [ -f "/lib/functions.sh" ]; then . /lib/functions.sh @@ -58,6 +64,17 @@ if [ -f "/lib/functions.sh" ]; then config_get GPG_PASS encrypt pass "$GPG_PASS" fi +[ \! -f /etc/schnapps/config ] || . /etc/schnapps/config + +if [ "x$1" == "x-d" ]; then + ROOT_DEV="$(btrfs fi show $2 | sed -n 's|.*\(/dev/[^[:blank:]]*\)$|\1|p')" + shift 2 +fi + +[ -n "$ROOT_DEV" ] || die "Can't figure out device to work on" +ROOT_LABEL="$(btrfs fi label "$ROOT_DEV")" +[ -z "$ROOT_LABEL" ] || [ \! -f /etc/schnapps/"$ROOT_LABEL" ] || . /etc/schnapps/"$ROOT_LABEL" + # Usage help USAGE="Usage: $(basename "$0") [-d root] command [options] @@ -147,13 +164,6 @@ Commands: version Display version " - -die() { - echo "$@" >&2 - ERR="${ERR:-1}" - exit 1 -} - show_help() { echo "$USAGE" } @@ -861,17 +871,6 @@ trap_cleanup() { exit "$ERR" } -[ \! -f /etc/schnapps/config ] || . /etc/schnapps/config - -if [ "x$1" == "x-d" ]; then - ROOT_DEV="$(btrfs fi show $2 | sed -n 's|.*\(/dev/[^[:blank:]]*\)$|\1|p')" - shift 2 -fi - -[ -n "$ROOT_DEV" ] || die "Can't figure out device to work on" -ROOT_LABEL="$(btrfs fi label "$ROOT_DEV")" -[ -z "$ROOT_LABEL" ] || [ \! -f /etc/schnapps/"$ROOT_LABEL" ] || . /etc/schnapps/"$ROOT_LABEL" - trap 'trap_cleanup' EXIT INT QUIT TERM ABRT mount_root