Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script improvement #511

Merged
merged 6 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 8 additions & 1 deletion uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,19 @@ function delete_current_klippain {
else
echo "[WARNING] Klippain path not found! Nothing to delete here. Continuing..."
fi

rm -f ${KLIPPER_PATH}/klippy/extras/gcode_shell_command.py
Frix-x marked this conversation as resolved.
Show resolved Hide resolved
}

# Step 3: Find the latest backup without a .VERSION file and restore it if needed
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 +101,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