fix: shellcheck's improvement

This commit is contained in:
Ravinou 2023-11-02 11:47:51 +01:00
parent 8a366d614e
commit eb9625a542
No known key found for this signature in database
GPG key ID: EEEE670C40F6A4D7
5 changed files with 13 additions and 11 deletions

View file

@ -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/

View file

@ -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

View file

@ -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 "[]"

View file

@ -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

View file

@ -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}')