-
Notifications
You must be signed in to change notification settings - Fork 53
/
update.sh
196 lines (183 loc) · 5.14 KB
/
update.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/sh
# update script for nosh2
set -e
# Constants and paths
LOGDIR=/var/log/nosh2
LOG=$LOGDIR/nosh2_installation_log
NOSHCRON=/etc/cron.d/nosh-cs
MYSQL_DATABASE=nosh
NOSH_DIR=/noshdocuments
OLDNOSH=$NOSH_DIR/nosh-cs
NEWNOSH=$NOSH_DIR/nosh2
ENV=$NEWNOSH/.env
log_only () {
echo "$1"
echo "`date`: $1" >> $LOG
}
unable_exit () {
echo "$1"
echo "`date`: $1" >> $LOG
echo "EXITING.........."
echo "`date`: EXITING.........." >> $LOG
exit 1
}
get_settings () {
echo `grep -i "^[[:space:]]*$1[[:space:]=]" $2 | cut -d \= -f 2 | cut -d \; -f 1 | sed "s/[ '\"]//gi"`
}
insert_settings () {
sed -i 's%^[ ]*'"$1"'[ =].*$%'"$1"' = '"$2"'%' "$3"
}
# Check if running as root user
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Aborting." 1>&2
exit 1
fi
# Check if previous installation
if [ ! -d $OLDNOSH ]; then
echo "No previous installation of NOSH found. Aborting." 1>&2
exit 1
fi
# Create log file if it doesn't exist
if [ ! -d $LOGDIR ]; then
mkdir -p $LOGDIR
fi
# Check os and distro
if [[ "$OSTYPE" == "linux-gnu" ]]; then
if [ -f /etc/debian_version ]; then
# Ubuntu or Debian
WEB_GROUP=www-data
WEB_USER=www-data
if [ -d /etc/apache2/conf-enabled ]; then
WEB_CONF=/etc/apache2/conf-enabled
else
WEB_CONF=/etc/apache2/conf.d
fi
APACHE="/etc/init.d/apache2 restart"
SSH="/etc/init.d/ssh stop"
SSH1="/etc/init.d/ssh start"
elif [ -f /etc/redhat-release ]; then
# CentOS or RHEL
WEB_GROUP=apache
WEB_USER=apache
WEB_CONF=/etc/httpd/conf.d
APACHE="/etc/init.d/httpd restart"
SSH="/etc/init.d/sshd stop"
SSH1="/etc/init.d/sshd start"
elif [ -f /etc/arch-release ]; then
# ARCH
WEB_GROUP=http
WEB_USER=http
WEB_CONF=/etc/httpd/conf/extra
APACHE="systemctl restart httpd.service"
SSH="systemctl stop sshd"
SSH1="systemctl start sshd"
elif [ -f /etc/gentoo-release ]; then
# Gentoo
WEB_GROUP=apache
WEB_USER=apache
WEB_CONF=/etc/apache2/modules.d
APACHE=/etc/init.d/apache2
SSH="/etc/init.d/sshd stop"
SSH1="/etc/init.d/sshd start"
elif [ -f /etc/fedora-release ]; then
# Fedora
WEB_GROUP=apache
WEB_USER=apache
WEB_CONF=/etc/httpd/conf.d
APACHE="/etc/init.d/httpd restart"
SSH="/etc/init.d/sshd stop"
SSH1="/etc/init.d/sshd start"
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac
WEB_GROUP=_www
WEB_USER=_www
WEB_CONF=/etc/httpd/conf.d
APACHE="/usr/sbin/apachectl restart"
SSH="launchctl unload com.openssh.sshd"
SSH1="launchctl load com.openssh.sshd"
elif [[ "$OSTYPE" == "cygwin" ]]; then
echo "This operating system is not supported by this install script at this time. Aborting." 1>&2
exit 1
elif [[ "$OSTYPE" == "win32" ]]; then
echo "This operating system is not supported by this install script at this time. Aborting." 1>&2
exit 1
elif [[ "$OSTYPE" == "freebsd"* ]]; then
WEB_GROUP=www
WEB_USER=www
WEB_CONF=/etc/httpd/conf.d
if [ -e /usr/local/etc/rc.d/apache22.sh ]; then
APACHE="/usr/local/etc/rc.d/apache22.sh restart"
else
APACHE="/usr/local/etc/rc.d/apache24.sh restart"
fi
SSH="/etc/rc.d/sshd stop"
SSH1="/etc/rc.d/sshd start"
else
echo "This operating system is not supported by this install script at this time. Aborting." 1>&2
exit 1
fi
# Check apache version
APACHE_VER=$(apache2 -v | awk -F"[..]" 'NR<2{print $2}')
# Update
cd $NOSH_DIR
composer create-project nosh2/nosh2 --prefer-dist --stability dev
cd $NEWNOSH
chown -R $WEB_GROUP.$WEB_USER $NEWNOSH
chmod -R 755 $NEWNOSH
chmod -R 777 $NEWNOSH/storage
chmod -R 777 $NEWNOSH/public
chmod 777 $NEWNOSH/noshfax
chmod 777 $NEWNOSH/noshreminder
chmod 777 $NEWNOSH/noshbackup
cp $OLDNOSH/.google $NEWNOSH/.google
log_only "Updated NOSH ChartingSystem core files."
a2enmod ssl
if [ -e "$WEB_CONF"/nosh.conf ]; then
sed -i "s_Alias /nosh /noshdocuments/nosh-cs/public_Alias /nosh-old /noshdocuments/nosh-cs/public_" "$WEB_CONF"/nosh.conf
fi
if [ -e "$WEB_CONF"/nosh2.conf ]; then
rm "$WEB_CONF"/nosh2.conf
fi
touch "$WEB_CONF"/nosh2.conf
APACHE_CONF="Alias /nosh $NEWNOSH/public
<Directory $NEWNOSH/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride None"
if [ "$APACHE_VER" = "4" ]; then
APACHE_CONF="$APACHE_CONF
Require all granted"
else
APACHE_CONF="$APACHE_CONF
Order allow,deny
allow from all"
fi
APACHE_CONF="$APACHE_CONF
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /\$1 [L,R=301]
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
<IfModule mod_php5.c>
php_value upload_max_filesize 512M
php_value post_max_size 512M
php_flag magic_quotes_gpc off
php_flag register_long_arrays off
</IfModule>
</Directory>"
echo "$APACHE_CONF" >> "$WEB_CONF"/nosh2.conf
log_only "NOSH ChartingSystem Apache configuration file set."
log_only "Restarting Apache service."
$APACHE >> $LOG 2>&1
# Installation completed
log_only "You can now use NOSH ChartingSystem by browsing to:"
log_only "https://localhost/nosh"
log_only "The old version of NOSH ChartingSystem can still be used by browsing to:"
log_only "https://localhost/nosh-old"
exit 0