-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuf-first-setup.sh
143 lines (135 loc) · 4.27 KB
/
uf-first-setup.sh
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
# Written by Mikhail P. Ortiz-Lunyov
#
# Updated May 21st 2024
# This script is licensed under the GNU Public License Version 3 (GPLv3).
# More information about license in readme and bottom.
# Checks for root user
RootCheck() {
# Checks whoami
case `whoami` in
"root")
echo "Script run as root..."
;;
*)
# Alerts user to lack of root execution
printf "\e[1mMISSING ROOT!\e[0m\n"
# Gives user advices for intended use
echo "Update_Full is intended to be used by sysadmins and others authorized to update Linux and UNIX-based systems."
echo "As such, it is best for the script to have limited writing and executing permissions."
echo "This first setup script changes the script's permission."
printf "\nAs such, this script needs to be executed as root to improve the update_full's permissions.\n"
exit 1
;;
esac
}
# Sets default (root) settings
DefaultSettings() {
# Sets owner
OWNERNAME="root"
# Sets group
GROUPNAME="root"
chown $OWNERNAME:$GROUPNAME $SCRIPTNAME
chmod 744 $SCRIPTNAME
}
# Sets custom settings for chown
CustomChown() {
# Starts loop
Q_LOOP1=true
while [ "$Q_LOOP1" = true ] ; do
printf "File owner name: "
read OWNERNAME
printf "File group name: "
read GROUPNAME
chown $OWNERNAME:$GROUPNAME $SCRIPTNAME
if [ "$?" != "0" ] ; then
clear
echo "Something went wrong, try again!"
else
Q_LOOP1=false
fi
done
}
# Sets custom settings for Chmod
CustomChmod() {
# Starts loop
Q_LOOP2=true
while [ "$Q_LOOP2" = true ] ; do
printf "Owner rights code: "
read OWNERRIGHTS
printf "Group rights code: "
read GROUPRIGHTS
printf "Others rights code: "
read OTHERSRIGHTS
chmod $OWNERRIGHTS$GROUPRIGHTS$OTHERSRIGHTS $SCRIPTNAME
if [ "$?" != "0" ] ; then
clear
echo "Something went wrong, try again!"
else
Q_LOOP2=false
fi
done
}
# Main
clear
# Runs Root check function
RootCheck
SCRIPTNAME="update_full-unix.sh"
# Start default check loop
DEFAULT_Q_LOOP=true
while [ "$DEFAULT_Q_LOOP" = true ] ; do
echo "Do you want to use defaults ($SCRIPTNAME is owned by root, $SCRIPTNAME can only be read, writen, and executed by user (root), and read by everyone else)?"
echo "!!!RECOMMENDED!!!"
printf "[Y]es/[N]o < "
read DEFAULT_Q
case $DEFAULT_Q in
"Y"|"y"|"Yes"|"yes")
DefaultSettings
DEFAULT_Q_LOOP=false
;;
"N"|"n"|"No"|"no")
Q_LOOP0=true
while [ "$Q_LOOP0" = true ] ; do
echo "What do you want to change?"
printf "\t[1] chown (change file owner and group)\n"
printf "\t[2] chmod (change file mode bits)\n"
printf "\t[3] Both\n"
printf "\t[4] Use defaults instead\n"
printf " < "
read Q_0
case $Q_0 in
"1")
CustomChown
;;
"2")
CustomChmod
Q_LOOP0=false
;;
"3")
CustomChown
CustomChmod
Q_LOOP0=false
;;
"4")
DefaultSettings
Q_LOOP0=false
;;
esac
done
;;
*)
clear
echo "Invalid response, try again."
;;
esac
done
# Notifies user to changed permissions
printf "\n\e[1mPermissions changed for $SCRIPTNAME!\e[0m\n"
# Describes changes
echo "$SCRIPTNAME's owner is now '$OWNERNAME' in group '$GROUPNAME'."
printf "This first-setup script will now delf-destruct.\n\tIf you need different permissions and ownership, change it manually!\n"
rm -f $0
exit 0
# uf-first-setup.sh Copyright (C) 2024 Mikhail P. Ortiz-Lunyov
# This program comes with ABSOLUTELY NO WARRANTY.
# This is free software, and you are welcome to redistribute it
# under certain conditions.