-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·147 lines (141 loc) · 5.24 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
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
144
145
146
147
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
if [ -d "/opt/attendance-monitoring-system" ]; then
echo "Updating the repo..."
cd /opt/attendance-monitoring-system
git pull
else
echo "Cloning the repo to /opt..."
cd /opt
git clone https://github.com/Arkapravo-Ghosh/attendance-monitoring-system.git
git config pull.rebase false
fi
if [ -x "$(command -v apt)" ]; then
echo "Detected Debian Linux"
if [ ! -x "$(command -v curl)" ]; then
echo "Installing curl..."
apt install -y curl
fi
if [ ! -x "$(command -v mysql)" ]; then
echo -n "Do you want to install MariaDB? (Y/n): "
read install
if [ "$install" == "Y" ] || [ "$install" == "y" ] || [ "$install" == "" ]; then
curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | bash
apt update
apt install -y libmariadb-dev mariadb-server mariadb-client python3-dev python3-pip
fi
fi
elif [ -x "$(command -v pacman)" ]; then
echo "Detected that you use Arch btw"
if [ ! -x "$(command -v curl)" ]; then
echo "Installing curl..."
pacman -S --noconfirm curl
fi
if [ ! -x "$(command -v mysql)" ]; then
echo -n "Do you want to install MariaDB? (Y/n): "
read install
if [ "$install" == "Y" ] || [ "$install" == "y" ] || [ "$install" == "" ]; then
pacman -S --noconfirm mariadb python-pip
fi
fi
fi
echo -n "Do you want to install the required pip packages? (Y/n): "
read pipinstall
if [ "$pipinstall" == "Y" ] || [ "$pipinstall" == "y" ] || [ "$pipinstall" == "" ]; then
echo "Installing the required pip packages..."
pip3 install -r /opt/attendance-monitoring-system/requirements.txt
fi
echo -n "Do you want to auto setup MariaDB? (Y/n): "
read auto
if [ "$auto" == "Y" ] || [ "$auto" == "y" ] || [ "$auto" == "" ]; then
echo "Enabling and Starting MariaDB..."
systemctl enable --now mysql
echo "Changing the root password of MariaDB..."
mysql_secure_installation
echo "Creating the database..."
mysql -u root < /opt/attendance-monitoring-system/server/database.sql
echo "Creating the user..."
pass_var="Enter Password for SQL User: "
while IFS= read -p "$pass_var" -r -s -n 1 letter
do
if [[ $letter == $'\0' ]]
then
break
fi
password="$password$letter"
pass_var="*"
done
echo
mysql -u root -e "CREATE DATABASE attendance;"
mysql -u root -e "CREATE USER 'attendance'@'%' IDENTIFIED BY '$password';"
mysql -u root -e "GRANT ALL PRIVILEGES ON attendance.* TO 'attendance'@'%';"
mysql -u root -e "FLUSH PRIVILEGES;"
fi
echo -n "Do you want to generate the config file? (Y/n): "
read generate
if [ "$generate" == "Y" ] || [ "$generate" == "y" ] || [ "$generate" == "" ]; then
echo "Creating the config file..."
mkdir /etc/ams
if [ "$password" == "" ]; then
pass_var="Enter Password for SQL User: "
while IFS= read -p "$pass_var" -r -s -n 1 letter
do
if [[ $letter == $'\0' ]]
then
break
fi
password="$password$letter"
pass_var="*"
done
echo
fi
echo -n "$password" > /etc/ams/mysqlpasswd.txt
fi
echo "Creating ams user..."
useradd -m ams
echo "Adding the user to the dialout group..."
usermod -aG dialout ams
usermod -aG gpio ams
usermod -aG dialout $SUDO_USER
usermod -aG gpio $SUDO_USER
echo "Adding service files..."
cp /opt/attendance-monitoring-system/src/server/ams-attendance.service /etc/systemd/system/ams-attendance.service
systemctl daemon-reload
echo -n "Do you want to enable the ams service? (Y/n): "
read enableams
if [ "$enableams" == "Y" ] || [ "$enableams" == "y" ] || [ "$enableams" == "" ]; then
echo "Enabling the service..."
systemctl enable ams-attendance.service
fi
echo -n "Do you want to secure the config file? (Y/n): "
read secure
if [ "$secure" == "Y" ] || [ "$secure" == "y" ] || [ "$secure" == "" ]; then
echo "Securing the config file..."
echo "Adding current user to the ams group..."
usermod -aG ams $SUDO_USER
echo "Changes will take effect after a relogin."
echo "Setting the permissions..."
chown root:ams /etc/ams/mysqlpasswd.txt
chmod 640 /etc/ams/mysqlpasswd.txt
fi
echo "Adding the scripts to the PATH variable..."
if [ -f "/etc/profile" ]; then
if [ -z "$(grep "/opt/attendance-monitoring-system/src/server" /etc/profile)" ]; then
echo "export PATH=\$PATH:/opt/attendance-monitoring-system/src/server:/opt/attendance-monitoring-system/src/fingerprint:/opt/attendance-monitoring-system/src/frontend" >> /etc/profile
if [ -x "$(command -v zsh)" ]; then
if [ -z "$(grep "/opt/attendance-monitoring-system/src/server" /etc/zsh/zprofile)" ]; then
echo "export PATH=\$PATH:/opt/attendance-monitoring-system/src/server:/opt/attendance-monitoring-system/src/fingerprint:/opt/attendance-monitoring-system/src/frontend" >> /etc/zsh/zprofile
fi
fi
fi
fi
echo -n "Do you want to reboot now? (Y/n): "
read reboot
if [ "$reboot" == "Y" ] || [ "$reboot" == "y" ] || [ "$reboot" == "" ]; then
echo "Rebooting..."
reboot
fi
echo "Installed."