-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateConfigs
More file actions
executable file
·167 lines (137 loc) · 3.47 KB
/
updateConfigs
File metadata and controls
executable file
·167 lines (137 loc) · 3.47 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env bash
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"
)
if [[ $1 == '' ]]; then
CUR_DIR=$(pwd)
else
CUR_DIR=$1
fi
CFGS=()
DIR_LIST=()
verifyCfgDir() {
for configDir in "${CONFIGS[@]}"; do
if [ "$1" == "$(basename "$(dirname "$configDir")")" ] || [ "$1" == "user" ]; then
#basename "$(dirname "$configDir")"
return
else
continue
fi
done
false
}
verifyCfg() {
for configDir in "${CONFIGS[@]}"; do
if [ "$1" == "$(basename "$configDir")" ]; then
echo "$configDir"
return
elif [ ".$1" == "$(basename "$configDir")" ]; then
echo "$configDir"
return
else
continue
fi
done
false
}
if ! [[ -d $CUR_DIR ]]; then
echo -e "${RED}\nNot a valid directory!${NC}"
exit 1
fi
for dir in "$CUR_DIR"/*; do
if [ -d "$dir" ]; then
DIR_LIST+=("$dir")
fi
done
if [ ${#DIR_LIST[@]} -eq 0 ]; then
echo -e "${RED}\nNo valid directories found!${NC}"
exit 1
elif [ ${#DIR_LIST[@]} -eq 1 ]; then
BASE_DIR=${DIR_LIST[0]}
else
printf "\n${BLUE}Select the hostname folder from which you wish to update the configs from:${NC}\n"
select dir in "${DIR_LIST[@]}" "Current Folder" "Quit"; do
if [ "$dir" == "Quit" ]; then
echo -e "\n${RED}Quitting...${NC}"
exit 1
elif [ "$dir" == "Current Folder" ]; then
BASE_DIR=$CUR_DIR
break
elif [ -d "$dir" ]; then
BASE_DIR="$dir"
break
fi
done
fi
for dir in "$BASE_DIR"/*; do
if ! [[ -d $dir ]]; then
continue
fi
verifyCfgDir "$(basename "$dir")"
cfgDirCheck=$?
if ! [ $cfgDirCheck -eq 0 ]; then
continue
fi
for file in "$dir"/*; do
#basename "$file"
verifyCfgFile=$(verifyCfg "$(basename "$file")")
#echo "$verifyCfgFile"
if [ "$verifyCfgFile" == '' ]; then
continue
fi
CFGS+=("$verifyCfgFile")
done
done
if [ ${#CFGS[@]} -eq 0 ]; then
echo -e "\n${RED}No configs were found. Quitting...${NC}"
exit 1
fi
printf "\n${GREEN}"
for cfg in "${CFGS[@]}"; do
CFG_FOUND=/$(basename "$(dirname "$cfg")")/$(basename "$cfg")
echo "$CFG_FOUND"
done
echo -e "${BLUE}"
read -n 1 -rp "These configs were found in $BASE_DIR, update? [Y/n] " prompt
# Convert input to lowercase
prompt=${prompt,,}
#Add extra \n if not empty due to "enter" inserting a newline
if [[ -n "$prompt" ]]; then
printf "\n"
fi
if ! [ "$prompt" == y ] && [ -n "$prompt" ]; then
echo -e "\n${RED}Quitting...${NC}"
exit 1
fi
echo -e "\n${BLUE}Updating configs...${NC}"
for cfg in "${CFGS[@]}"; do
CUR_PATH="$CUR_DIR/$(basename "$(dirname "$cfg")")/$(basename "$cfg")"
CFG_NAME=$(basename "$cfg")
if [[ "$CFG_NAME" == .* ]]; then
CFG_NAME="${CFG_NAME#?}"
fi
if [ "$(dirname "$cfg")" == "$USER_HOME" ]; then
CUR_PATH="$CUR_DIR/user/$CFG_NAME"
fi
cp "$CUR_PATH" "$cfg"
done
echo -e "\n${GREEN}Updating finished${NC}"