irongit
hygoland/scripts/KooLsDotsUpdate.sh
73 lines2.5 KBBourne Again Shell (bash)
1#!/bin/bash
2# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ ##
3# simple bash script to check if update is available by comparing local version and github version
4
5# Local Paths
6local_dir="$HOME/.config/hypr"
7iDIR="$HOME/.config/swaync/images/"
8local_version=$(ls $local_dir/v* 2>/dev/null | sort -V | tail -n 1 | sed 's/.*v\(.*\)/\1/')
9KooL_Dots_DIR="$HOME/Hyprland-Dots"
10
11# exit if cannot find local version
12if [ -z "$local_version" ]; then
13 notify-send -i "$iDIR/error.png" "ERROR "!?!?!!"" "Unable to find KooL's dots version . exiting.... "
14 exit 1
15fi
16
17# GitHub URL - KooL's dots
18branch="main"
19github_url="https://github.com/JaKooLit/Hyprland-Dots/tree/$branch/config/hypr/"
20
21# Fetch the version from GitHub URL - KooL's dots
22github_version=$(curl -s $github_url | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+' | sort -V | tail -n 1 | sed 's/v//')
23
24# Cant find GitHub URL - KooL's dots version
25if [ -z "$github_version" ]; then
26 exit 1
27fi
28
29# Comparing local and github versions
30if [ "$(echo -e "$github_version\n$local_version" | sort -V | head -n 1)" = "$github_version" ]; then
31 notify-send -i "$iDIR/note.png" "KooL Hyprland:" "No update available"
32 exit 0
33else
34 # update available
35 notify_cmd_base="notify-send -t 10000 -A action1=Update -A action2=NO -h string:x-canonical-private-synchronous:shot-notify"
36 notify_cmd_shot="${notify_cmd_base} -i $iDIR/ja.png"
37
38 response=$($notify_cmd_shot "KooL Hyprland:" "Update available! Update now?")
39
40 case "$response" in
41 "action1")
42 if [ -d $KooL_Dots_DIR ]; then
43 if ! command -v kitty &> /dev/null; then
44 notify-send -i "$iDIR/error.png" "E-R-R-O-R" "Kitty terminal not found. Please install Kitty terminal."
45 exit 1
46 fi
47 kitty -e bash -c "
48 cd $KooL_Dots_DIR &&
49 git stash &&
50 git pull &&
51 ./copy.sh &&
52 notify-send -u critical -i "$iDIR/ja.png" 'Update Completed:' 'Kindly log out and relogin to take effect'
53 "
54
55 else
56 if ! command -v kitty &> /dev/null; then
57 notify-send -i "$iDIR/error.png" "E-R-R-O-R" "Kitty terminal not found. Please install Kitty terminal."
58 exit 1
59 fi
60 kitty -e bash -c "
61 git clone --depth=1 https://github.com/JaKooLit/Hyprland-Dots.git $KooL_Dots_DIR &&
62 cd $KooL_Dots_DIR &&
63 chmod +x copy.sh &&
64 ./copy.sh &&
65 notify-send -u critical -i "$iDIR/ja.png" 'Update Completed:' 'Kindly log out and relogin to take effect'
66 "
67 fi
68 ;;
69 "action2")
70 exit 0
71 ;;
72 esac
73fi