Skip to content
Open
Changes from all 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
44 changes: 38 additions & 6 deletions configs/.zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function astro-rollback-kstars()
function update-astroarch()
{
# Store actual version
OLD_VER=$(cat /home/$USER/.astroarch.version)
OLD_VER=$(cat "/home/$USER/.astroarch/configs/.astroarch.version" | tr -d '[:space:]')

# Store the current commit hash before the pull
cd /home/$USER/.astroarch
Expand All @@ -89,18 +89,50 @@ function update-astroarch()
git pull origin main
cd - > /dev/null 2>&1

NEW_VER=$(cat /home/$USER/.astroarch/configs/.astroarch.version)
# Store new version
NEW_VER=$(cat "/home/$USER/.astroarch/configs/.astroarch.version" | tr -d '[:space:]')

if [[ "$OLD_VER" != "$NEW_VER" ]]; then
zsh /home/$USER/.astroarch/scripts/$NEW_VER.sh
if [[ $? -ne 0 ]]; then
# Function convert to integer for comparison
function ver_to_int() {
local parts=(${(s:.:)1})
echo $(( ${parts[1]:-0} * 10000 + ${parts[2]:-0} * 100 + ${parts[3]:-0} ))
}

old_int=$(ver_to_int "$OLD_VER")
new_int=$(ver_to_int "$NEW_VER")

if [[ $old_int -lt $new_int ]]; then
local scripts_to_run=($(ls "/home/$USER/.astroarch/scripts/"*.sh | sort -V))
success=true

for script_path in "${scripts_to_run[@]}"; do
local script_name="${${script_path:t}:r}"

if [[ "$script_name" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
local script_int=$(ver_to_int "$script_name")

if (( script_int > old_int && script_int <= new_int )); then

# Apply scripts less than or equal to new astroarch.version
zsh "$script_path"

if [[ $? -ne 0 ]]; then
success=false
break
fi
fi
fi
done

if [[ "$success" = false ]]; then
# Revert to the commit stored before the pull
cd /home/$USER/.astroarch
git reset --hard "$CURRENT_COMMIT"
cd - > /dev/null 2>&1
notify-send --app-name 'AstroArch' --icon="/home/astronaut/.astroarch/assets/icons/novnc-icon.svg" -t 10000 'Update AstroArch' "Script '$SCRIPT_VER' failed. Reverted to previous state."
else
notify-send --app-name 'AstroArch' --icon="/home/astronaut/.astroarch/assets/icons/novnc-icon.svg" -t 10000 'Update AstroArch' 'All scripts applied successfully'
fi
notify-send --app-name 'AstroArch' --icon="/home/astronaut/.astroarch/assets/icons/novnc-icon.svg" -t 10000 'Update AstroArch' 'All scripts applied successfully'
fi;

# Temporary fix for kde-portal duplicated conf
Expand Down