Update update-restic.sh to use a temporary directory for cloning and cleanup

- Modify the script to create a unique temporary directory for cloning the repository
- Change the script to remove the temporary directory after execution
- Ensure the repository is cloned into the temporary directory and cleaned up after the script is done running
This commit is contained in:
Laurent Le Houerou 2023-03-27 10:34:22 +04:00
parent 7358e2814a
commit 0d908159c1

View File

@ -18,9 +18,10 @@ if ! grep -q "^relayhost" $POSTFIX_CONFIG; then
exit 1
fi
# Clone the repository
git clone $GIT_REPO
cd restic-docker
# Create a temporary directory and clone the repository
TEMP_DIR=$(mktemp -d)
git clone $GIT_REPO $TEMP_DIR
cd $TEMP_DIR
# Get the latest version of Restic
LATEST_VERSION=$(curl --silent "https://api.github.com/repos/restic/restic/releases/latest" | jq -r .tag_name | tr -d v)
@ -46,3 +47,7 @@ if [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then
else
echo "The Restic Docker image is already up to date (version $CURRENT_VERSION)."
fi
# Clean up the temporary directory
cd ..
rm -rf $TEMP_DIR