stage/autorun.sh
author Dan Fuhry <dan@enanocms.org>
Mon, 05 Jul 2010 23:29:07 -0400
changeset 4 c6c431cf0a89
parent 3 859eeb3579b2
child 5 7d3b7009399d
permissions -rwxr-xr-x
OS X compatibility hell yeah!
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     1
#!/bin/bash
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     2
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     3
## FUNCTIONS
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     4
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     5
check_bitnami_dir()
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     6
{
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     7
  test -d "$1" || return 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     8
  test -f "$1/ctlscript.sh" || return 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     9
  test -f "$1/properties.ini" || return 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    10
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    11
  mysqladmin=$bitnami/mysql/bin/mysqladmin
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    12
  test -x "$mysqladmin" || return 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    13
  mysql=$bitnami/mysql/bin/mysql
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    14
  test -x "$mysql" || return 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    15
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    16
  return 0
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    17
}
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    18
4
c6c431cf0a89 OS X compatibility hell yeah!
Dan Fuhry <dan@enanocms.org>
parents: 3
diff changeset
    19
## COMPAT
c6c431cf0a89 OS X compatibility hell yeah!
Dan Fuhry <dan@enanocms.org>
parents: 3
diff changeset
    20
c6c431cf0a89 OS X compatibility hell yeah!
Dan Fuhry <dan@enanocms.org>
parents: 3
diff changeset
    21
# OS X sed (at least leopard and up) seem to support -E
c6c431cf0a89 OS X compatibility hell yeah!
Dan Fuhry <dan@enanocms.org>
parents: 3
diff changeset
    22
sedflags=Ee
c6c431cf0a89 OS X compatibility hell yeah!
Dan Fuhry <dan@enanocms.org>
parents: 3
diff changeset
    23
if ( sed --version 2>&1 | grep 'GNU sed' 2>&1 ) > /dev/null ; then
c6c431cf0a89 OS X compatibility hell yeah!
Dan Fuhry <dan@enanocms.org>
parents: 3
diff changeset
    24
	sedflags=re
c6c431cf0a89 OS X compatibility hell yeah!
Dan Fuhry <dan@enanocms.org>
parents: 3
diff changeset
    25
fi
c6c431cf0a89 OS X compatibility hell yeah!
Dan Fuhry <dan@enanocms.org>
parents: 3
diff changeset
    26
0
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    27
## SCRIPT
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    28
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    29
cd `dirname $0`
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    30
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    31
echo "Welcome to the Enano CMS BitNami module installer."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    32
autobitnami=""
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    33
if test -n "$HOME"; then
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    34
  autobitnami=$(echo $HOME/lampstack-*)
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    35
  if test ! -d "$autobitnami"; then
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    36
    autobitnami=""
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    37
  fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    38
fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    39
while true; do
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    40
  if test -n "$autobitnami"; then
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    41
    read -p "Path to BitNami directory [$autobitnami]: " bitnami
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    42
    test -z "$bitnami" && bitnami="$autobitnami"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    43
  else
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    44
    read -p "Path to BitNami directory: " bitnami    
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    45
  fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    46
  check_bitnami_dir $bitnami && break
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    47
  echo "This does not seem to be the home of a BitNami LAMPStack installation."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    48
done
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    49
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    50
if [ -d $bitnami/apps/enanocms ]; then
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    51
  echo "Enano is already installed as a module on this LAMPStack."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    52
  exit 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    53
fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    54
4
c6c431cf0a89 OS X compatibility hell yeah!
Dan Fuhry <dan@enanocms.org>
parents: 3
diff changeset
    55
mysql_port=$(cat $bitnami/properties.ini | grep mysql_port | sed -$sedflags 's/^mysql_port=//g')
0
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    56
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    57
while true; do
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    58
  read -s -p "MySQL root password: " mysqlpass
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    59
  echo ""
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    60
  out=`$mysqladmin -u root --password="$mysqlpass" ping 2>&1`
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    61
  test "$out" = "mysqld is alive" && break
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    62
  echo $out
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    63
done
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    64
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    65
echo "Creating database."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    66
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    67
bitnami_db="bn_enanocms"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    68
bitnami_user="bn_enanocms"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    69
bitnami_pass=`dd if=/dev/urandom bs=256 count=1 2>/dev/null | tr -cd '\41-\46\50-\176' | cut -c 1-12`
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    70
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    71
query='CREATE DATABASE IF NOT EXISTS `'$bitnami_db'`; GRANT ALL PRIVILEGES ON '$bitnami_db'.* TO '"$bitnami_user"'@localhost IDENTIFIED BY '"'$bitnami_pass'"'; FLUSH PRIVILEGES;'
3
859eeb3579b2 Added uninstall script and warning about SSE2-only build of GMP
Dan Fuhry <dan@enanocms.org>
parents: 0
diff changeset
    72
echo "$query" | $mysql -u root --password="$mysqlpass" || exit 1
0
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    73
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    74
echo "Installing files."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    75
mkdir -p $bitnami/apps/enanocms/{conf,licenses} || exit 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    76
cp -r ./enano-* $bitnami/apps/enanocms/htdocs || exit 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    77
cp ./COPYING $bitnami/apps/enanocms/licenses/ || exit 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    78
cat <<EOF > $bitnami/apps/enanocms/conf/enanocms.conf
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    79
Alias /enanocms "$bitnami/apps/enanocms/htdocs"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    80
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    81
<Directory "$bitnami/apps/enanocms/htdocs">
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    82
    Options -Indexes MultiViews FollowSymLinks
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    83
    AllowOverride All
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    84
    Order allow,deny
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    85
    Allow from all
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    86
</Directory>
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    87
EOF
3
859eeb3579b2 Added uninstall script and warning about SSE2-only build of GMP
Dan Fuhry <dan@enanocms.org>
parents: 0
diff changeset
    88
