From c6f39687bfbb313c49c3da19f744f3de7adb4d81 Mon Sep 17 00:00:00 2001 From: sc74 Date: Sat, 9 May 2026 21:52:15 +0200 Subject: [PATCH 1/3] Check the permissions for mkdir --- scripts/backup-astroarch.sh | 49 ++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/scripts/backup-astroarch.sh b/scripts/backup-astroarch.sh index ea2fcb8..e23df27 100755 --- a/scripts/backup-astroarch.sh +++ b/scripts/backup-astroarch.sh @@ -10,6 +10,35 @@ is_gui() { [[ -n "$DISPLAY" && -z "$SSH_CLIENT" ]]; } # Update specific keys in the config file update_config() { sed -i "s|^$1=.*|$1=\"$2\"|" "$CONFIG_FILE"; } +ask_valid_dest() { + local PROMPT="$1" + local DEFAULT="$2" + local PATH_OK=false + + while [ "$PATH_OK" = false ]; do + if is_gui; then + DEST_PATH=$(kdialog --inputbox "$PROMPT" "$DEFAULT") + [ -z "$DEST_PATH" ] && exit 0 + else + read -p "$PROMPT (or Enter to quit): " DEST_PATH + [ -z "$DEST_PATH" ] && exit 0 + fi + + [[ "$DEST_PATH" != */backup ]] && DEST_PATH="${DEST_PATH%/}/backup" + + if mkdir -p "$DEST_PATH" 2>/dev/null; then + PATH_OK=true + else + MSG_PERM="⚠️ Cannot create \"$DEST_PATH\": permission denied." + if is_gui; then + kdialog --title "Permission Denied" --error "$MSG_PERM" + else + echo -e "$MSG_PERM" + fi + fi + done +} + # --- NEW CLEANING FEATURE --- cleanup_canceled_backup() { local DEST="$1" @@ -77,7 +106,7 @@ if [ ! -f "$CONFIG_FILE" ]; then fi [ -z "$DEST_PATH" ] && DEST_PATH="$DEFAULT_DEST" - mkdir -p "$DEST_PATH" 2>/dev/null + ask_valid_dest "First backup. Choose storage location:" "$DEFAULT_DEST" FIRST_BACKUP="yes" AUTO_CHOICE="Ask" @@ -104,7 +133,7 @@ else ask_confirmation "New confirmation mode:" fi - mkdir -p "$DEST_PATH" 2>/dev/null + ask_valid_dest "New location:" "$DEST_PATH" update_config "DEST_PATH" "$DEST_PATH" update_config "AUTO_CHOICE" "$AUTO_CHOICE" SKIP_FINAL_PROMPT="true" @@ -128,7 +157,21 @@ fi # --- 3. DISK SPACE VALIDATION LOOP --- VALID_SPACE=false while [ "$VALID_SPACE" = false ]; do - mkdir -p "$DEST_PATH" 2>/dev/null + if ! mkdir -p "$DEST_PATH" 2>/dev/null; then + MSG_PERM="⚠️ Cannot create folder \"$DEST_PATH\".\nPermission denied." + if is_gui; then + kdialog --title "Permission Denied" --warningcontinuecancel "$MSG_PERM" \ + --continue-label "Choose another location" --cancel-label "Abort" || exit 0 + DEST_PATH=$(kdialog --inputbox "New location:" "$DEFAULT_DEST") + [ -z "$DEST_PATH" ] && exit 0 + else + echo -e "$MSG_PERM" + read -p "New path (or Enter to quit): " DEST_PATH + [ -z "$DEST_PATH" ] && exit 0 + fi + update_config "DEST_PATH" "$DEST_PATH" + continue + fi ABS_DEST=$(realpath "$DEST_PATH") EXCLUSIONS=(--exclude='/dev/*' --exclude='/proc/*' --exclude='/sys/*' --exclude='/tmp/*' --exclude='/run/*' --exclude='/mnt/*' --exclude='/media/*' --exclude='/lost+found/' --exclude='/boot/*' --exclude='*/thinclient_drives' --exclude='*/.gvfs' --exclude="$ABS_DEST") From 1e53adbc781b112b309f5032ca8dad59921908bc Mon Sep 17 00:00:00 2001 From: sc74 Date: Sun, 10 May 2026 22:28:59 +0200 Subject: [PATCH 2/3] Set LC_ALL=C --- scripts/backup-astroarch.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/backup-astroarch.sh b/scripts/backup-astroarch.sh index e23df27..6164f8b 100755 --- a/scripts/backup-astroarch.sh +++ b/scripts/backup-astroarch.sh @@ -1,4 +1,5 @@ #!/bin/bash +export LC_ALL=C # --- 1. INITIALIZATION --- CONFIG_FILE="$HOME/.backup_dest" @@ -176,9 +177,9 @@ while [ "$VALID_SPACE" = false ]; do EXCLUSIONS=(--exclude='/dev/*' --exclude='/proc/*' --exclude='/sys/*' --exclude='/tmp/*' --exclude='/run/*' --exclude='/mnt/*' --exclude='/media/*' --exclude='/lost+found/' --exclude='/boot/*' --exclude='*/thinclient_drives' --exclude='*/.gvfs' --exclude="$ABS_DEST") echo "Analyzing space on $ABS_DEST..." - ROOT_SIZE=$(sudo -n rsync -aAXHvx --delete --dry-run --stats "${EXCLUSIONS[@]}" / "$ABS_DEST" | grep "Total transferred file size" | awk '{print $5}' | tr -d ',') + ROOT_SIZE=$(sudo -n env LC_ALL=C rsync -aAXHvx --delete --dry-run --stats "${EXCLUSIONS[@]}" / "$ABS_DEST" | grep "Total transferred file size" | awk '{print $5}' | tr -d ',.') [ -z "$ROOT_SIZE" ] && ROOT_SIZE=0 - AVAILABLE_SIZE=$(df -B1 "$ABS_DEST" | tail -1 | awk '{print $4}') + AVAILABLE_SIZE=$(LC_ALL=C df --output=avail -B1 "$ABS_DEST" | tail -1 | tr -d ' ') TRANS_HUMAN=$(numfmt --to=iec-i --suffix=B $ROOT_SIZE) AVAIL_HUMAN=$(numfmt --to=iec-i --suffix=B $AVAILABLE_SIZE) From e79263c1b84cd11d8a16af9a2e7b34b39cc0f678 Mon Sep 17 00:00:00 2001 From: sc74 Date: Fri, 15 May 2026 13:14:11 +0200 Subject: [PATCH 3/3] Wait until DBUS_SESSION_BUS_ADDRESS is set --- scripts/backup-astroarch.sh | 68 +++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/scripts/backup-astroarch.sh b/scripts/backup-astroarch.sh index 6164f8b..7bf41f9 100755 --- a/scripts/backup-astroarch.sh +++ b/scripts/backup-astroarch.sh @@ -40,7 +40,7 @@ ask_valid_dest() { done } -# --- NEW CLEANING FEATURE --- +# --- CLEANING FEATURE --- cleanup_canceled_backup() { local DEST="$1" # Deletes the corrupted folder (requires sudo because rsync preserves root permissions) @@ -97,16 +97,9 @@ if [ ! -f "$CONFIG_FILE" ]; then

