-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateGlobalScripts
More file actions
executable file
·64 lines (49 loc) · 1.27 KB
/
updateGlobalScripts
File metadata and controls
executable file
·64 lines (49 loc) · 1.27 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
#!/usr/bin/env bash
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
if [ $EUID = 0 ]; then
printf "\n"
else
echo -e "\n${RED}Root permission will be required to make script global!${NC}"
exit 1
fi
if [[ $1 == '' ]]; then
CUR_DIR=$(pwd)
else
CUR_DIR=$1
fi
SCRIPTS=()
for file in "$CUR_DIR"/*; do
FILE_NAME=$(basename "$file")
if [ -f "/usr/bin/$FILE_NAME" ] && [ "$(cmp "/usr/bin/$FILE_NAME" "$file")" ]; then
#echo "/usr/bin/$FILE_NAME" exists and is different
SCRIPTS+=("$file")
fi
done
printf "${GREEN}"
for script in "${SCRIPTS[@]}"; do
FILE_NAME=$(basename "$script")
echo "$FILE_NAME"
done
echo -e "${BLUE}"
read -n 1 -rp "These scripts were found in /usr/bin, 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 scripts...${NC}"
for defScript in "${SCRIPTS[@]}"; do
FILE_NAME=$(basename "$defScript")
cp "$defScript" /usr/bin/"$FILE_NAME"
chown "$SUDO_USER":"$SUDO_USER" /usr/bin/"$FILE_NAME"
chmod +x /usr/bin/"$FILE_NAME"
done
echo -e "\n${GREEN}Updating finished${NC}"