cp ./uninstall.sh $bitnami/apps/enanocms/
0
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    89
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    90
echo "Patching Apache configuration."
4
c6c431cf0a89 OS X compatibility hell yeah!
Dan Fuhry <dan@enanocms.org>
parents: 3
diff changeset
    91
if test "`cat $bitnami/apache2/conf/httpd.conf | grep '^Include' | grep enanocms | wc -l`" -eq 0; then
0
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    92
  echo -ne "\nInclude "'"'"$bitnami/apps/enanocms/conf/enanocms?conf"'"'"\n" >> $bitnami/apache2/conf/httpd.conf
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    93
fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    94
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    95
echo "Adding Enano to BitNami's applications.html."
4
c6c431cf0a89 OS X compatibility hell yeah!
Dan Fuhry <dan@enanocms.org>
parents: 3
diff changeset
    96
if test "`cat $bitnami/apache2/htdocs/applications.html | fgrep 'START BitNami Enano CMS Module enanocms' | wc -l`" -eq 0; then
0
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    97
  cp enanocms-module.png $bitnami/apache2/htdocs/img/
4
c6c431cf0a89 OS X compatibility hell yeah!
Dan Fuhry <dan@enanocms.org>
parents: 3
diff changeset
    98
  line=`cat $bitnami/apache2/htdocs/applications.html | fgrep -n '<!-- @@BITNAMI_MODULE_PLACEHOLDER@@ -->' | cut -d ':' -f 1`
0
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    99
  head -n $(($line - 1)) $bitnami/apache2/htdocs/applications.html > ./applications-temp.html
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   100
  cat application.html >> ./applications-temp.html
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   101
  tail -n +$line $bitnami/apache2/htdocs/applications.html >> ./applications-temp.html
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   102
  mv ./applications-temp.html $bitnami/apache2/htdocs/applications.html
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   103
fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   104
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   105
echo "Starting Enano installer."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   106
while true; do
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   107
  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
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   108
  then
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   109
    break
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   110
  else
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   111
    read -n 1 -p "Try installation again? [y/N] " RETRY
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   112
    if test "$RETRY" != "y"; then
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   113
      cat <<EOF
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   114
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   115
Enano installation failed. To install Enano using the web interface,
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   116
navigate to http://localhost/enanocms (or http://localhost:8080/enanocms,
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   117
depending on how you installed LAMPStack), and use the following settings:
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   118
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   119
  Database type:       MySQL
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   120
  Database hostname:   localhost
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   121
  Database name:       $bitnami_db
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   122
  Database username:   $bitnami_user
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   123
  Database password:   $bitnami_pass
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   124
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   125
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   126
EOF
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   127
      break
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   128
    fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   129
  fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   130
done
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   131
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   132
echo "Restarting Apache."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   133
$bitnami/ctlscript.sh restart apache
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   134
3
859eeb3579b2 Added uninstall script and warning about SSE2-only build of GMP
Dan Fuhry <dan@enanocms.org>
parents: 0
diff changeset
   135
echo
859eeb3579b2 Added uninstall script and warning about SSE2-only build of GMP
Dan Fuhry <dan@enanocms.org>
parents: 0
diff changeset
   136
echo -e "Installation finished, \e[31;1mbut be warned! We are aware of a bug with BitNami's"
859eeb3579b2 Added uninstall script and warning about SSE2-only build of GMP
Dan Fuhry <dan@enanocms.org>
parents: 0
diff changeset
   137
echo -e "copy of GMP.\e[0m If your server doesn't support SSE2, Enano logins may fail. A"
859eeb3579b2 Added uninstall script and warning about SSE2-only build of GMP
Dan Fuhry <dan@enanocms.org>
parents: 0
diff changeset
   138
echo -e "symptom of this problem is messages similar to the following in your Apache"
859eeb3579b2 Added uninstall script and warning about SSE2-only build of GMP
Dan Fuhry <dan@enanocms.org>
parents: 0
diff changeset
   139
echo -e "error log and a blank response when you try to log in to your Enano website:"
859eeb3579b2 Added uninstall script and warning about SSE2-only build of GMP
Dan Fuhry <dan@enanocms.org>
parents: 0
diff changeset
   140
echo
859eeb3579b2 Added uninstall script and warning about SSE2-only build of GMP
Dan Fuhry <dan@enanocms.org>
parents: 0
diff changeset
   141
echo -e "\t[Mon Jul 05 14:22:10 2010] [notice] child pid 26544 exit signal"
859eeb3579b2 Added uninstall script and warning about SSE2-only build of GMP
Dan Fuhry <dan@enanocms.org>
parents: 0
diff changeset
   142
echo -e "\tIllegal instruction (4)"
859eeb3579b2 Added uninstall script and warning about SSE2-only build of GMP
Dan Fuhry <dan@enanocms.org>
parents: 0
diff changeset
   143
echo
859eeb3579b2 Added uninstall script and warning about SSE2-only build of GMP
Dan Fuhry <dan@enanocms.org>
parents: 0
diff changeset
   144
echo -e "If you experience this bug, please report it to BitNami, not the Enano project."
859eeb3579b2 Added uninstall script and warning about SSE2-only build of GMP
Dan Fuhry <dan@enanocms.org>
parents: 0
diff changeset
   145
echo
859eeb3579b2 Added uninstall script and warning about SSE2-only build of GMP
Dan Fuhry <dan@enanocms.org>
parents: 0
diff changeset
   146