mirror of
https://github.com/Ravinou/borgwarehouse
synced 2024-05-15 20:16:50 +02:00
fix: remove \n in end of the error msg
This commit is contained in:
parent
ad46df61a3
commit
1d1c4e01d6
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue