0
|
1 |
#!/bin/bash
|
|
2 |
|
|
3 |
## FUNCTIONS
|
|
4 |
|
|
5 |
check_bitnami_dir()
|
|
6 |
{
|
|
7 |
test -d "$1" || return 1
|
|
8 |
test -f "$1/ctlscript.sh" || return 1
|
|
9 |
test -f "$1/properties.ini" || return 1
|
|
10 |
|
|
11 |
mysqladmin=$bitnami/mysql/bin/mysqladmin
|
|
12 |
test -x "$mysqladmin" || return 1
|
|
13 |
mysql=$bitnami/mysql/bin/mysql
|
|
14 |
test -x "$mysql" || return 1
|
|
15 |
|
|
16 |
return 0
|
|
17 |
}
|
|
18 |
|
|
19 |
## SCRIPT
|
|
20 |
|
|
21 |
cd `dirname $0`
|
|
22 |
|
|
23 |
echo "Welcome to the Enano CMS BitNami module installer."
|
|
24 |
autobitnami=""
|
|
25 |
if test -n "$HOME"; then
|
|
26 |
autobitnami=$(echo $HOME/lampstack-*)
|
|
27 |
if test ! -d "$autobitnami"; then
|
|
28 |
autobitnami=""
|
|
29 |
fi
|
|
30 |
fi
|
|
31 |
while true; do
|
|
32 |
if test -n "$autobitnami"; then
|
|
33 |
read -p "Path to BitNami directory [$autobitnami]: " bitnami
|
|
34 |
test -z "$bitnami" && bitnami="$autobitnami"
|
|
35 |
else
|
|
36 |
read -p "Path to BitNami directory: " bitnami
|
|
37 |
fi
|
|
38 |
check_bitnami_dir $bitnami && break
|
|
39 |
echo "This does not seem to be the home of a BitNami LAMPStack installation."
|
|
40 |
done
|
|
41 |
|
|
42 |
if [ -d $bitnami/apps/enanocms ]; then
|
|
43 |
echo "Enano is already installed as a module on this LAMPStack."
|
|
44 |
exit 1
|
|
45 |
fi
|
|
46 |
|
|
47 |
mysql_port=$(cat $bitnami/properties.ini | grep mysql_port | sed -re 's/^mysql_port=//g')
|
|
48 |
|
|
49 |
while true; do
|
|
50 |
read -s -p "MySQL root password: " mysqlpass
|
|
51 |
echo ""
|
|
52 |
out=`$mysqladmin -u root --password="$mysqlpass" ping 2>&1`
|
|
53 |
test "$out" = "mysqld is alive" && break
|
|
54 |
echo $out
|
|
55 |
done
|
|
56 |
|
|
57 |
echo "Creating database."
|
|
58 |
|
|
59 |
bitnami_db="bn_enanocms"
|
|
60 |
bitnami_user="bn_enanocms"
|
|
61 |
bitnami_pass=`dd if=/dev/urandom bs=256 count=1 2>/dev/null | tr -cd '\41-\46\50-\176' | cut -c 1-12`
|
|
62 |
|
|
63 |
query='CREATE DATABASE IF NOT EXISTS `'$bitnami_db'`; GRANT ALL PRIVILEGES ON '$bitnami_db'.* TO '"$bitnami_user"'@localhost IDENTIFIED BY '"'$bitnami_pass'"'; FLUSH PRIVILEGES;'
|
|
64 |
echo $query | $mysql -u root --password="$mysqlpass" || exit 1
|
|
65 |
|
|
66 |
echo "Installing files."
|
|
67 |
mkdir -p $bitnami/apps/enanocms/{conf,licenses} || exit 1
|
|
68 |
cp -r ./enano-* $bitnami/apps/enanocms/htdocs || exit 1
|
|
69 |
cp ./COPYING $bitnami/apps/enanocms/licenses/ || exit 1
|
|
70 |
cat <<EOF > $bitnami/apps/enanocms/conf/enanocms.conf
|
|
71 |
Alias /enanocms "$bitnami/apps/enanocms/htdocs"
|
|
72 |
|
|
73 |
<Directory "$bitnami/apps/enanocms/htdocs">
|
|
74 |
Options -Indexes MultiViews FollowSymLinks
|
|
75 |
AllowOverride All
|
|
76 |
Order allow,deny
|
|
77 |
Allow from all
|
|
78 |
</Directory>
|
|
79 |
EOF
|
|
80 |
|
|
81 |
echo "Patching Apache configuration."
|
|
82 |
if test x$(cat $bitnami/apache2/conf/httpd.conf | grep '^Include' | grep enanocms | wc -l) = x0; then
|
|
83 |
echo -ne "\nInclude "'"'"$bitnami/apps/enanocms/conf/enanocms?conf"'"'"\n" >> $bitnami/apache2/conf/httpd.conf
|
|
84 |
fi
|
|
85 |
|
|
86 |
echo "Adding Enano to BitNami's applications.html."
|
|
87 |
if test x$(cat $bitnami/apache2/htdocs/applications.html | fgrep 'START BitNami Enano CMS Module enanocms' | wc -l) = x0; then
|
|
88 |
cp enanocms-module.png $bitnami/apache2/htdocs/img/
|
|
89 |
line=$(cat $bitnami/apache2/htdocs/applications.html | fgrep -n '<!-- @@BITNAMI_MODULE_PLACEHOLDER@@ -->' | cut -d ':' -f 1)
|
|
90 |
head -n $(($line - 1)) $bitnami/apache2/htdocs/applications.html > ./applications-temp.html
|
|
91 |
cat application.html >> ./applications-temp.html
|
|
92 |
tail -n +$line $bitnami/apache2/htdocs/applications.html >> ./applications-temp.html
|
|
93 |
mv ./applications-temp.html $bitnami/apache2/htdocs/applications.html
|
|
94 |
fi
|
|
95 |
|
|
96 |
echo "Starting Enano installer."
|
|
97 |
while true; do
|
|
98 |
if $bitnami/php/bin/php $bitnami/apps/enanocms/htdocs/install/install-cli.php -b mysql -h 127.0.0.1 -o $mysql_port -u "$bitnami_user" -p "$bitnami_pass" -d $bitnami_db -i /enanocms -r rewrite
|
|
99 |
then
|
|
100 |
break
|
|
101 |
else
|
|
102 |
read -n 1 -p "Try installation again? [y/N] " RETRY
|
|
103 |
if test "$RETRY" != "y"; then
|
|
104 |
cat <<EOF
|
|
105 |
|
|
106 |
Enano installation failed. To install Enano using the web interface,
|
|
107 |
navigate to http://localhost/enanocms (or http://localhost:8080/enanocms,
|
|
108 |
depending on how you installed LAMPStack), and use the following settings:
|
|
109 |
|
|
110 |
Database type: MySQL
|
|
111 |
Database hostname: localhost
|
|
112 |
Database name: $bitnami_db
|
|
113 |
Database username: $bitnami_user
|
|
114 |
Database password: $bitnami_pass
|
|
115 |
|
|
116 |
|
|
117 |
EOF
|
|
118 |
break
|
|
119 |
fi
|
|
120 |
fi
|
|
121 |
done
|
|
122 |
|
|
123 |
echo "Restarting Apache."
|
|
124 |
$bitnami/ctlscript.sh restart apache
|
|
125 |
|