fix: remove \n in end of the error msg

This commit is contained in:
Ravinou 2023-09-03 15:31:15 +02:00
parent ad46df61a3
commit 1d1c4e01d6
No known key found for this signature in database
GPG key ID: EEEE670C40F6A4D7
3 changed files with 14 additions and 14 deletions

View file

@ -32,7 +32,7 @@ authorized_keys="${home}/.ssh/authorized_keys"
# Check args
if [ "$1" == "" ] || [ "$2" == "" ];then
echo "This shell takes 2 arguments : SSH Public Key, Quota in Go [e.g. : 10] "
echo -n "This shell takes 2 arguments : SSH Public Key, Quota in Go [e.g. : 10] "
exit 1
fi
@ -41,19 +41,19 @@ fi
pattern='(ssh-ed25519 AAAAC3NzaC1lZDI1NTE5|sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29t|ssh-rsa AAAAB3NzaC1yc2)[0-9A-Za-z+/]+[=]{0,3}(\s.*)?'
if [[ ! "$1" =~ $pattern ]]
then
echo "Invalid public SSH KEY format. Provide a key in OpenSSH format (rsa, ed25519, ed25519-sk)"
echo -n "Invalid public SSH KEY format. Provide a key in OpenSSH format (rsa, ed25519, ed25519-sk)"
exit 2
fi
# Check if SSH pub key is already present in authorized_keys
if grep -q "$1" "$authorized_keys"; then
echo "SSH pub key already present in authorized_keys"
echo -n "SSH pub key already present in authorized_keys"
exit 3
fi
# Check if borgbackup is installed
if ! [ -x "$(command -v borg)" ]; then
echo "You must install borgbackup package."
echo -n "You must install borgbackup package."
exit 4
fi
@ -65,7 +65,7 @@ repositoryName=$(randRepositoryName)
## Check if authorized_keys exists
if [ ! -f "${authorized_keys}" ];then
echo "${authorized_keys} must be present"
echo -n "${authorized_keys} must be present"
exit 5
fi

View file

@ -21,7 +21,7 @@ authorized_keys="${home}/.ssh/authorized_keys"
# Check arg
if [[ $# -ne 1 || $1 = "" ]]; then
echo "You must provide a repositoryName in argument."
echo -n "You must provide a repositoryName in argument."
exit 1
fi
@ -29,7 +29,7 @@ fi
# If we receive another length there is necessarily a problem.
repositoryName=$1
if [ ${#repositoryName} != 8 ]; then
echo "Error with the length of the repositoryName."
echo -n "Error with the length of the repositoryName."
exit 2
fi
@ -39,11 +39,11 @@ if [ -d "$1" ]; then
rm -rf "${pool}/${repositoryName}"
# Delete the line in the authorized_keys file
sed -i "/${repositoryName}/d" "${authorized_keys}"
echo "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."
exit 3
else
# Delete the line in the authorized_keys file
sed -i "/${repositoryName}/d" "${authorized_keys}"
echo "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."
exit 3
fi

View file

@ -17,7 +17,7 @@ fi
# Check args
if [ "$1" == "" ] || [ "$2" == "" ] || [ "$3" == "" ]; then
echo "This shell takes 3 args: [repositoryName] [new SSH pub key] [quota]"
echo -n "This shell takes 3 args: [repositoryName] [new SSH pub key] [quota]"
exit 1
fi
@ -26,7 +26,7 @@ fi
pattern='(ssh-ed25519 AAAAC3NzaC1lZDI1NTE5|sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29t|ssh-rsa AAAAB3NzaC1yc2)[0-9A-Za-z+/]+[=]{0,3}(\s.*)?'
if [[ ! "$2" =~ $pattern ]]
then
echo "Invalid public SSH KEY format. Provide a key in OpenSSH format (rsa, ed25519, ed25519-sk)"
echo -n "Invalid public SSH KEY format. Provide a key in OpenSSH format (rsa, ed25519, ed25519-sk)"
exit 2
fi
@ -34,13 +34,13 @@ fi
# If we receive another length, there is necessarily a problem.
repositoryName=$1
if [ ${#repositoryName} != 8 ]; then
echo "Error with the length of the repositoryName."
echo -n "Error with the length of the repositoryName."
exit 3
fi
# Check if a line in authorized_keys contains repository_name
if ! grep -q "command=\".*${repositoryName}.*\",restrict" "$home/.ssh/authorized_keys"; then
echo "No line containing $repositoryName found in authorized_keys"
echo -n "No line containing $repositoryName found in authorized_keys"
exit 4
fi
@ -64,7 +64,7 @@ while IFS= read -r line; do
fi
done < "$home/.ssh/authorized_keys"
if [ "$found" = true ]; then
echo "The new SSH pub key $2 is already present in authorized_keys on a different line."
echo -n "The new SSH pub key $2 is already present in authorized_keys on a different line."
exit 5
fi