-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·79 lines (71 loc) · 2.21 KB
/
install.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
#!/bin/bash
NETBASICS_PATH="/Library/Scripts/NetBasics"
LAUNCHDAEMONS_PATH="/Library/LaunchDaemons"
PS3='[Please enter your choice]: '
options=(
"install (i): install mode" # 1
"uninstall (ui): uninstall mode" # 2
"update (up): update mode" # 3
"quit: Exit from this menu" # 4
)
function _sudo() {
SUDO=''
if [[ $(id -u) -ne 0 ]]; then
SUDO='sudo'
fi
}
function _mkdir() {
if [! -d $NETBASICS_PATH ]; then
$SUDO mkdir -p $NETBASICS_PATH;
fi
if [! -d $LAUNCHDAEMONS_PATH ]; then
$SUDO mkdir -p $LAUNCHDAEMONS_PATH;
fi
}
function _switch() {
_reply="$1"
case $_reply in
""|"i"|"install"|"1")
_sudo
_mkdir
$SUDO cp wireless.sh $NETBASICS_PATH;
$SUDO cp com.computernetworkbasics.wifionoff.plist $LAUNCHDAEMONS_PATH/com.computernetworkbasics.wifionoff.plist;
$SUDO chmod 755 $NETBASICS_PATH/wireless.sh;
$SUDO chown root:wheel $LAUNCHDAEMONS_PATH/com.computernetworkbasics.wifionoff.plist;
;;
""|"ui"|"uninstall"|"2")
_sudo
$SUDO rm -Rf $NETBASICS_PATH/wireless.sh;
$SUDO rm -Rf $LAUNCHDAEMONS_PATH/com.computernetworkbasics.wifionoff.plist;
;;
""|"up"|"update"|"3")
_sudo
$SUDO cp wireless.sh $NETBASICS_PATH;
$SUDO cp com.computernetworkbasics.wifionoff.plist $LAUNCHDAEMONS_PATH/com.computernetworkbasics.wifionoff.plist;
$SUDO chmod 755 $NETBASICS_PATH/wireless.sh;
$SUDO chown root:wheel $LAUNCHDAEMONS_PATH/com.computernetworkbasics.wifionoff.plist;
exit
;;
""|"quit"|"4")
echo "Goodbye!"
exit
;;
""|"--help")
echo "Available commands:"
printf '%s\n' "${options[@]}"
;;
*) echo "invalid option, use --help option for the commands list";;
esac
}
while true
do
# run option directly if specified in argument
[ ! -z $1 ] && _switch $@
[ ! -z $1 ] && exit 0
echo "==== OPTIONS ===="
select opt in "${options[@]}"
do
_switch $REPLY
break
done
done