Skip to content

Commit

Permalink
Update/install scripts improvements (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
koeqaife authored Sep 21, 2024
2 parents 503a908 + f928a1d commit b6df686
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 41 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ git clone https://github.com/koeqaife/hyprland-material-you.git
mv hyprland-material-you dotfiles
cd dotfiles
./install.sh

```

### Change wallpaper to random wallpaper (after installation)

```sh
python ~/dotfiles/hypr/scripts/wallpaper.py -R
```

> I'm not sure if it will work, if you have any problems installing it, post in Issues
Expand Down
55 changes: 37 additions & 18 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ if [ ! -d "$HOME/dotfiles" ]; then
exit 1
fi

execute_command() {
while true; do
"$@"
exit_code=$?
if [ $exit_code -eq 0 ]; then
break
else
echo "Command failed with exit code $exit_code."
choice=$(gum choose "Continue the script" "Retry the command" "Exit the script")
case $choice in
"Continue the script") break ;;
"Retry the command") continue ;;
"Exit the script") exit 1 ;;
esac
fi
done
}

ask_continue() {
local message=$1
local exit_on_no=${2:-true}
Expand Down Expand Up @@ -41,8 +59,8 @@ preference_select() {
CHOICE=$(gum choose "${options[@]}" "NONE")

if [[ $CHOICE != "NONE" ]]; then
yay -Syu --noconfirm --needed
yay -S --noconfirm --needed $CHOICE
execute_command yay -Sy
execute_command yay -S --needed $CHOICE
python -O "$HOME"/dotfiles/ags/scripts/apps.py --"$app_type" $CHOICE
else
echo "Not installing a(n) $type..."
Expand All @@ -52,23 +70,23 @@ preference_select() {

install_yay() {
echo ":: Installing yay..."
sudo pacman -Syu --noconfirm
sudo pacman -S --needed --noconfirm base-devel git
git clone https://aur.archlinux.org/yay.git /tmp/yay
execute_command sudo pacman -Sy
execute_command sudo pacman -S --needed --noconfirm base-devel git
execute_command git clone https://aur.archlinux.org/yay.git /tmp/yay
cd /tmp/yay
makepkg -si --noconfirm --needed
execute_command makepkg -si --noconfirm --needed
}

install_microtex() {
cd ~/dotfiles/setup/MicroTex/
makepkg -si
execute_command makepkg -si
}

install_packages() {
echo ":: Installing packages"
sleep 1
yay -Syu --noconfirm --needed
yay -S --needed \
yay -Sy
execute_command yay -S --needed \
hyprland hyprshot hyprcursor hypridle hyprlang hyprpaper hyprpicker hyprlock \
hyprutils hyprwayland-scanner xdg-dbus-proxy xdg-desktop-portal \
xdg-desktop-portal-gtk xdg-desktop-portal-hyprland xdg-user-dirs \
Expand Down Expand Up @@ -99,7 +117,7 @@ setup_yay() {
}

setup_sensors() {
sudo sensors-detect --auto >/dev/null
execute_command sudo sensors-detect --auto >/dev/null
}

check_config_folders() {
Expand Down Expand Up @@ -172,7 +190,7 @@ install_icon_theme() {

setup_colors() {
echo ":: Setting colors"
python -O $HOME/dotfiles/material-colors/generate.py --color "#0000FF"
execute_command python -O $HOME/dotfiles/material-colors/generate.py --color "#0000FF"
}

setup_sddm() {
Expand All @@ -190,16 +208,16 @@ copy_files() {
echo ":: Copying files"
mkdir -p $HOME/.config
"$HOME"/dotfiles/setup/copy.sh
}

create_links() {
echo ":: Creating links"
ln -f $HOME/dotfiles/electron-flags.conf $HOME/.config/electron-flags.conf
if [ -d "$HOME/wallpaper" ]; then
echo ":: Error: directory wallpaper already exists in home"
else
cp -r $HOME/dotfiles/wallpapers $HOME/wallpaper
fi
}

create_links() {
echo ":: Creating links"
ln -f $HOME/dotfiles/electron-flags.conf $HOME/.config/electron-flags.conf
ln -s $HOME/dotfiles/ags $HOME/.config/ags
ln -s $HOME/dotfiles/alacritty $HOME/.config/alacritty
ln -s $HOME/dotfiles/hypr $HOME/.config/hypr
Expand Down Expand Up @@ -247,6 +265,7 @@ misc_tasks() {
echo ":: Misc"
hyprctl reload
ags --init
execute_command python $HOME/dotfiles/hypr/scripts/wallpaper.py -R
}

main() {
Expand All @@ -259,7 +278,7 @@ main() {
setup_yay
if ! command -v gum &>/dev/null; then
echo ":: gum not installed"
sudo pacman -S gum
execute_command sudo pacman -S gum
fi

ask_continue "Proceed with installing packages?" false && install_packages
Expand All @@ -270,10 +289,10 @@ main() {
ask_continue "Proceed with setting up sensors?" false && setup_sensors
ask_continue "Proceed with checking config folders?*" && check_config_folders
ask_continue "Proceed with installing icon themes?" false && install_icon_theme
ask_continue "Proceed with setting up colors?*" && setup_colors
ask_continue "Proceed with setting up SDDM?" false && setup_sddm
ask_continue "Proceed with copying files?*" && copy_files
ask_continue "Proceed with creating links?*" && create_links
ask_continue "Proceed with setting up colors?*" && setup_colors
ask_continue "Proceed with installing Vencord?" false && install_vencord
ask_continue "Proceed with removing GTK buttons?" false && remove_gtk_buttons
ask_continue "Proceed with setting up services?*" && setup_services
Expand Down
10 changes: 0 additions & 10 deletions scripts/check_updates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ if [ -z "$(ls -A "$OLD_SETTINGS")" ]; then
rmdir "$OLD_SETTINGS"
fi

git update-index --skip-worktree $HOME/dotfiles/.settings/*
git update-index --skip-worktree $HOME/dotfiles/hypr/conf/custom/*
git update-index --skip-worktree $HOME/dotfiles/hypr/conf/apps.conf
git update-index --skip-worktree $HOME/dotfiles/alacritty/alacritty.toml
git update-index --skip-worktree $HOME/dotfiles/wallpapers/*
git update-index --skip-worktree $HOME/dotfiles/hypr/hypridle.conf
git update-index --skip-worktree $HOME/dotfiles/electron-flags.conf
git update-index --skip-worktree $HOME/dotfiles/ags/README.md
git update-index --skip-worktree $HOME/dotfiles/ags/tsconfig.json

git fetch
UPSTREAM=${1:-'@{u}'}
LOCAL=$(git rev-parse @)
Expand Down
47 changes: 43 additions & 4 deletions setup/after_update.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#!/bin/bash

BACKUP_DIR="$HOME/dotfiles/.backup"

FILES_TO_RESTORE=(
"./hypr/conf/custom/*"
"./.settings/*"
"./hypr/conf/apps.conf"
"./wallpapers/*"
"./hypr/hypridle.conf"
"./electron-flags.conf"
"./ags/README.md"
"./ags/tsconfig.json"
)

ask_continue() {
local message=$1
local exit_on_no=${2:-false}
Expand All @@ -21,10 +34,36 @@ install_microtex() {
makepkg -si
}

cp -f $HOME/dotfiles/setup/wl-gammarelay.service $HOME/.config/systemd/user/
ask_continue "Import the old settings into the new settings?" && python "$HOME"/dotfiles/setup/import_settings.py
ask_continue "Proceed with installing/updating packages?" && "$HOME"/dotfiles/install.sh packages
ask_continue "Proceed with installing MicroTex?" && install_microtex
restore_files() {
for file_pattern in "${FILES_TO_RESTORE[@]}"; do
for file in $BACKUP_DIR/$file_pattern; do
if [ -e "$file" ]; then
original_path="${file/$BACKUP_DIR\//}"
cp "$file" "$original_path"
echo "Restored: $original_path"
fi
done
done
}

skip_worktree() {
for file_pattern in "${FILES_TO_RESTORE[@]}"; do
git update-index --skip-worktree $file_pattern 2>/dev/null || echo "Unable to mark: $file_pattern"
done
}

copy_files() {
"$HOME/dotfiles/setup/copy.sh"
}

git ls-files -v | grep '^S' | awk '{print $2}' | xargs git update-index --no-skip-worktree
restore_files
skip_worktree

cp -f "$HOME/dotfiles/setup/wl-gammarelay.service" "$HOME/.config/systemd/user/"
ask_continue "Import the old settings into the new settings?" && python "$HOME/dotfiles/setup/import_settings.py"
ask_continue "Proceed with installing/updating packages?" && "$HOME/dotfiles/install.sh packages"
ask_continue "Proceed with installing MicroTex?" && install_microtex
ask_continue "Proceed to copy files?" && copy_files

exit 0
32 changes: 30 additions & 2 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,36 @@ if [ "$1" == "--force" ]; then
fi

perform_update() {
echo ":: Performing git pull..."
git pull && "$HOME/dotfiles/setup/after_update.sh"
echo ":: Removing skip-worktree flags..."
git ls-files -v | grep '^S' | awk '{print $2}' | xargs git update-index --no-skip-worktree

BACKUP_DIR="$HOME/dotfiles/.backup"
TIMESTAMP=$(date +%F_%H-%M-%S)

if [ -d "$BACKUP_DIR" ]; then
NEW_BACKUP_DIR="${BACKUP_DIR}_old/${TIMESTAMP}"
mkdir -p "$NEW_BACKUP_DIR"
echo ":: Moving existing backup to $NEW_BACKUP_DIR..."
mv "$BACKUP_DIR" "$NEW_BACKUP_DIR"
fi

echo ":: Creating backup of modified files..."
mkdir -p "$BACKUP_DIR"

git diff --name-only | while read -r file; do
if [ -f "$file" ]; then
mkdir -p "$BACKUP_DIR/$(dirname "$file")"
cp "$file" "$BACKUP_DIR/$file"
fi
done

echo ":: Performing full repository update..."
git fetch origin
git reset --hard origin/$(git rev-parse --abbrev-ref HEAD)

echo ":: Running post-update script..."
"$HOME/dotfiles/setup/after_update.sh"

rm -f $NOTIFICATION_SENT_FILE
}

Expand Down

0 comments on commit b6df686

Please sign in to comment.