diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 69da7cf..d9566c0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,7 @@ +# Run test against shells with "pre-commit run shellcheck --all-files" repos: - - repo: https://github.com/jumanjihouse/pre-commit-hooks - rev: 3.0.0 - hooks: - - id: shellcheck + - repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 3.0.0 + hooks: + - id: shellcheck + files: helpers/shells/ diff --git a/helpers/shells/deleteRepo.sh b/helpers/shells/deleteRepo.sh index 8883193..c725908 100755 --- a/helpers/shells/deleteRepo.sh +++ b/helpers/shells/deleteRepo.sh @@ -36,12 +36,12 @@ fi # Delete the repository and the line associated in the authorized_keys file if [ -d "${pool}/${repositoryName}" ]; then # Delete the repository - rm -rf "${pool}/${repositoryName}" + rm -rf """${pool}""/""${repositoryName:?}""" # Delete the line in the authorized_keys file sed -i "/${repositoryName}/d" "${authorized_keys}" - echo -n "The folder "${pool}/${repositoryName}" and all its data have been deleted. The line associated in the authorized_keys file has been deleted." + echo -n "The folder ""${pool}"/"${repositoryName}"" and all its data have been deleted. The line associated in the authorized_keys file has been deleted." else # Delete the line in the authorized_keys file sed -i "/${repositoryName}/d" "${authorized_keys}" - echo -n "The folder "${pool}/${repositoryName}" did not exist (repository never initialized or used). The line associated in the authorized_keys file has been deleted." + echo -n "The folder ""${pool}"/"${repositoryName}"" did not exist (repository never initialized or used). The line associated in the authorized_keys file has been deleted." fi \ No newline at end of file diff --git a/helpers/shells/getLastSave.sh b/helpers/shells/getLastSave.sh index a7ca79f..0c7d58b 100755 --- a/helpers/shells/getLastSave.sh +++ b/helpers/shells/getLastSave.sh @@ -26,9 +26,9 @@ fi # Default value if .env not exists : "${home:=/home/borgwarehouse}" -if [ -n "$(find ${home}/repos -mindepth 1 -maxdepth 1 -type d)" ]; then +if [ -n "$(find "${home}"/repos -mindepth 1 -maxdepth 1 -type d)" ]; then stat --format='{"repositoryName":"%n","lastSave":%Y}' \ - ${home}/repos/*/integrity* | + "${home}"/repos/*/integrity* | jq --slurp '[.[] | .repositoryName = (.repositoryName | split("/")[-2])]' else echo "[]" diff --git a/helpers/shells/getStorageUsed.sh b/helpers/shells/getStorageUsed.sh index 106c758..682413f 100755 --- a/helpers/shells/getStorageUsed.sh +++ b/helpers/shells/getStorageUsed.sh @@ -23,5 +23,5 @@ fi : "${home:=/home/borgwarehouse}" # Use jc to output a JSON format with du command -cd ${home}/repos +cd "${home}"/repos du -s -- * | jc --du diff --git a/helpers/shells/updateRepo.sh b/helpers/shells/updateRepo.sh index 400bc7b..9faae6f 100755 --- a/helpers/shells/updateRepo.sh +++ b/helpers/shells/updateRepo.sh @@ -50,7 +50,7 @@ regex="command=\".*${repositoryName}.*\",restrict" while IFS= read -r line; do if [[ $line =~ $pattern ]]; then # Get the SSH pub key of the line (ignore the comment) - key1=$(echo ${BASH_REMATCH[0]} | awk '{print $1 " " $2}') + key1=$(echo "${BASH_REMATCH[0]}" | awk '{print $1 " " $2}') # Get the SSH pub key of the new SSH pub key (ignore the comment) key2=$(echo "$2" | awk '{print $1 " " $2}')