Skip to content

Commit a56d6ce

Browse files
committed
Lint bin/clicksnap-setup
1 parent 9a96c6a commit a56d6ce

1 file changed

Lines changed: 34 additions & 30 deletions

File tree

bin/clicksnap-setup

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash -e
2-
# Copyright (c) 2023 TurnKey GNU/Linux - https://www.turnkeylinux.org
2+
# Copyright (c) 2023-2025 TurnKey GNU/Linux - https://www.turnkeylinux.org
33
#
44
# This file is part of buildtasks.
55
#
@@ -8,13 +8,14 @@
88
# Free Software Foundation; either version 3 of the License, or (at your
99
# option) any later version.
1010

11-
fatal() { echo "FATAL [$(basename $0)]: $@" 1>&2; exit 1; }
12-
warn() { echo -e "WARNING [$(basename $0)]: $@"; }
13-
info() { echo "INFO [$(basename $0)]: $@"; }
11+
fatal() { echo "FATAL [$(basename "$0")]: $*" 1>&2; exit 1; }
12+
warn() { echo -e "WARNING [$(basename "$0")]: $*"; }
13+
info() { echo "INFO [$(basename "$0")]: $*"; }
1414

1515
usage() {
16+
local msg="$*"
1617
cat<<EOF
17-
Syntax: $(basename $0) [APP_NAME]
18+
Syntax: $(basename "$0") [APP_NAME]
1819
Setup/update system ready for bt-iso (clicksnap & deps)
1920
2021
Option::
@@ -29,20 +30,20 @@ Environment::
2930
BT_DEBUG turn on debugging
3031
3132
EOF
32-
if [[ -n "$1" ]]; then
33-
echo "Error: $@" >&2
34-
exit 1
33+
if [[ -n "$msg" ]]; then
34+
fatal "$msg"
3535
fi
3636
exit
3737
}
3838

3939
[ -n "$BT_DEBUG" ] && set -x
4040

41-
export BT=$(dirname $(dirname $(readlink -f $0)))
41+
BT=$(dirname "$(dirname "$(readlink -f "$0")")")
42+
export BT
4243
export BT_CONFIG=$BT/config
4344

4445
[[ -n "$BASE_DIR" ]] || BASE_DIR=/turnkey/public
45-
mkdir -p $BASE_DIR
46+
mkdir -p "$BASE_DIR"
4647
GH_URL=https://github.com/turnkeylinux
4748

4849
unset app
@@ -59,19 +60,20 @@ while [ "$1" != "" ]; do
5960
done
6061

6162
install() {
62-
info "Updating apt cache and installing deps:" $@
63-
info "installing $@"
63+
info "Updating apt cache and installing deps: $*"
64+
info "installing $*"
6465
apt-get -qq update
65-
DEBIAN_FRONTEND=noninteractive apt-get -y install $@
66+
DEBIAN_FRONTEND=noninteractive apt-get -y install "$@"
6667
}
6768

6869
git_pull() {
6970
local dir=$1
7071
local app=$2
71-
cd $dir
72-
local remote=$(sed -En "s|(^[a-zA-Z0-9_-]*)[[:space:]].*|\1|p" \
73-
<<<$(git remote -v | grep -m1 "turnkeylinux/$app"))
74-
git pull $remote master
72+
cd "$dir"
73+
local remote
74+
remote=$(sed -En "s|(^[a-zA-Z0-9_-]*)[[:space:]].*|\1|p" \
75+
<<<"$(git remote -v | grep -m1 "turnkeylinux/$app")")
76+
git pull "$remote" master
7577
}
7678

7779
# 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
8688
fi
8789
else
8890
info "Downloading $dl source"
89-
git clone --depth=1 $GH_URL/$dl $BASE_DIR/$dl
91+
git clone --depth=1 $GH_URL/$dl "$BASE_DIR/$dl"
9092
fi
9193
done
9294

93-
app=$(sed "s|-|_|g" <<<$app)
95+
# TODO use ${variable//search/replace} instead of sed here
96+
app="$(sed "s|-|_|g" <<< "$app")"
9497
if [[ -z "$app" ]]; then
9598
warn "App name not given - continuing, but may fail later"
96-
elif ! ls $BASE_DIR/clicksnap/src/apps/ | grep -q -w "$app" \
99+
elif ! grep -r -q -w "$app" "$BASE_DIR"/clicksnap/src/apps/ \
97100
&& [[ -z "$no_screens" ]] ; then
98101
fatal "Clicksnap code for $app not found (checked in $BASE_DIR/clicksnap/src/apps/)"
99102
fi
@@ -102,30 +105,31 @@ fi
102105
deps="podman sed fab deck"
103106
missing=''
104107
for dep in $deps; do
105-
which $dep >/dev/null || missing="$missing $dep"
108+
which "$dep" >/dev/null || missing="$missing $dep"
106109
done
107-
[[ -z "$missing" ]] || install $missing
110+
[[ -z "$missing" ]] || install "$missing"
108111

109112
case "$(which cargo || echo 'fail')" in
110113
"$HOME/.cargo/bin/cargo")
111114
info "Rust installed via rustup detected, attempting update"
112-
rustup update;;
115+
rustup update
116+
;;
113117
/usr/bin/cargo)
114118
warn "system installed rust detected; continuing but may cause issues\n" \
115119
" - if you encountner issues, please remove rust and rerun";;
116120
fail)
117121
info "Installing rust via rustup"
118122
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
119-
echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" > $HOME/.bashrc.d/rust
120-
chmod +x $HOME/.bashrc.d/rust
121-
source $HOME/.bashrc.d/rust;;
123+
echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" > "$HOME"/.bashrc.d/rust
124+
chmod +x "$HOME"/.bashrc.d/rust
125+
source "$HOME/.bashrc.d/rust";;
122126
*)
123127
fatal "Unexpected cargo path: '$1'";;
124128
esac
125129

126-
cd $BASE_DIR/clicksnap
130+
cd "$BASE_DIR"/clicksnap
127131
info "Building & installing clicksnap"
128132
cargo build
129-
ln -sf $PWD/target/debug/clicksnap /usr/local/bin/clicksnap
130-
ln -sf $BASE_DIR/tkldev-docker/dockerize.sh /usr/local/bin/dockerize
131-
ln -sf $BASE_DIR/tkldev-docker/wait-ready.sh /usr/local/bin/tkl-docker-wait-ready
133+
ln -sf "$PWD"/target/debug/clicksnap /usr/local/bin/clicksnap
134+
ln -sf "$BASE_DIR"/tkldev-docker/dockerize.sh /usr/local/bin/dockerize
135+
ln -sf "$BASE_DIR"/tkldev-docker/wait-ready.sh /usr/local/bin/tkl-docker-wait-ready

0 commit comments

Comments
 (0)