2023-06-08 12:59:00 +02:00
#!/usr/bin/env bash
2022-12-01 13:25:10 +01:00
# Shell created by Raven for BorgWarehouse.
2023-08-20 16:40:23 +02:00
# This shell takes 1 arg : [repositoryName] with 8 char. length only.
# This shell **delete the repository** in arg and **all his data** and the line associated in the authorized_keys file.
2022-12-01 13:25:10 +01:00
# Exit when any command fails
set -e
2023-08-20 16:40:23 +02:00
# Load .env if exists
if [ [ -f .env ] ] ; then
source .env
fi
# Default value if .env not exists
: " ${ home : =/home/borgwarehouse } "
# Some variables
pool = " ${ home } /repos "
authorized_keys = " ${ home } /.ssh/authorized_keys "
2022-12-01 13:25:10 +01:00
# Check arg
2022-12-17 02:23:42 +01:00
if [ [ $# -ne 1 || $1 = "" ] ] ; then
2023-09-03 15:31:15 +02:00
echo -n "You must provide a repositoryName in argument."
2022-12-01 13:25:10 +01:00
exit 1
fi
2023-08-20 16:40:23 +02:00
# Check if the repositoryName length is 8 char. With createRepo.sh our randoms have a length of 8 characters.
2022-12-01 13:25:10 +01:00
# If we receive another length there is necessarily a problem.
2023-08-20 16:40:23 +02:00
repositoryName = $1
if [ ${# repositoryName } != 8 ] ; then
2023-09-03 15:31:15 +02:00
echo -n "Error with the length of the repositoryName."
2022-12-01 13:25:10 +01:00
exit 2
fi
2023-08-20 16:40:23 +02:00
# Delete the repository and the line associated in the authorized_keys file
2023-09-23 18:09:10 +02:00
if [ -d " ${ pool } / ${ repositoryName } " ] ; then
2023-08-20 16:40:23 +02:00
# Delete the repository
2023-11-02 11:47:51 +01:00
rm -rf "" " ${ pool } " "/" " ${ repositoryName : ? } " ""
2023-08-20 16:40:23 +02:00
# Delete the line in the authorized_keys file
sed -i " / ${ repositoryName } /d " " ${ authorized_keys } "
2023-11-02 11:47:51 +01:00
echo -n "The folder " " ${ pool } " /" ${ repositoryName } " " and all its data have been deleted. The line associated in the authorized_keys file has been deleted."
2022-12-01 13:25:10 +01:00
else
2023-08-20 16:40:23 +02:00
# Delete the line in the authorized_keys file
sed -i " / ${ repositoryName } /d " " ${ authorized_keys } "
2023-11-02 11:47:51 +01:00
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."
2023-08-20 16:40:23 +02:00
fi