Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 48 additions & 32 deletions bin/clicksnap-setup
Original file line number Diff line number Diff line change
@@ -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.
#
Expand All @@ -8,13 +8,18 @@
# 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")]: $*"; }

# XXX this was only used temporarily to workaround:
# https://github.com/turnkeylinux/tracker/issues/2033
RUST_V=

usage() {
local msg="$*"
cat<<EOF
Syntax: $(basename $0) [APP_NAME]
Syntax: $(basename "$0") [APP_NAME]
Setup/update system ready for bt-iso (clicksnap & deps)

Option::
Expand All @@ -29,20 +34,20 @@ Environment::
BT_DEBUG turn on debugging

EOF
if [[ -n "$1" ]]; then
echo "Error: $@" >&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
Expand All @@ -59,19 +64,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
Expand All @@ -86,14 +92,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
Expand All @@ -102,30 +109,39 @@ 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;;
# TODO see note re $RUST_V above
rustup update
rustup default "$RUST_V"
;;
/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;;
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"
;;
*)
fatal "Unexpected cargo path: '$1'";;
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
37 changes: 24 additions & 13 deletions bt-iso
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -167,14 +172,20 @@ 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"

INIT_CONF=/turnkey/public/tkldev-docker/inithooks.conf
if [[ ! -f "$INIT_CONF" ]]; then
if [[ "$skip_setup" != "true" ]]; then
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
. "$INIT_CONF"
fi

source "$INIT_CONF"
if [[ -z "$APP_DOMAIN" ]]; then
check_debug "APP_DOMAIN not set"
fi
Expand Down Expand Up @@ -220,7 +231,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
Expand Down Expand Up @@ -371,7 +382,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
Expand Down