aboutsummaryrefslogtreecommitdiff
path: root/mod/lorea-status/install.sh
blob: c4a50c17e2e090d587d05f4857634f74f84b7069 (plain)
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
#!/bin/sh
#
# Install status.lorea.org website and activate it
#

INSTALL_DIR=/usr/local
DOMAIN=status.lorea.org

# Sanity check
if [ ! -d ./bin -o ! -f ./bin/lorea_refresh_status ] ; then
	echo "This script must run from the source tree."
	exit 1
fi
if [ $(id -un) != 'root' ] ; then
	echo "This script must be run by root."
	exit 1
fi
if [ ! -x /bin/zsh ] ; then
	echo "*warning* Package zsh is not installed."
	echo -n "Do you want to install it now? [yN] "
	read -s
	case $REPLY in
		[Yy]*)
			apt-get install zsh
			;;
		*)
			echo "OK, don't forget to install it!"
			;;
	esac
fi
if [ ! -x /usr/sbin/nginx ] ; then
	echo "*warning* Package nginx is not installed."
	echo -n "Do you want to install it now? [yN] "
	read -s
	case $REPLY in
		[Yy]*)
			apt-get install nginx
			;;
		*)
			echo "OK, don't forget to install it!"
			;;
	esac
fi

# Install script
install -m 0755 ./bin/lorea_refresh_status $INSTALL_DIR/bin
install -m 0755 ./etc/lorea-status /etc/default

# Install web
mkdir -p /var/www/$DOMAIN/pub
chown www-data:www-data /var/www/$DOMAIN/pub
for file in index.html status.css status.js jquery.js ; do
	install -C -D -m 0644 -t /var/www/$DOMAIN ./www/$file
done

# Configure Nginx
install -C -D -m 0644 ./etc/status.lorea.org /etc/nginx/sites-available
ln -sf /etc/nginx/sites-available/status.lorea.org /etc/nginx/sites-enabled

# Install crontab
install -m 0644 ./etc/crontab /etc/cron.d/lorea_refresh_status

# Bootstrap JSON data
su - www-data -c "$INSTALL_DIR/bin/lorea_refresh_status"

# Wrap up
if [ -x /usr/sbin/nginx ] ; then
	nginx_status=$(/etc/init.d/nginx status)
	if [ "$nginx_status" = "nginx is running." ] ; then
		/etc/init.d/nginx reload
	else
		echo "Nginx not running: not reloaded."
	fi
fi