From f7294e01e4c6d69d31b6bc5a53228ab3a1e60355 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 28 May 2025 20:40:24 +1200 Subject: [PATCH] :-'Generic Commit' --- source/agent-remote/_allservicesstatus.sh | 7 ++- source/agent-remote/common.sh | 30 +++++----- source/agent-remote/datacommands.sh | 68 +++++++++++++---------- source/build.sh | 21 +++---- source/publish.sh | 10 ++-- source/src/dropshell-completion.bash | 4 +- 6 files changed, 75 insertions(+), 65 deletions(-) diff --git a/source/agent-remote/_allservicesstatus.sh b/source/agent-remote/_allservicesstatus.sh index cef786f..6b0d52a 100755 --- a/source/agent-remote/_allservicesstatus.sh +++ b/source/agent-remote/_allservicesstatus.sh @@ -38,6 +38,7 @@ CURRENT_EXIT_CODE=0 load_dotenv(){ local file_path=$1 if [ -f "${file_path}" ]; then + # shellcheck source=/dev/null source "${file_path}" fi } @@ -69,9 +70,9 @@ function run_command() { load_dotenv "${service_path}/config/.template_info.env" # update the main variables. - CONFIG_PATH="${service_path}/config" - SERVICE="${SERVICE_NAME}" - DOCKER_CLI_HINTS=false + export CONFIG_PATH="${service_path}/config" + export SERVICE="${SERVICE_NAME}" + export DOCKER_CLI_HINTS=false set +a diff --git a/source/agent-remote/common.sh b/source/agent-remote/common.sh index 6b638fc..56abeef 100755 --- a/source/agent-remote/common.sh +++ b/source/agent-remote/common.sh @@ -41,18 +41,18 @@ _create_and_start_container() { local run_cmd="$1" local container_name="$2" - if _is_container_exists $container_name; then - _is_container_running $container_name && return 0 - _start_container $container_name + if _is_container_exists "$container_name"; then + _is_container_running "$container_name" && return 0 + _start_container "$container_name" else $run_cmd fi - if ! _is_container_running $container_name; then + if ! _is_container_running "$container_name"; then _die "Container ${container_name} failed to start" fi - ID=$(_get_container_id $container_name) + ID=$(_get_container_id "$container_name") echo "Container ${container_name} is running with ID ${ID}" } @@ -119,32 +119,32 @@ _get_container_status() { # Starts an existing, stopped container. _start_container() { - _is_container_exists $1 || return 1 - _is_container_running $1 && return 0 - docker start $1 + _is_container_exists "$1" || return 1 + _is_container_running "$1" && return 0 + docker start "$1" } # Stops a running container. _stop_container() { - _is_container_running $1 || return 0; - docker stop $1 + _is_container_running "$1" || return 0; + docker stop "$1" } # Stops (if needed) and removes a container. _remove_container() { - _stop_container $1 - _is_container_exists $1 || return 0; - docker rm $1 + _stop_container "$1" + _is_container_exists "$1" || return 0; + docker rm "$1" } # Prints the logs for a container. _get_container_logs() { - if ! _is_container_exists $1; then + if ! _is_container_exists "$1"; then echo "Container $1 does not exist" return 1 fi - docker logs $1 + docker logs "$1" } # Checks if listed environment variables are set; calls _die() if any are missing. diff --git a/source/agent-remote/datacommands.sh b/source/agent-remote/datacommands.sh index c752cbb..12a1087 100755 --- a/source/agent-remote/datacommands.sh +++ b/source/agent-remote/datacommands.sh @@ -12,26 +12,26 @@ _autocommandrun_volume() { case "$command" in create) - if docker volume ls | grep -q ${volume_name}; then + if docker volume ls | grep -q "${volume_name}"; then echo "Volume ${volume_name} already exists - leaving unchanged" return fi echo "Creating volume ${volume_name}" - docker volume create ${volume_name} + docker volume create "${volume_name}" ;; destroy) echo "Destroying volume ${volume_name}" - docker volume rm ${volume_name} + docker volume rm "${volume_name}" ;; backup) echo "Backing up volume ${volume_name}" - docker run --rm -v ${volume_name}:/volume -v ${backup_folder}:/backup debian bash -c "tar -czvf /backup/backup.tgz -C /volume . && chown -R $MYID:$MYGRP /backup" + docker run --rm -v "${volume_name}":/volume -v "${backup_folder}":/backup debian bash -c "tar -czvf /backup/backup.tgz -C /volume . && chown -R $MYID:$MYGRP /backup" ;; restore) echo "Restoring volume ${volume_name}" - docker volume rm ${volume_name} - docker volume create ${volume_name} - docker run --rm -v ${volume_name}:/volume -v ${backup_folder}:/backup debian bash -c "tar -xzvf /backup/backup.tgz -C /volume --strip-components=1" + docker volume rm "${volume_name}" + docker volume create "${volume_name}" + docker run --rm -v "${volume_name}":/volume -v "${backup_folder}":/backup debian bash -c "tar -xzvf /backup/backup.tgz -C /volume --strip-components=1" ;; esac } @@ -48,14 +48,16 @@ _autocommandrun_path() { return fi echo "Creating path ${path}" - mkdir -p ${path} + mkdir -p "${path}" ;; destroy) echo "Destroying path ${path}" - local path_parent=$(dirname ${path}) - local path_child=$(basename ${path}) + local path_parent; + path_parent=$(dirname "${path}") + local path_child; + path_child=$(basename "${path}") if [ -d "${path_parent}/${path_child}" ]; then - docker run --rm -v ${path_parent}:/volume debian bash -c "rm -rfv /volume/${path_child}" || echo "Failed to destroy path ${path}" + docker run --rm -v "${path_parent}":/volume debian bash -c "rm -rfv /volume/${path_child}" || echo "Failed to destroy path ${path}" else echo "Path ${path} does not exist - nothing to destroy" fi @@ -63,7 +65,7 @@ _autocommandrun_path() { backup) echo "Backing up path ${path}" if [ -d "${path}" ]; then - docker run --rm -v ${path}:/path -v ${backup_folder}:/backup debian bash -c "tar -czvf /backup/backup.tgz -C /path . && chown -R $MYID:$MYGRP /backup" + docker run --rm -v "${path}":/path -v "${backup_folder}":/backup debian bash -c "tar -czvf /backup/backup.tgz -C /path . && chown -R $MYID:$MYGRP /backup" else echo "Path ${path} does not exist - nothing to backup" fi @@ -73,9 +75,9 @@ _autocommandrun_path() { echo "Backup file ${backup_folder}/backup.tgz does not exist - nothing to restore" else echo "Clearing existing data in path ${path}" - docker run --rm -v ${path}:/path debian bash -c "rm -rfv /path/{*,.*}" + docker run --rm -v "${path}":/path debian bash -c "rm -rfv /path/{*,.*}" echo "Restoring path ${path} from backup file ${backup_folder}/backup.tgz" - tar -xzvf ${backup_folder}/backup.tgz -C ${path} --strip-components=1 + tar -xzvf "${backup_folder}/backup.tgz" -C "${path}" --strip-components=1 fi ;; esac @@ -88,31 +90,36 @@ _autocommandrun_file() { case "$command" in create) - filepath_parent=$(dirname ${filepath}) - filepath_child=$(basename ${filepath}) - if [ ! -d "${filepath_parent}" ]; then - echo "Parent directory ${filepath_parent} of ${filepath_child} does not exist - creating" - mkdir -p ${filepath_parent} + local file_parent; + file_parent=$(dirname "${filepath}") + local file_name; + file_name=$(basename "${filepath}") + if [ ! -d "${file_parent}" ]; then + echo "Parent directory ${file_parent} of ${file_name} does not exist - creating" + mkdir -p "${file_parent}" fi ;; destroy) - rm -f ${filepath} + rm -f "${filepath}" ;; backup) echo "Backing up file ${filepath}" - local file_parent=$(dirname ${filepath}) - local file_name=$(basename ${filepath}) + local file_parent; + file_parent=$(dirname "${filepath}") + local file_name; + file_name=$(basename "${filepath}") if [ -f "${file_parent}/${file_name}" ]; then - docker run --rm -v ${file_parent}:/volume -v ${backup_folder}:/backup debian bash -c "cp /volume/${file_name} /backup/${file_name} && chown -R $MYID:$MYGRP /backup" + docker run --rm -v "${file_parent}":/volume -v "${backup_folder}":/backup debian bash -c "cp /volume/${file_name} /backup/${file_name} && chown -R $MYID:$MYGRP /backup" else echo "File ${filepath} does not exist - nothing to backup" fi ;; restore) echo "Restoring file ${filepath}" - local file_name=$(basename ${filepath}) - rm -f ${filepath} || die "Unable to remove existing file ${filepath}, restore failed." - cp ${backup_folder}/${file_name} ${filepath} || die "Unable to copy file ${backup_folder}/${file_name} to ${filepath}, restore failed." + local file_name; + file_name=$(basename "${filepath}") + rm -f "${filepath}" || die "Unable to remove existing file ${filepath}, restore failed." + cp "${backup_folder}/${file_name}" "${filepath}" || die "Unable to copy file ${backup_folder}/${file_name} to ${filepath}, restore failed." ;; esac } @@ -153,9 +160,10 @@ _autocommandparse() { local value="${pair#*=}" # create backup folder unique to key/value. - local bfolder=$(echo "${key}_${value}" | tr -cd '[:alnum:]_-') + local bfolder; + bfolder=$(echo "${key}_${value}" | tr -cd '[:alnum:]_-') local targetpath="${backup_temp_path}/${bfolder}" - mkdir -p ${targetpath} + mkdir -p "${targetpath}" # Key must be one of volume, path or file case "$key" in @@ -191,7 +199,7 @@ databackup() { mkdir -p "$BACKUP_TEMP_PATH" - echo "_autocommandparse [backup] [$BACKUP_TEMP_PATH] [$@]" + echo "_autocommandparse [backup] [$BACKUP_TEMP_PATH]" "$@" _autocommandparse backup "$BACKUP_TEMP_PATH" "$@" tar zcvf "$BACKUP_FILE" -C "$BACKUP_TEMP_PATH" . @@ -201,7 +209,7 @@ datarestore() { _check_required_env_vars "BACKUP_FILE" "TEMP_DIR" BACKUP_TEMP_PATH="$TEMP_DIR/restore" - echo "_autocommandparse [restore] [$BACKUP_TEMP_PATH] [$@]" + echo "_autocommandparse [restore] [$BACKUP_TEMP_PATH]" "$@" mkdir -p "$BACKUP_TEMP_PATH" tar zxvf "$BACKUP_FILE" -C "$BACKUP_TEMP_PATH" --strip-components=1 diff --git a/source/build.sh b/source/build.sh index 527bd0d..d2a7ebc 100755 --- a/source/build.sh +++ b/source/build.sh @@ -3,7 +3,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" OUTPUT_DIR=${SCRIPT_DIR}/output INSTALL_DIR=${HOME}/.local/bin -mkdir -p ${OUTPUT_DIR} +mkdir -p "${OUTPUT_DIR}" # Exit on error set -e @@ -11,29 +11,30 @@ set -e function build_native() { local BUILDDIR=${SCRIPT_DIR}/build/native local PREVDIR=$PWD - local JOBS=$(nproc) # Set JOBS to the number of available CPU cores - mkdir -p ${BUILDDIR} - cd ${SCRIPT_DIR} + local JOBS; + JOBS=$(nproc) # Set JOBS to the number of available CPU cores + mkdir -p "${BUILDDIR}" + cd "${SCRIPT_DIR}" || exit 1 CC="${HOME}/.musl-cross/x86_64-linux-musl-native/bin/x86_64-linux-musl-gcc" CXX="${HOME}/.musl-cross/x86_64-linux-musl-native/bin/x86_64-linux-musl-g++" - cmake -B ${BUILDDIR} -G Ninja \ + cmake -B "${BUILDDIR}" -G Ninja \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_LINKER=mold \ - -DCMAKE_C_COMPILER=${CC} \ - -DCMAKE_CXX_COMPILER=${CXX} + -DCMAKE_C_COMPILER="${CC}" \ + -DCMAKE_CXX_COMPILER="${CXX}" - cd ${BUILDDIR} + cd "${BUILDDIR}" || exit 1 ninja -j"$JOBS" #upx ${BUILDDIR}/dropshell - cp ${BUILDDIR}/dropshell ${OUTPUT_DIR}/dropshell.native + cp "${BUILDDIR}/dropshell" "${OUTPUT_DIR}/dropshell.native" - cd ${PREVDIR} + cd "${PREVDIR}" || exit 1 } build_native diff --git a/source/publish.sh b/source/publish.sh index 0445a3d..7b8b254 100755 --- a/source/publish.sh +++ b/source/publish.sh @@ -9,11 +9,11 @@ echo "Script directory: $SCRIPT_DIR" TOKEN="${GITEA_TOKEN_DEPLOY:-${GITEA_TOKEN}}" [ -z "$TOKEN" ] && { echo "Neither GITEA_TOKEN_DEPLOY nor GITEA_TOKEN environment variable set!" >&2; exit 1; } -$SCRIPT_DIR/multibuild.sh -BUILD_DIR=$SCRIPT_DIR/build +"$SCRIPT_DIR/multibuild.sh" +#BUILD_DIR=$SCRIPT_DIR/build -OLD_PWD=$PWD -cd $SCRIPT_DIR +OLD_PWD="$PWD" +cd "$SCRIPT_DIR" || exit 1 # Check for required binaries REQUIRED_BINARIES=("dropshell.x86_64" "dropshell.aarch64") @@ -115,4 +115,4 @@ done echo "Published dropshell version $TAG to $REPO_URL (tag $TAG) with binaries." -cd $OLD_PWD \ No newline at end of file +cd "$OLD_PWD" || exit 1 \ No newline at end of file diff --git a/source/src/dropshell-completion.bash b/source/src/dropshell-completion.bash index 0bd5a1d..4509a99 100755 --- a/source/src/dropshell-completion.bash +++ b/source/src/dropshell-completion.bash @@ -6,8 +6,8 @@ _dropshell_completions() { cur="${COMP_WORDS[COMP_CWORD]}" # call dropshell to get the list of possiblities for the current argument. Supply all previous arguments. - local completions=($(dropshell autocomplete "${COMP_WORDS[@]:1:${COMP_CWORD}-1}")) - COMPREPLY=( $(compgen -W "${completions[*]}" -- ${cur}) ) + mapfile -t completions < <(dropshell autocomplete "${COMP_WORDS[@]:1:${COMP_CWORD}-1}") + mapfile -t COMPREPLY < <(compgen -W "${completions[*]}" -- "$cur") return 0 }