Skip to content

Commit

Permalink
Merge pull request #255 from fukamachi/fix/scripts-warnings
Browse files Browse the repository at this point in the history
Fix warnings in shell scripts.
  • Loading branch information
fukamachi authored Jul 12, 2024
2 parents 0c5aa7b + d79aa48 commit 97f51bd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci-scripts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CI for scripts

on:
push:
paths:
- 'scripts/**'

jobs:
test:
name: ShellCheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run ShellCheck
run: |
docker run --rm -v "$PWD:/mnt" koalaman/shellcheck:stable scripts/*
4 changes: 2 additions & 2 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ansi() {
[ -t 1 ] || ansi() { :; }
errmsg() { printf "%sError: %s%s\n" "$(ansi 31)" "$1" "$(ansi 0)"; }

if [ `id -u` -eq 0 ]; then
if [ "$(id -u)" -eq 0 ]; then
QLOT_BASE=${QLOT_BASE:-/usr/local}
QLOT_BIN_DIR=${QLOT_BIN_DIR:-$QLOT_BASE/bin}
else
Expand All @@ -33,7 +33,7 @@ printf '#!/bin/sh\nexport QLOT_SETUP_FILE=%s\nexec %s/scripts/run.sh "$@"\n' \
"$SETUP_FILE" "$QLOT_SOURCE_DIR" > "$QLOT_BIN_DIR/qlot"
chmod 755 "$QLOT_BIN_DIR/qlot"

if [ `id -u` -eq 0 ]; then
if [ "$(id -u)" -eq 0 ]; then
REGISTRY_DIR=/usr/local/share/common-lisp/systems
else
REGISTRY_DIR="${XDG_DATA_HOME:-~/.local/share}/common-lisp/systems"
Expand Down
22 changes: 11 additions & 11 deletions scripts/qlot-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -eu
VERSION=${VERSION:-heads/master}
QLOT_ARCHIVE=${QLOT_ARCHIVE:-https://github.com/fukamachi/qlot/archive/refs/$VERSION.tar.gz}

if [ `id -u` -eq 0 ]; then
if [ "$(id -u)" -eq 0 ]; then
QLOT_BASE=${QLOT_BASE:-/usr/local}
QLOT_HOME=${QLOT_HOME:-"$QLOT_BASE/lib/qlot"}
QLOT_BIN_DIR=${QLOT_BIN_DIR:-"$QLOT_BASE/bin"}
Expand Down Expand Up @@ -43,7 +43,7 @@ check_requirement() {
if [ $# -eq 1 ]; then
errmsg "$1 is required to install Qlot"
else
printf -v all_cmds '%s, ' "$@"
all_cmds=$(printf '%s, ' "$@")
errmsg "One of ${all_cmds%, } is required to install Qlot"
fi
exit 1
Expand Down Expand Up @@ -82,7 +82,7 @@ mkdir -p "$QLOT_TMP_DIR"
if [ -f "$QLOT_TMP_DIR/qlot.tar.gz" ]; then
echo "Already have an archive: $QLOT_TMP_DIR/qlot.tar.gz"
else
echo -n "Downloading an archive from '$QLOT_ARCHIVE'..."
printf "Downloading an archive from '%s'..." "$QLOT_ARCHIVE"
if [ "$(which curl 2>/dev/null)" != "" ]; then
curl -sL "$QLOT_ARCHIVE" -o "$QLOT_TMP_DIR/qlot.tar.gz"
else
Expand All @@ -93,7 +93,7 @@ fi
tar zxf "$QLOT_TMP_DIR/qlot.tar.gz" -C "$QLOT_TMP_DIR"

if [ -d "$QLOT_SOURCE_DIR/" ]; then
rm -rf "$QLOT_SOURCE_DIR/"
rm -rf "${QLOT_SOURCE_DIR:?}/"
fi
mv "$(find "$QLOT_TMP_DIR" -maxdepth 1 -mindepth 1 -type d -name "qlot*")" "$QLOT_SOURCE_DIR"

Expand All @@ -107,27 +107,27 @@ cd "$QLOT_SOURCE_DIR"
mkdir -p "$QLOT_LOGS_DIR"
install_log_path="$QLOT_LOGS_DIR/install-$(date '+%s').log"
echo "Setting it up. This may take a while..."
scripts/setup.sh > "$install_log_path" 2>&1
setup_success=$(scripts/setup.sh > "$install_log_path" 2>&1)

if [ $? -ne 0 ]; then
if [ "$setup_success" -ne 0 ]; then
errmsg "Setup process is failed. See '$install_log_path' for the detailed logs."
errmsg "If it can be a bug, please report an issue at https://github.com/fukamachi/qlot/issues."
exit $?
exit "$setup_success"
fi

QLOT_BIN_DIR="$QLOT_BIN_DIR" scripts/install.sh >> "$install_log_path" 2>&1
install_success=$(QLOT_BIN_DIR="$QLOT_BIN_DIR" scripts/install.sh >> "$install_log_path" 2>&1)

if [ $? -ne 0 ]; then
if [ "$install_success" -ne 0 ]; then
errmsg "Install process is failed. See '$install_log_path' for the detailed logs."
errmsg "If it can be a bug, please report an issue at https://github.com/fukamachi/qlot/issues."
exit $?
exit "$install_success"
fi

echo ''
success "Qlot v$(qlot_version) has been successfully installed under '$QLOT_HOME'."
echo ''

if [ `id -u` -ne 0 ]; then
if [ "$(id -u)" -ne 0 ]; then
echo "The executable script is located at '$QLOT_BIN_DIR/qlot'."
echo "To make it runnable by your shell, please add '$QLOT_BIN_DIR' to '\$PATH'."
echo ''
Expand Down
4 changes: 2 additions & 2 deletions scripts/qlot-uninstaller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -eu

if [ `id -u` -eq 0 ]; then
if [ "$(id -u)" -eq 0 ]; then
QLOT_BASE=${QLOT_BASE:-/usr/local}
QLOT_HOME=${QLOT_HOME:-"$QLOT_BASE/lib/qlot"}
QLOT_BIN_DIR=${QLOT_BIN_DIR:-"$QLOT_BASE/bin"}
Expand All @@ -24,7 +24,7 @@ ansi() {
rm "$QLOT_BIN_DIR"/qlot
rm -r "$QLOT_HOME"

if [ `id -u` -eq 0 ]; then
if [ "$(id -u)" -eq 0 ]; then
REGISTRY_DIR=/usr/local/share/common-lisp/systems
else
REGISTRY_DIR="${XDG_DATA_HOME:-~/.local/share}/common-lisp/systems"
Expand Down
3 changes: 2 additions & 1 deletion scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -e

QLOT_SOURCE_DIR=$(dirname -- "${0%/*}")
LISP=${LISP:-}

ansi() {
[ $# -gt 0 ] || return
Expand Down Expand Up @@ -81,7 +82,7 @@ if [ "$QLOT_SETUP_FILE" = "" ]; then
fi
fi

exec $lisp_cmd $lisp_init_options \
exec $lisp_cmd "$lisp_init_options" \
"$eval_option" "(let (*load-verbose*) (load \"$QLOT_SETUP_FILE\"))" \
"$eval_option" "(let (*load-verbose*) (asdf:load-asd #P\"$QLOT_SOURCE_DIR/qlot.asd\"))" \
"$eval_option" '(let ((*standard-output* (make-broadcast-stream)) (*trace-output* (make-broadcast-stream))) (asdf:load-system :qlot/cli))' \
Expand Down

0 comments on commit 97f51bd

Please sign in to comment.