Skip to content

Commit

Permalink
install and uninstall scripts improvement (#511)
Browse files Browse the repository at this point in the history
* Don't fail uninstall if the backup folder has been removed
* Make uninstall work when backup has sub-directories
* Make sure we don't fail making a backup when there is no current user config folder
  • Loading branch information
magne authored Mar 4, 2024
1 parent 228f5bc commit bad68da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ function check_download {
if [ ! -d "${FRIX_CONFIG_PATH}" ]; then
echo "[DOWNLOAD] Downloading Klippain repository..."
if git -C $frixtemppath clone -b $frixbranchname https://github.com/Frix-x/klippain.git $frixreponame; then
chmod +x ${FRIX_CONFIG_PATH}/install.sh
printf "[DOWNLOAD] Download complete!\n\n"
else
echo "[ERROR] Download of Klippain git repository failed!"
Expand All @@ -94,6 +93,11 @@ function check_download {

# Step 3: Backup the old Klipper configuration
function backup_config {
if [ ! -e "${USER_CONFIG_PATH}" ]; then
printf "[BACKUP] No previous config found, skipping backup...\n\n"
return 0
fi

mkdir -p ${BACKUP_DIR}

# Copy every files from the user config ("2>/dev/null || :" allow it to fail silentely in case the config dir doesn't exist)
Expand All @@ -104,7 +108,7 @@ function backup_config {
# If Klippain is not already installed (we check for .VERSION in the backup to detect it),
# we need to remove, wipe and clean the current user config folder...
if [ ! -f "${BACKUP_DIR}/.VERSION" ]; then
rm -R ${USER_CONFIG_PATH}
rm -fR ${USER_CONFIG_PATH}
fi

printf "[BACKUP] Backup of current user config files done in: ${BACKUP_DIR}\n\n"
Expand Down
7 changes: 6 additions & 1 deletion uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ function delete_current_klippain {
function restore_latest_backup {
local restore_backup latest_backup

if [[ ! -e "${BACKUP_PATH}" ]]; then
printf "[RESTORE] No backup folder found! Skipping...\n\n"
return
fi

read < /dev/tty -rp "[RESTORE] Would you like to restore your last config backup? This script will look for the last one before running Klippain (Y/n) " restore_backup
if [[ -z "$restore_backup" ]]; then
restore_backup="y"
Expand All @@ -94,7 +99,7 @@ function restore_latest_backup {
return
fi

latest_backup=$(find ${BACKUP_PATH} -type d -not -path "${BACKUP_PATH}" -exec sh -c 'if [ ! -f "$1/.VERSION" ]; then echo "$1"; fi' sh {} \; | sort -r | head -n 1)
latest_backup=$(find ${BACKUP_PATH} -maxdepth 1 -type d -not -path "${BACKUP_PATH}" -exec sh -c 'if [ ! -f "$1/.VERSION" ]; then echo "$1"; fi' sh {} \; | sort -r | head -n 1)
if [ -n "${latest_backup}" ]; then
cp -fa ${latest_backup}/. ${USER_CONFIG_PATH} 2>/dev/null || :
printf "[RESTORE] Latest backup restored from: ${latest_backup}\n\n"
Expand Down

0 comments on commit bad68da

Please sign in to comment.