Please note: if you cancel the backup while it is in progress, the backup folder and the configuration file will be deleted

The backup will take some time...

" 600 500 - - DEST_PATH=$(kdialog --inputbox "First backup. Choose storage location:" "$DEFAULT_DEST") - else - read -p "First installation. Location [$DEFAULT_DEST]: " DEST_PATH - fi - if [[ "$DEST_PATH" != */backup ]]; then - DEST_PATH="${DEST_PATH%/}/backup" fi - [ -z "$DEST_PATH" ] && DEST_PATH="$DEFAULT_DEST" + # ask_valid_dest handles everything: prompt, validation, mkdir ask_valid_dest "First backup. Choose storage location:" "$DEFAULT_DEST" FIRST_BACKUP="yes" AUTO_CHOICE="Ask" @@ -220,23 +213,48 @@ fi # --- 5. EXECUTION --- if is_gui; then - dbus_ref=$(kdialog --progressbar "Initializing backup..." 100) - sudo -n rsync -aAXHxh --delete --no-inc-recursive --info=progress2 "${EXCLUSIONS[@]}" / "$ABS_DEST" 2>/dev/null | \ - stdbuf -oL tr '\r' '\n' | grep --line-buffered -oP '[0-9]+(?=%)' | \ - while read -r percent; do - ((count++)) - if (( count % 5 == 0 )); then - # IF CANCELED BY THE USER - if ! qdbus6 $dbus_ref >/dev/null 2>&1; then - sudo pkill -f "rsync.*$ABS_DEST" - cleanup_canceled_backup "$ABS_DEST" - fi - qdbus6 $dbus_ref setLabelText "Copying: $percent% of $TRANS_HUMAN" - qdbus6 $dbus_ref Set "" value "$percent" - fi + + # --- D-Bus session detection --- + # If DBUS_SESSION_BUS_ADDRESS is not set (e.g. launched from Calamares at session start + # before the bus is ready), build the standard systemd socket path for user astronaut. + if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then + USER_ID=$(id -u astronaut 2>/dev/null || id -u) + export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/${USER_ID}/bus" + fi + + # Wait until the D-Bus socket is actually available (max 30s). + # This handles the race condition where Calamares autostart launches + # before the KDE session bus is fully initialised. + DBUS_SOCKET=$(echo "$DBUS_SESSION_BUS_ADDRESS" | sed 's|unix:path=||') + WAIT=0 + while [ ! -S "$DBUS_SOCKET" ] && [ "$WAIT" -lt 30 ]; do + sleep 1 + ((WAIT++)) done - qdbus6 $dbus_ref close 2>/dev/null - notify-send --app-name 'AstroArch' --icon="/home/astronaut/.astroarch/assets/icons/novnc-icon.svg" -t 10000 "✅ Backup completed." + + if [ ! -S "$DBUS_SOCKET" ]; then + # Fallback: D-Bus still not available after 30s → run in terminal mode + echo "⚠️ D-Bus session bus not available after 30s. Falling back to terminal mode." + sudo -n rsync -aAXHxh --delete --no-inc-recursive --info=progress2 "${EXCLUSIONS[@]}" / "$ABS_DEST" + else + dbus_ref=$(kdialog --progressbar "Initializing backup..." 100) + sudo -n rsync -aAXHxh --delete --no-inc-recursive --info=progress2 "${EXCLUSIONS[@]}" / "$ABS_DEST" 2>/dev/null | \ + stdbuf -oL tr '\r' '\n' | grep --line-buffered -oP '[0-9]+(?=%)' | \ + while read -r percent; do + ((count++)) + if (( count % 5 == 0 )); then + # IF CANCELED BY THE USER + if ! qdbus6 $dbus_ref >/dev/null 2>&1; then + sudo pkill -f "rsync.*$ABS_DEST" + cleanup_canceled_backup "$ABS_DEST" + fi + qdbus6 $dbus_ref setLabelText "Copying: $percent% of $TRANS_HUMAN" + qdbus6 $dbus_ref Set "" value "$percent" + fi + done + qdbus6 $dbus_ref close 2>/dev/null + notify-send --app-name 'AstroArch' --icon="/home/astronaut/.astroarch/assets/icons/novnc-icon.svg" -t 10000 "✅ Backup completed." + fi else sudo -n rsync -aAXHxh --delete --no-inc-recursive --info=progress2 "${EXCLUSIONS[@]}" / "$ABS_DEST" fi