-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackupConfigs
More file actions
executable file
·77 lines (65 loc) · 2.17 KB
/
backupConfigs
File metadata and controls
executable file
·77 lines (65 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
# The intention is to make this into a cronjob or systemd timer to run periodically
# This script is a short-term solution
# This has been done in backupConfigs
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
if [ $EUID = 0 ]; then
USER_HOME=$(getent passwd "$SUDO_USER" | cut -d: -f6)
else
USER_HOME=$HOME
echo -e "\n${RED}Some configs may require root permission to backup!${NC}\n"
fi
CONFIGS=(
"$USER_HOME/.config/fastfetch/config.jsonc"
"$USER_HOME/.config/kitty/kitty.conf"
"/etc/locale.conf"
"/etc/dracut.conf.d/myflags.conf"
"$USER_HOME/.config/ohmyposh/myprofile.yaml"
"$USER_HOME/.zshrc"
"$USER_HOME/.config/ghostty/config"
"$USER_HOME/.zen/tizo6sbm.Default (release)/chrome/userChrome.css"
"$USER_HOME/.zen/tizo6sbm.Default (release)/chrome/userContent.css"
"$USER_HOME/.zen/tizo6sbm.Default (release)/chrome/natsumi-config.css"
"$USER_HOME/.config/wofi/config"
"$USER_HOME/.config/wofi/style.css"
"$USER_HOME/.config/yazi/init.lua"
"$USER_HOME/.config/yazi/keymap.toml"
"$USER_HOME/.config/yazi/theme.toml"
"$USER_HOME/.config/yazi/yazi.toml"
)
DEST_FOLDER="$USER_HOME/Dev/Linux/Config/$(hostname)"
echo -e "${BLUE}Creating $DEST_FOLDER if it doesn't exist"
mkdir -pv "$DEST_FOLDER"
chown "$SUDO_USER":"$SUDO_USER" "$DEST_FOLDER"
# Backing up configs
echo -e "\n${BLUE}Backing up configs to $DEST_FOLDER${RED}\n"
for config in "${CONFIGS[@]}"; do
if ! [[ -f $config ]]; then
continue
fi
FILE_NAME=$(basename "$config")
if [[ $(dirname "$config") == "$USER_HOME" ]]; then
FILE_DIR="user"
else
FILE_DIR=$(basename "$(dirname "$config")")
fi
# This check is to make dot files (hidden files) visible
if [[ $FILE_NAME == .* ]]; then
FILE_NAME="${FILE_NAME#?}"
# echo "$FILE_NAME"
fi
# This check is to make dot folders (hidden folders) visible
if [[ $FILE_DIR == .* ]]; then
FILE_DIR="${FILE_DIR#?}"
# echo "$FILE_NAME"
fi
printf "${NC}"
mkdir -pv "$DEST_FOLDER"/"$FILE_DIR"
chown "$SUDO_USER":"$SUDO_USER" "$DEST_FOLDER"/"$FILE_DIR"
printf "${RED}"
cp "$config" "$DEST_FOLDER"/"$FILE_DIR"/"$FILE_NAME"
done
echo -e "\n${GREEN}Finished backing up configs${NC}"