-
-
Notifications
You must be signed in to change notification settings - Fork 116
/
setup.sh
executable file
·134 lines (118 loc) · 4.47 KB
/
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
#!/bin/bash
# Script Name: AtoMiC ToolKit
# Set caller id and script path
CALLER=$(ps -o args= $PPID | awk '{print $NF}')
export CALLER
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SCRIPTPATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
export SCRIPTPATH
export ISSETUP="Yes"
source "$SCRIPTPATH/inc/commons.sh"
source "$SCRIPTPATH/inc/app-constant-reset.sh"
# Check if being run as root
if [[ $EUID -ne 0 ]] ; then
echo
echo -e "${RED}Please run as root using the command: ${ENDCOLOR}sudo bash setup.sh"
echo
exit 0
fi
source "$SCRIPTPATH/inc/header.sh"
# Define help function for options
help(){
echo
echo -e "${YELLOW}--->COMMAND LINE OPTIONS:$ENDCOLOR"
echo
echo "Usage example:";
echo "atomic-toolkit [(-i|--install) appname] [(-u|--uninstall) appname] [(-b|--backup) appname] [(-r|--restore) appname] [(-m|--manualupdate) appname] [(-p|--passwordreset) appname] [(-a|--accessdetails) appname] [(-x|--reverseproxy)] [(-t|--updatetoolkit)] [(-U|--updateall)]";
echo "Options:";
echo
echo "-i or --install appname: Install an app.";
echo "-u or --uninstall appname: Uninstall an app.";
echo "-b or --backup appname: Backup an the config file for an app.";
echo "-r or --restore appname: Restore an app config file from backup.";
echo "-m or --manualupdate appname: Manually update a specific app.";
echo "-p or --passwordreset appname: Reset the password to an app.";
echo "-a or --accessdetails appname: View the access details for an app.";
echo "-x or --reverseproxy appname: Enable Reverse Proxy for an app.";
echo "-t or --updatetoolkit: Update AtoMiC-ToolKit.";
echo "-U or --updateall: Update Linux and all apps.";
exit 1;
}
# Reset option vars
updatetoolkit=0;
updateall=0;
# Capture options to getopts
ARGS=$(getopt -o "i:u:b:r:m:p:a:x:tUh" -l "install:,uninstall:,backup:,restore:,manualupdate:,passwordreset:,accessdetails:,reverseproxy:,updatetoolkit,updateall,help" -n "AtoMiC-ToolKit" -- "$@");
export ARGS
#sleep 1
#echo $1
if [[ ! -d $SCRIPTPATH/tmp ]]; then
mkdir "$SCRIPTPATH/tmp"
fi
if [[ ! -d $SCRIPTPATH/backups ]]; then
mkdir "$SCRIPTPATH/backups"
fi
if [[ -z $CI ]]; then
echo -e "${YELLOW}--->DISCLAIMERS:$ENDCOLOR"
if [[ ! -f $SCRIPTPATH/tmp/consented ]]; then
#echo 'consent file not present'
source "$SCRIPTPATH/inc/consent.sh"
source "$SCRIPTPATH/inc/app-toolkit-deps.sh"
else
echo -e 'Already agreed. Can be cleared in the next screen.'
fi
fi
echo
#sleep 1
if [[ -z $CI ]]; then
echo -e "${YELLOW}--->USER INFORMATION:$ENDCOLOR"
if [[ ! -f $SCRIPTPATH/tmp/userinfo ]]; then
#echo 'userinfo not present'
source "$SCRIPTPATH/inc/usercheck.sh"
else
#echo 'userinfo present'
source "$SCRIPTPATH/tmp/userinfo"
if [[ -z $UNAME ]] || [[ -z $UGROUP ]]; then
#echo 'userinfo not complete'
source "$SCRIPTPATH/inc/usercheck.sh"
else
echo -e "Already present: $CYAN$UNAME$ENDCOLOR." \
"Can be cleared in the next screen."
echo
source "$SCRIPTPATH/inc/option-handler.sh"
fi
fi
else
source "$SCRIPTPATH/tmp/userinfo"
source "$SCRIPTPATH/inc/option-handler.sh"
fi
# Set permissions for all files
sudo chown -R $UNAME:$UGROUP $SCRIPTPATH >/dev/null 2>&1
sudo chmod -R 775 $SCRIPTPATH >/dev/null 2>&1
sudo chmod -R g+s $SCRIPTPATH >/dev/null 2>&1
if [[ ! -d '/opt' ]]; then
mkdir /opt
sudo chown -R $UNAME:$UGROUP /opt >/dev/null 2>&1
sudo chmod -R 775 /opt >/dev/null 2>&1
sudo chmod -R g+s /opt >/dev/null 2>&1
echo -e 'opt dir created.'
fi
#Creating a sym link to the user bin so the toolkit can be accessed by typing atk.
if [[ ! -L "/usr/local/bin/atk" ]]; then
echo
echo -e "${YELLOW}--->Installing AtoMiC-ToolKit symbolic link...$ENDCOLOR"
sudo ln -s -T "$SCRIPTPATH/setup.sh" /usr/local/bin/atk
echo 'You can use the AtoMiC-ToolKit by typing the following command from anywhere:'
echo -e "${GREEN}sudo atk$ENDCOLOR"
echo
fi
if [[ -z $ARGS ]]; then
source "$SCRIPTPATH/inc/pause.sh"
source "$SCRIPTPATH/inc/header.sh"
source "$SCRIPTPATH/menus/menu-main.sh"
fi