-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobalizeScripts
More file actions
executable file
·82 lines (62 loc) · 1.65 KB
/
globalizeScripts
File metadata and controls
executable file
·82 lines (62 loc) · 1.65 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
#!/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 [[ $FILE_NAME == *.txt ]] || [[ $FILE_NAME == *.service ]] || [[ $FILE_NAME == *.timer ]] || [[ $FILE_NAME == *.md ]]; then
continue
fi
read -n 1 -rp "Make $FILE_NAME global? [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 ] || [ -z "$prompt" ]; then
SCRIPTS+=("$file")
fi
done
if [ ${#SCRIPTS[@]} -eq 0 ]; then
echo -e "\n${RED}No scripts were selected. Quitting${NC}"
exit 1
fi
printf "\n${GREEN}"
for script in "${SCRIPTS[@]}"; do
FILE_NAME=$(basename "$script")
echo "$FILE_NAME"
done
echo -e "${BLUE}"
read -n 1 -rp "Confirm scripts selection to make global? [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}Copying scripts to /usr/bin/${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}Copying finished${NC}"