From c4fa7b08088be7e4874db56dc9f46b19b265fee1 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Mon, 16 Jun 2025 02:34:28 +0000 Subject: [PATCH 1/8] Improve tkldev-docker missing error --- bt-iso | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bt-iso b/bt-iso index 27405f3..5e34a74 100755 --- a/bt-iso +++ b/bt-iso @@ -169,11 +169,16 @@ export BT export BT_CONFIG="$BT/config" . "$BT_CONFIG/common.cfg" -INIT_CONF=/turnkey/public/tkldev-docker/inithooks.conf -if [[ ! -f "$INIT_CONF" ]]; then +TKLDEV_DOCKER=${TKLDEV_DOCKER:-/turnkey/public/tkldev-docker} +INIT_CONF="$TKLDEV_DOCKER/inithooks.conf" + +if [[ ! -d "$TKLDEV_DOCKER" ]]; then + msg="TKLDev-Docker repo not found ($TKLDEV_DOCKER) - clone repo to" + check_debug "$msg $TKLDEV_DOCKER or set TKLDEV_DOCKER env var" +elif [[ ! -f "$INIT_CONF" ]]; then check_debug "Inithooks preseed file ($INIT_CONF) not found" else - . "$INIT_CONF" + source "$INIT_CONF" fi if [[ -z "$APP_DOMAIN" ]]; then check_debug "APP_DOMAIN not set" From 96ccea303856ee26f9dbc82511b33d77424b0166 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Mon, 16 Jun 2025 02:42:52 +0000 Subject: [PATCH 2/8] Actually; clone if missing --- bt-iso | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bt-iso b/bt-iso index 5e34a74..b850904 100755 --- a/bt-iso +++ b/bt-iso @@ -167,14 +167,16 @@ link=$(readlink -f "$0") BT=$(dirname "$link") export BT export BT_CONFIG="$BT/config" -. "$BT_CONFIG/common.cfg" +source "$BT_CONFIG/common.cfg" TKLDEV_DOCKER=${TKLDEV_DOCKER:-/turnkey/public/tkldev-docker} INIT_CONF="$TKLDEV_DOCKER/inithooks.conf" -if [[ ! -d "$TKLDEV_DOCKER" ]]; then - msg="TKLDev-Docker repo not found ($TKLDEV_DOCKER) - clone repo to" - check_debug "$msg $TKLDEV_DOCKER or set TKLDEV_DOCKER env var" +if [[ ! -d "$TKLDEV_DOCKER" ]] && [[ "skip_setup" != "true" ]]; then + warning "TKLDev-Docker repo not found ($TKLDEV_DOCKER); cloning" + mkdir -p $(dirname "$TKLDEV_DOCKER") + git clone https://github.com/turnkeylinux/tkldev-docker.git \ + "$TKLDEV_DOCKER" elif [[ ! -f "$INIT_CONF" ]]; then check_debug "Inithooks preseed file ($INIT_CONF) not found" else From 427aad2bc4509c3bea0943c3534b8bfac2fbe70a Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Mon, 16 Jun 2025 13:26:21 +1000 Subject: [PATCH 3/8] Improvements and linting --- bt-iso | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/bt-iso b/bt-iso index b850904..612f46a 100755 --- a/bt-iso +++ b/bt-iso @@ -1,5 +1,5 @@ #!/bin/bash -e -# Copyright (c) 2011-2021 TurnKey GNU/Linux - http://www.turnkeylinux.org +# Copyright (c) 2011-2025 TurnKey GNU/Linux - https://www.turnkeylinux.org # # This file is part of buildtasks. # @@ -55,26 +55,31 @@ EOF clone_or_pull() { # If $dir doesn't exist, clone $repo. If it does, update from origin master - dir=$1 - repo=$2 + local dir=$1 + local repo=$2 if [[ -z "$dir" ]] || [[ -z "$repo" ]]; then fatal "One or more empty values passed to function: ${FUNCNAME[*]}." fi if [ ! -e "$dir" ]; then + mkdir -p "$(dirname "$dir")" info "Attempting to clone repo $repo to $dir." cd "$(dirname "$dir")" git clone "https://github.com/$repo" "$dir" cd "$dir" else - info "Repo $repo found, attempting to update" + info "Directory $repo found, attempting to update" + if [[ ! -d "$dir/.git" ]]; then + check_debug "Does not appear to be a git repo (no .git)" + fi cd "$dir" git pull origin master fi } get_version() { - pkg=$1 - sp="[[:space:]]" + local pkg=$1 + local sp="[[:space:]]" + local pkg_info pkg_info=$(dpkg -l \ | sed -En "s|^ii.*($pkg)$sp*([0-9a-z\.-:]*)$sp*amd64$sp*.*|\1 \2|p") echo "$pkg_info" | cut -d' ' -f2 @@ -172,11 +177,11 @@ source "$BT_CONFIG/common.cfg" TKLDEV_DOCKER=${TKLDEV_DOCKER:-/turnkey/public/tkldev-docker} INIT_CONF="$TKLDEV_DOCKER/inithooks.conf" -if [[ ! -d "$TKLDEV_DOCKER" ]] && [[ "skip_setup" != "true" ]]; then - warning "TKLDev-Docker repo not found ($TKLDEV_DOCKER); cloning" - mkdir -p $(dirname "$TKLDEV_DOCKER") - git clone https://github.com/turnkeylinux/tkldev-docker.git \ +if [[ "$skip_setup" != "true" ]]; then + clone_or_pull https://github.com/turnkeylinux/tkldev-docker.git \ "$TKLDEV_DOCKER" +elif [[ ! -d "$TKLDEV_DOCKER" ]]; then + check_debug "tkldev-docker repo not found: $TKLDEV_DOCKER" elif [[ ! -f "$INIT_CONF" ]]; then check_debug "Inithooks preseed file ($INIT_CONF) not found" else @@ -227,7 +232,7 @@ if [[ -z "$skip_setup" ]]; then touch /root/clicksnap-setup.done fi fi - if ! grep -q $appname <<<$(clicksnap list); then + if ! grep -q "$appname" <<<"$(clicksnap list)"; then fatal "Clicksnap code for $appname not found" fi fi @@ -378,7 +383,7 @@ if [[ -z "$no_screens" ]]; then sleep 1 done info "container running - waiting for connection" - for ping in {1..20}; do + for _ in {1..20}; do # ping container to ensure it's available if ! curl localhost:7900 >/dev/null 2>&1; then sleep 1 fi From 9a96c6a3bc377d4cf7eea08a7baabdd355801839 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Mon, 16 Jun 2025 03:28:20 +0000 Subject: [PATCH 4/8] Fix incorrect arg order on call to clone_or_pull() & other bits --- bt-iso | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bt-iso b/bt-iso index 612f46a..bbea77a 100755 --- a/bt-iso +++ b/bt-iso @@ -178,15 +178,14 @@ TKLDEV_DOCKER=${TKLDEV_DOCKER:-/turnkey/public/tkldev-docker} INIT_CONF="$TKLDEV_DOCKER/inithooks.conf" if [[ "$skip_setup" != "true" ]]; then - clone_or_pull https://github.com/turnkeylinux/tkldev-docker.git \ - "$TKLDEV_DOCKER" + clone_or_pull "$TKLDEV_DOCKER" turnkeylinux/tkldev-docker elif [[ ! -d "$TKLDEV_DOCKER" ]]; then check_debug "tkldev-docker repo not found: $TKLDEV_DOCKER" elif [[ ! -f "$INIT_CONF" ]]; then check_debug "Inithooks preseed file ($INIT_CONF) not found" -else - source "$INIT_CONF" fi + +source "$INIT_CONF" if [[ -z "$APP_DOMAIN" ]]; then check_debug "APP_DOMAIN not set" fi From a56d6ce693a375d287c0624a01221228df2f5762 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Mon, 16 Jun 2025 14:44:50 +1000 Subject: [PATCH 5/8] Lint bin/clicksnap-setup --- bin/clicksnap-setup | 64 ++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/bin/clicksnap-setup b/bin/clicksnap-setup index 1b138d9..0ce8190 100755 --- a/bin/clicksnap-setup +++ b/bin/clicksnap-setup @@ -1,5 +1,5 @@ #!/bin/bash -e -# Copyright (c) 2023 TurnKey GNU/Linux - https://www.turnkeylinux.org +# Copyright (c) 2023-2025 TurnKey GNU/Linux - https://www.turnkeylinux.org # # This file is part of buildtasks. # @@ -8,13 +8,14 @@ # Free Software Foundation; either version 3 of the License, or (at your # option) any later version. -fatal() { echo "FATAL [$(basename $0)]: $@" 1>&2; exit 1; } -warn() { echo -e "WARNING [$(basename $0)]: $@"; } -info() { echo "INFO [$(basename $0)]: $@"; } +fatal() { echo "FATAL [$(basename "$0")]: $*" 1>&2; exit 1; } +warn() { echo -e "WARNING [$(basename "$0")]: $*"; } +info() { echo "INFO [$(basename "$0")]: $*"; } usage() { + local msg="$*" cat<&2 - exit 1 + if [[ -n "$msg" ]]; then + fatal "$msg" fi exit } [ -n "$BT_DEBUG" ] && set -x -export BT=$(dirname $(dirname $(readlink -f $0))) +BT=$(dirname "$(dirname "$(readlink -f "$0")")") +export BT export BT_CONFIG=$BT/config [[ -n "$BASE_DIR" ]] || BASE_DIR=/turnkey/public -mkdir -p $BASE_DIR +mkdir -p "$BASE_DIR" GH_URL=https://github.com/turnkeylinux unset app @@ -59,19 +60,20 @@ while [ "$1" != "" ]; do done install() { - info "Updating apt cache and installing deps:" $@ - info "installing $@" + info "Updating apt cache and installing deps: $*" + info "installing $*" apt-get -qq update - DEBIAN_FRONTEND=noninteractive apt-get -y install $@ + DEBIAN_FRONTEND=noninteractive apt-get -y install "$@" } git_pull() { local dir=$1 local app=$2 - cd $dir - local remote=$(sed -En "s|(^[a-zA-Z0-9_-]*)[[:space:]].*|\1|p" \ - <<<$(git remote -v | grep -m1 "turnkeylinux/$app")) - git pull $remote master + cd "$dir" + local remote + remote=$(sed -En "s|(^[a-zA-Z0-9_-]*)[[:space:]].*|\1|p" \ + <<<"$(git remote -v | grep -m1 "turnkeylinux/$app")") + git pull "$remote" master } # dl & check for screenshot code first so we can bail as early as possible @@ -86,14 +88,15 @@ for dl in tkldev-docker clicksnap; do fi else info "Downloading $dl source" - git clone --depth=1 $GH_URL/$dl $BASE_DIR/$dl + git clone --depth=1 $GH_URL/$dl "$BASE_DIR/$dl" fi done -app=$(sed "s|-|_|g" <<<$app) +# TODO use ${variable//search/replace} instead of sed here +app="$(sed "s|-|_|g" <<< "$app")" if [[ -z "$app" ]]; then warn "App name not given - continuing, but may fail later" -elif ! ls $BASE_DIR/clicksnap/src/apps/ | grep -q -w "$app" \ +elif ! grep -r -q -w "$app" "$BASE_DIR"/clicksnap/src/apps/ \ && [[ -z "$no_screens" ]] ; then fatal "Clicksnap code for $app not found (checked in $BASE_DIR/clicksnap/src/apps/)" fi @@ -102,30 +105,31 @@ fi deps="podman sed fab deck" missing='' for dep in $deps; do - which $dep >/dev/null || missing="$missing $dep" + which "$dep" >/dev/null || missing="$missing $dep" done -[[ -z "$missing" ]] || install $missing +[[ -z "$missing" ]] || install "$missing" case "$(which cargo || echo 'fail')" in "$HOME/.cargo/bin/cargo") info "Rust installed via rustup detected, attempting update" - rustup update;; + rustup update + ;; /usr/bin/cargo) warn "system installed rust detected; continuing but may cause issues\n" \ " - if you encountner issues, please remove rust and rerun";; fail) info "Installing rust via rustup" curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" > $HOME/.bashrc.d/rust - chmod +x $HOME/.bashrc.d/rust - source $HOME/.bashrc.d/rust;; + echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" > "$HOME"/.bashrc.d/rust + chmod +x "$HOME"/.bashrc.d/rust + source "$HOME/.bashrc.d/rust";; *) fatal "Unexpected cargo path: '$1'";; esac -cd $BASE_DIR/clicksnap +cd "$BASE_DIR"/clicksnap info "Building & installing clicksnap" cargo build -ln -sf $PWD/target/debug/clicksnap /usr/local/bin/clicksnap -ln -sf $BASE_DIR/tkldev-docker/dockerize.sh /usr/local/bin/dockerize -ln -sf $BASE_DIR/tkldev-docker/wait-ready.sh /usr/local/bin/tkl-docker-wait-ready +ln -sf "$PWD"/target/debug/clicksnap /usr/local/bin/clicksnap +ln -sf "$BASE_DIR"/tkldev-docker/dockerize.sh /usr/local/bin/dockerize +ln -sf "$BASE_DIR"/tkldev-docker/wait-ready.sh /usr/local/bin/tkl-docker-wait-ready From de5ccb150c0052881182afa8ed1d1ce420944e34 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Mon, 16 Jun 2025 14:45:11 +1000 Subject: [PATCH 6/8] Workaround #2033 --- bin/clicksnap-setup | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bin/clicksnap-setup b/bin/clicksnap-setup index 0ce8190..73619d1 100755 --- a/bin/clicksnap-setup +++ b/bin/clicksnap-setup @@ -12,6 +12,10 @@ fatal() { echo "FATAL [$(basename "$0")]: $*" 1>&2; exit 1; } warn() { echo -e "WARNING [$(basename "$0")]: $*"; } info() { echo "INFO [$(basename "$0")]: $*"; } +# XXX this is only a temporary measure +# see: https://github.com/turnkeylinux/tracker/issues/2033 +RUST_V=1.76.0 + usage() { local msg="$*" cat< "$HOME"/.bashrc.d/rust chmod +x "$HOME"/.bashrc.d/rust source "$HOME/.bashrc.d/rust";; From abd93a6313c63ef432b6302410046525908cfbe8 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Fri, 20 Jun 2025 07:07:12 +0000 Subject: [PATCH 7/8] tweak bin/clicksnap-setup --- bin/clicksnap-setup | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bin/clicksnap-setup b/bin/clicksnap-setup index 73619d1..1a185a8 100755 --- a/bin/clicksnap-setup +++ b/bin/clicksnap-setup @@ -122,18 +122,21 @@ case "$(which cargo || echo 'fail')" in ;; /usr/bin/cargo) warn "system installed rust detected; continuing but may cause issues\n" \ - " - if you encountner issues, please remove rust and rerun";; + " - if you encounter issues, please remove rust and rerun" + ;; fail) info "Installing rust via rustup" curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" > "$HOME"/.bashrc.d/rust + chmod +x "$HOME"/.bashrc.d/rust + source "$HOME/.bashrc.d/rust" # TODO see note re $RUST_V above rustup update "$RUST_V" rustup default "$RUST_V" - echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" > "$HOME"/.bashrc.d/rust - chmod +x "$HOME"/.bashrc.d/rust - source "$HOME/.bashrc.d/rust";; + ;; *) - fatal "Unexpected cargo path: '$1'";; + fatal "Unexpected cargo path: '$1'" + ;; esac cd "$BASE_DIR"/clicksnap From a2555fa95bac90395bde45bd660ec69a2d6a7d8f Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Fri, 20 Jun 2025 07:11:42 +0000 Subject: [PATCH 8/8] Remove issue workaround --- bin/clicksnap-setup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/clicksnap-setup b/bin/clicksnap-setup index 1a185a8..3800713 100755 --- a/bin/clicksnap-setup +++ b/bin/clicksnap-setup @@ -12,9 +12,9 @@ fatal() { echo "FATAL [$(basename "$0")]: $*" 1>&2; exit 1; } warn() { echo -e "WARNING [$(basename "$0")]: $*"; } info() { echo "INFO [$(basename "$0")]: $*"; } -# XXX this is only a temporary measure -# see: https://github.com/turnkeylinux/tracker/issues/2033 -RUST_V=1.76.0 +# XXX this was only used temporarily to workaround: +# https://github.com/turnkeylinux/tracker/issues/2033 +RUST_V= usage() { local msg="$*"