configure.sh 3.04 KB
Newer Older
Sebastien's avatar
Sebastien committed
1 2 3 4 5 6 7
#!/bin/bash

error=0;

echo -e "\e[1m\e[100m";


8
if [ -z ${FC_DIR+x} ]
Sebastien's avatar
Sebastien committed
9
then 
10
	echo -e "\n\e[31m[ERROR] - FC_DIR is unset\e[39m";
Sebastien's avatar
Sebastien committed
11 12
	error=1;
else
13
	if [ ! -d $FC_DIR/ ]
Sebastien's avatar
Sebastien committed
14
	then
15
		echo -e "\n\e[31m[ERROR] - FC_DIR >$FC_DIR< DOES NOT EXIST\e[39m";
Sebastien's avatar
Sebastien committed
16 17 18 19
		error=1;
	fi
fi

20
if [ -z ${FC_ADMIN+x} ]
Sebastien's avatar
Sebastien committed
21
then 
22
	echo -e "\n\e[31m[ERROR] - FC_ADMIN is unset : MUST BE SET TO Admin email address\e[39m";
Sebastien's avatar
Sebastien committed
23 24 25
	error=1;
fi

26
if [ ! -e $FC_DIR/data/cfg/ssmtp.conf ]
Sebastien's avatar
Sebastien committed
27
then
28
	if [ -z ${FC_SMTP+x} ]
Sebastien's avatar
Sebastien committed
29
	then
30
		echo -e "\n\e[31m[ERROR] - FC_SMTP is unset and SSMTP not configured: >$FC_DIR/data/cfg/ssmtp.conf< DOES NOT EXIST";
Sebastien's avatar
Sebastien committed
31
		echo -e "\e[33m>>>> [HELP] - Set FC_SMTP to your SMTP server address , FC_SMTP_SECURITY protocol (STARTLS or TLS) and FC_SMTP_LOGIN and FC_SMTP_PASSWD if authentication is required\e[39m";
Sebastien's avatar
Sebastien committed
32 33
		error=1;
	fi
Sebastien's avatar
Sebastien committed
34 35 36 37 38 39 40 41 42 43
	if [ ! -z ${FC_SMTP_SECURITY+x} ]
	then
		if [[ "$FC_SMTP_SECURITY" =~ ^(STARTTLS|TLS)$ ]]
		then
			echo "$FC_SMTP_SECURITY is in the list"
		else
			echo "\n\e[31m[ERROR] - FC_SMTP_SECURITY is not in the valid list : STARTTLS|TLS\e[39m";
			error=1
		fi
	fi
Sebastien's avatar
Sebastien committed
44 45
fi

46
if [ -z ${FC_PORT+x} ]
Sebastien's avatar
Sebastien committed
47
then 
48
	echo -e "\n\e[31m[ERROR] - FC_PORT is unset : MUST BE SET TO the port you want to access family-companion app\e[39m";
Sebastien's avatar
Sebastien committed
49 50 51
	error=1;
fi

52
if [ -z ${FC_HOSTNAME+x} ]
Sebastien's avatar
Sebastien committed
53
then
54 55
	echo -e "\e[33m>>>> [HELP] - FC_HOSTNAME not set - default setting is localhost\e[39m";
	FC_HOSTNAME='localhost';
Sebastien's avatar
Sebastien committed
56 57 58 59
fi

if [ $error -ne 1 ]
then
60
	if [ ! -d $FC_DIR/data ]
Sebastien's avatar
Sebastien committed
61
	then 
62 63
		mkdir $FC_DIR/data
		chown www-data.www-data  $FC_DIR/data
Sebastien's avatar
Sebastien committed
64
	fi
65
	if [ ! -d $FC_DIR/etc ]
Sebastien's avatar
Sebastien committed
66
	then 
67 68
		mkdir $FC_DIR/etc;
		chown www-data.www-data  $FC_DIR/etc
Sebastien's avatar
Sebastien committed
69
	fi
70
	if [ ! -d $FC_DIR/data/cfg ]
Sebastien's avatar
Sebastien committed
71
	then 
72
		mkdir $FC_DIR/data/cfg;
Sebastien's avatar
Sebastien committed
73
	fi
74

75 76
	echo -e "portal_web_server=http://$FC_HOSTNAME\n" > $FC_DIR/data/cfg/env.cfg;
	echo -e "portal_port=$FC_PORT\n" >>  $FC_DIR/data/cfg/env.cfg;
Sebastien's avatar
Sebastien committed
77
	
78
	if [ ! -e $FC_DIR/data/cfg/ssmtp.conf ]
Sebastien's avatar
Sebastien committed
79
	then
80
		cp site/cfg/ssmtp.conf.template $FC_DIR/data/cfg/ssmtp.conf
Sebastien's avatar
Sebastien committed
81 82 83 84 85 86 87
		echo -e "#LOCAL CONFIG\n\nmailhub=$FC_SMTP\n" >> $FC_DIR/data/cfg/ssmtp.conf;
		if [ ! -z ${FC_SMTP_SECURITY+x} ]
		then
			echo -e "Use$FC_SMTP_SECURITY=YES\n" >> $FC_DIR/data/cfg/ssmtp.conf;
		else
			echo -e "UseSTARTTLS=YES\n" >> $FC_DIR/data/cfg/ssmtp.conf;
		fi
88
		if [ ! -z ${FC_SMTP_LOGIN+x} ]
Sebastien's avatar
Sebastien committed
89
		then
90
			echo -e "AuthUser=$FC_SMTP_LOGIN\n" >> $FC_DIR/data/cfg/ssmtp.conf;
Sebastien's avatar
Sebastien committed
91
		fi
92
		if [ ! -z ${FC_SMTP_PASSWD+x} ]
Sebastien's avatar
Sebastien committed
93
		then
94
			echo -e "AuthPass=$FC_SMTP_PASSWD\n" >> $FC_DIR/data/cfg/ssmtp.conf;
Sebastien's avatar
Sebastien committed
95 96 97
		fi
	fi

98
	if [ ! -e $FC_DIR/data/cfg/local.cfg ]
Sebastien's avatar
Sebastien committed
99
	then
100
		echo -e "admin_mail=$FC_ADMIN\n" > $FC_DIR/data/cfg/local.cfg;
Sebastien's avatar
Sebastien committed
101
	fi
102
	if [ ! -e $FC_DIR/data/cfg/.htaccess ]
Sebastien's avatar
Sebastien committed
103
	then
104
		echo -e "Require all denied\n" > $FC_DIR/data/cfg/.htaccess
Sebastien's avatar
Sebastien committed
105 106
	fi

107
	if [ ! -e $FC_DIR/etc/.htaccess ]
Sebastien's avatar
Sebastien committed
108
	then
109
		echo -e "Require all denied\n" > $FC_DIR/etc/.htaccess
Sebastien's avatar
Sebastien committed
110 111
	fi

112
	echo -e "\n\n\e[32mfamily-companion is properly configured\n\n\e[39m";
Sebastien's avatar
Sebastien committed
113 114 115 116
else
	echo -e "\n\n\e[31m[ERROR] - Service not properly configured\n\n\e[39m";
fi

117
cp site/cfg/authentication-docker.cfg site/cfg/authentication.cfg
118
cp site/cfg/site-docker.cfg site/cfg/site.cfg
Sebastien's avatar
Sebastien committed
119
chown www-data.www-data $FC_DIR/data/cfg/local.cfg
Sebastien's avatar
Sebastien committed
120 121 122

echo -e "\e[49m";
echo -e "\e[0m";