script(apply, update-repo): organize scripts into different files

This commit is contained in:
retrozinndev
2025-02-12 15:56:44 -03:00
parent 58b876c6e8
commit 0bbff3ab89
4 changed files with 194 additions and 163 deletions
+41 -83
View File
@@ -1,74 +1,31 @@
#!/usr/bin/bash #!/usr/bin/bash
source ./utils.sh
set -e set -e
trap "printf \"\nOk! Quitting beacuse you entered an exit signal.\n\"; exit 1" SIGINT trap "printf \"\nOk, quitting beacuse you entered an exit signal. (SIGINT).\n\"; exit 1" SIGINT
trap "printf \"\nOh noo!! Some application just told the script to end!\"; exit 2" SIGTERM
printf "\n"
echo "######################################"
echo "## Retrozinndev's Hyprland Dotfiles ##"
echo "######################################"
printf "\n"
CONFIG_DIR="$HOME/.config"
DOTFILES_DIRS=("hypr" "ags" "kitty" "anyrun" "wal" "fastfetch")
DOTFILES_BACKUP_DIR="$HOME/hyprland-dotfiles-bkp"
echo "Welcome to my dotfiles installation script!"
# Warn user of possible problems that can happen
echo "WARN! Running this script may cause problems with your system. When continuing, you're confirming that any problem that may happen with your system is of **your** responsability."
function Backup_previous_dotfiles { function Backup_previous_dotfiles {
echo -n "Would you like to make a backup of the current dotfiles? [y/n] " echo -n "Would you like to make a backup of the current dotfiles? [y/n] "
read make_backup_answer read answer
printf "\n" printf "\n"
if [[ $make_backup_answer =~ "y" ]] if [[ $answer =~ "y" ]]
then then
echo "[info] Creating backup dir in $DOTFILES_BACKUP_DIR" . ./backup-dots.sh
if [[ -d $DOTFILES_BACKUP_DIR ]]
then
echo "Looks like the backup directory already exists!"
echo -n "Would you like to override it with the current configuration? (Will be moved to trash) [y/n] "
read override_backup
if [[ $override_backup = "y" ]] || [[ $override_backup = "yes" ]]
then
echo "Ok! The backup folder will be ovewritten with the current user configuration."
trash-put $DOTFILES_BACKUP_DIR
fi
else
mkdir $DOTFILES_BACKUP_DIR
fi
# Make backup of existing configurations
for dir in ${DOTFILES_DIRS[@]}; do
if [[ -d "$CONFIG_DIR/$dir" ]]
then
echo "-> Making backup of $dir"
cp -r "$CONFIG_DIR/$dir" $DOTFILES_BACKUP_DIR
else
echo "[info] $dir backup was skipped, because it wasn't found."
fi
done
echo "Finished backup!!"
else else
echo "Fine! Current settings will be overwritten, skipping backup :D" echo "Ok! Directories will be overwritten, skipping backup :3"
fi fi
} }
function Apply_wallpapers { function Apply_wallpapers {
echo -n "Would you also like to apply the wallpapers folder? :3 [y/n] " echo -n "Would you also like to apply the wallpapers folder? :3 [y/n] "
read input_wallpaper read answer
printf "\n" printf "\n"
if [[ $input_wallpaper =~ "y" ]] if [[ $answer =~ "y" ]]; then
then echo "Thanks for choosing! Please remember that I am not the author of the wallpapers!"
echo "Thanks for installing these wallpapers! Oh, remember that I am not the author of them!"
echo "You can see sources in the repo: https://github.com/retrozinndev/Hyprland-Dots/WALLPAPERS.md" echo "You can see sources in the repo: https://github.com/retrozinndev/Hyprland-Dots/WALLPAPERS.md"
echo "-> Copying wallpapers to ~/wallpapers" echo "-> Copying wallpapers to ~/wallpapers"
@@ -80,48 +37,49 @@ function Apply_wallpapers {
fi fi
} }
function Apply_dotfiles { for dir in ${config_dirs[@]}; do
if ! [[ -d ./$dir ]]; then
Send_log error "$dir is in fault, or you didn't run this script in its directory!"
exit 1
fi
done
printf "\n"
# Start of actual script
Print_header
echo "Welcome to my dotfiles installation script!"
# Warn user of possible problems that can happen
echo "!!!WARNING!!! Running this may cause issues to your system if you don't know what you're doing! When continuing, you agree that any problem that may happen with the system is of your responsability!"
echo -n "Do you want to run the retrozinndev/Hyprland-Dots installer? [y/n] "
read input
if [[ $input =~ "y" ]]; then
printf "\n"
Backup_previous_dotfiles Backup_previous_dotfiles
printf "\n" printf "\n"
printf "Starting dotfiles installation...\n" Send_log "Starting installation\n"
for dir in ${DOTFILES_DIRS[@]}; do for dir in ${config_dirs[@]}; do
echo "-> Installing $dir in $CONFIG_DIR/$dir" dest=$XDG_CONFIG_HOME/$dir
mkdir -p $CONFIG_DIR/$dir
cp -rf ./$dir/* $CONFIG_DIR/$dir echo "-> Installing $dir in $dest"
mkdir -p $dest
cp -rf ./$dir/* $dest
done done
# Ask if user wants to apply repo's wallpapers dir # Ask if user wants to apply repo's wallpapers dir
Apply_wallpapers Apply_wallpapers
echo "Ah yes! Looks like it's ready to use, yay :3" echo "Ah yes! Looks like it's ready to use, yay :3"
echo "If you find any issue, please report at: https://github.com/retrozinndev/Hyprland-Dots/issues" echo -e "If you find any issue, please report it in:
echo "Thanks for using my dotfiles! I'm really happy about that :3" https://github.com/retrozinndev/Hyprland-Dots/issues"
echo "Thanks for using my Hyprland-Dots! I'm really happy about that :3"
printf "\n" printf "\n"
}
for dir in ${DOTFILES_DIRS[@]}; do
if ! [[ -d ./$dir ]]; then
echo "[error] Looks like $dir configuration is in fault, or you didn't run this script in its directory!"
echo "[tip] If directory doesn't exist, try cloning the dotfiles again."
exit 1
fi
done
echo -n "Do you want to install the dotfiles? [y/n] "
read input
if [[ $input =~ "y" ]]
then
Apply_dotfiles
else else
printf "Ok, doing as you said! Bye bye!\n" printf "Ok, doing as you said! Bye bye!\n"
exit 0 exit 0
fi fi
printf "\n"
+44
View File
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
# This script backups current configuration dirs
# listed in utils.sh script.
# --------
# Made by retrozinndev (João Dias)
# Licensed under the MIT License
# From: https://github.com/retrozinndev/Hyprland-Dots
source ./utils.sh
bkp_dir="$HOME/hyprland-dots-bkp"
Send_log "Creating backup in $bkp_dir"
if [[ -d $bkp_dir ]]
then
Send_log "Found existing backup in $bkp_dir!"
echo "Looks like the backup directory already exists!"
echo -n "Would you like to move it to trash/override it? [y/n] "
read answer
if [[ $answer =~ "y" ]]; then
echo "Fine! Previous backup is goning to be moved to trash"
trash-put $bkp_dir
else
echo "Ok! Quitting doing backup because it already exists"
exit 1
fi
fi
# Make backup of existing configurations
for dir in ${config_dirs[@]}; do
if [[ -d "$CONFIG_DIR/$dir" ]]
then
echo "-> backuping $dir"
cp -r "$CONFIG_DIR/$dir" $DOTFILES_BACKUP_DIR
else
echo "[info] $dir backup was skipped, because it wasn't found."
fi
done
echo "Finished backup!!"
+39 -78
View File
@@ -1,46 +1,11 @@
#!/usr/bin/bash #!/usr/bin/bash
HYPRLAND_DOTS_DIRS=("hypr" "ags" "anyrun" "kitty" "wal" "fastfetch") source ./utils.sh
WALLPAPERS_DIR="$HOME/wallpapers"
printf "\n"
echo "Running this script may override all data in current repo with current user dotfiles."
echo "This script is intended to be used by repository owner(retrozinndev)"
printf "\n"
echo "Please run this script in it's current directory to avoid problems."
echo "Tip: Press Ctrl + C to stop script at any time"
printf "\n"
Send_log() {
output_color=""
if [[ $1 =~ ^inf(o)$ ]]
then
output_color="\e[34m"
fi
if [[ $1 =~ ^warn(ing)$ ]]
then
output_color="\e[33m"
fi
if [[ $1 =~ ^err(or)$ ]]
then
output_color="\e[31m"
fi
echo -e "[${output_color}$1\e[0m] $2"
}
Check_current_dir() { Check_current_dir() {
if ! [[ -f ./update-repo.sh ]] if ! [[ -f ./utils.sh ]]; then
then Send_log warn "Looks like you're not in the repository directory!\nPlease run this script from the repo to avoid problems."
Send_log "warning" "Looks like you're not in the repo dir! Please run this script from the repo to avoid problems." Send_log "Exiting"
printf "Quitting...\n"
sleep .5 sleep .5
exit 1 exit 1
fi fi
@@ -48,8 +13,7 @@ Check_current_dir() {
Clean_local() { Clean_local() {
Send_log "info" "Cleaning current repo dotfiles..." Send_log "info" "Cleaning current repo dotfiles..."
# Modify dirs here when adding something new: for dir in ${config_dirs[@]}; do
for dir in ${HYPRLAND_DOTS_DIRS[@]}; do
if [[ -d "./$dir" ]]; then if [[ -d "./$dir" ]]; then
rm -rf ./$dir rm -rf ./$dir
fi fi
@@ -61,30 +25,22 @@ Clean_local() {
echo "Done cleaning." echo "Done cleaning."
} }
Check_existance() {
if [[ -d "./$1" ]]; then
return 0
fi
return 1
}
Update_local() { Update_local() {
for dotsDir in ${HYPRLAND_DOTS_DIRS[@]}; do for dir in ${config_dirs[@]}; do
if [[ -d "$HOME/.config/$dotsDir" ]]; then if [[ -d "$XDG_CONFIG_HOME/$dir" ]]; then
Send_log "info" "Trying to copy ${dotsDir^}..." Send_log "Copying ${dir^}"
cp -r $HOME/.config/$dotsDir ./$dotsDir cp -r $XDG_CONFIG_HOME/$dir ./$dir
else else
Send_log "warn" "Looks like the ~/.config/$dotsDir dir is in fault! Skipping it..." Send_log "warn" "Looks like the ~/.config/$dir dir is in fault! Skipping it..."
fi fi
done done
if [[ -d $WALLPAPERS_DIR ]]; then if [[ -d "$HOME/wallpapers" ]]; then
Send_log "info" "Copying wallpapers" Send_log "Copying wallpapers"
mkdir -p ./wallpapers mkdir -p ./wallpapers
cp -rf $WALLPAPERS_DIR/* ./wallpapers cp -rf $HOME/wallpapers/* ./wallpapers
else else
Send_log "warn" "Wallpapers dir could not be found in $HOME, skipping..." Send_log warn "Wallpapers dir could not be found in $HOME, skipping..."
fi fi
printf "\nDone updating local repo!\n" printf "\nDone updating local repo!\n"
@@ -92,7 +48,7 @@ Update_local() {
Update_remote() { Update_remote() {
echo "Git status:" echo "Git status:"
/usr/bin/env git status git status
echo "Please type one of the dotfiles you want to push now(only one dir):" echo "Please type one of the dotfiles you want to push now(only one dir):"
ls --color=auto -d -- */ ls --color=auto -d -- */
printf "Directory: " printf "Directory: "
@@ -127,35 +83,40 @@ Update_remote() {
Check_current_dir Check_current_dir
echo "Starting in 3... " Print_header
sleep 1s
echo "2..." printf "\n"
sleep 1s echo "!!WARNING!! Running this script may override all data in current repo with host configurations."
echo "1..." echo "This script is intended to be used only by retrozinndev/Hyprland-Dots repo owner"
sleep 1s printf "\n"
echo "Please run this script in it's current directory to avoid problems."
echo "Tip: Press Ctrl + C to stop script at any time"
printf "\n"
echo -n "Do you want to update local repository with host configurations? [y/n] "
read answer
if ! [[ $answer =~ y ]]; then
Send_log "Exiting"
exit 1
fi
printf "\n" printf "\n"
Clean_local Clean_local
# Updates local repository with current user dotfiles
Update_local Update_local
echo -n "Would you like to push selected changes to remote? (You will be prompted to select folders) [y/n] " echo -n "Would you like to commit to remote? (You will be prompted for each directory and commit messages) [y/n] "
read push_changes_to_remote read answer
if [[ $push_changes_to_remote =~ y ]] if [[ $answer =~ y ]]; then
then
Update_remote Update_remote
echo "Looks like it's done! Bye bye, have a great day!" echo "Looks like it's done! Have a great day!"
else else
echo "Ok, work has been finished here! Bye bye!" echo "Ok, work's finished here! Have a great day!"
fi fi
if [[ -f "/usr/bin/git" ]] env git status
then
printf "\nGit status: \n"
git status
fi
exit 0 exit 0
+68
View File
@@ -0,0 +1,68 @@
#!/usr/bin/env bash
# This script contains useful functions to be used
# in other scripts from retrozindev's dotfiles.
# ----------
# Made by retrozinndev (João Dias)
# Licensed under the MIT License
# From: https://github.com/retrozinndev/Hyprland-dots
# -------------
# Array containing directory names to be used by
# retrozinndev/Hyprland-Dots install and update
# scripts.
# -------------
config_dirs=(
"hypr"
"ags"
"kitty"
"anyrun"
"wal"
"fastfetch"
)
# -------------
# Sends stdout log with type and message provided
# in parameters.
# param $1 (optional) log type (err[or], warn[ing]), if not any of list, print as info
# param $2 log message
# -------------
function Send_log() {
log_message=$2
case ${1,,} in
"^warn(ing)$")
color="\e[33m"
log_type="warning"
;;
"^err(or)$")
color="\e[31m"
log_type="error"
;;
*)
color="\e[34m"
log_type="info"
;;
esac
if [[ -z $2 ]]; then
log_message=$1
fi
echo -e "${color}[$log_type]\e[0m $log_message"
}
# -------------
# Prints retrozinndev/Hyprland-Dots installation
# script's welcome header on stdout
# -------------
function Print_header() {
printf "\n"
echo "######################################"
echo "## Retrozinndev's Hyprland Dotfiles ##"
echo "######################################"
printf "\n"
}