stage/autorun.sh
author Dan
Tue, 23 Jun 2009 09:55:13 -0400
changeset 2 7dddb5fb1595
parent 0 8e044e762a6c
child 3 859eeb3579b2
permissions -rwxr-xr-x
Me and my obsession with getting files to exactly 2048 bytes.
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
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    19
## SCRIPT
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    20
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    21
cd `dirname $0`
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    22
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    23
echo "Welcome to the Enano CMS BitNami module installer."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    24
autobitnami=""
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    25
if test -n "$HOME"; then
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    26
  autobitnami=$(echo $HOME/lampstack-*)
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    27
  if test ! -d "$autobitnami"; then
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    28
    autobitnami=""
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    29
  fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    30
fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    31
while true; do
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    32
  if test -n "$autobitnami"; then
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    33
    read -p "Path to BitNami directory [$autobitnami]: " bitnami
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    34
    test -z "$bitnami" && bitnami="$autobitnami"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    35
  else
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    36
    read -p "Path to BitNami directory: " bitnami    
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    37
  fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    38
  check_bitnami_dir $bitnami && break
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    39
  echo "This does not seem to be the home of a BitNami LAMPStack installation."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    40
done
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    41
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    42
if [ -d $bitnami/apps/enanocms ]; then
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    43
  echo "Enano is already installed as a module on this LAMPStack."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    44
  exit 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    45
fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    46
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    47
mysql_port=$(cat $bitnami/properties.ini | grep mysql_port | sed -re 's/^mysql_port=//g')
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    48
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    49
while true; do
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    50
  read -s -p "MySQL root password: " mysqlpass
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    51
  echo ""
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    52
  out=`$mysqladmin -u root --password="$mysqlpass" ping 2>&1`
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    53
  test "$out" = "mysqld is alive" && break
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    54
  echo $out
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    55
done
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    56
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    57
echo "Creating database."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    58
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    59
bitnami_db="bn_enanocms"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    60
bitnami_user="bn_enanocms"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    61
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
    62
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    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;'
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    64
echo $query | $mysql -u root --password="$mysqlpass" || exit 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    65
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    66
echo "Installing files."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    67
mkdir -p $bitnami/apps/enanocms/{conf,licenses} || exit 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    68
cp -r ./enano-* $bitnami/apps/enanocms/htdocs || exit 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    69
cp ./COPYING $bitnami/apps/enanocms/licenses/ || exit 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    70
cat <<EOF > $bitnami/apps/enanocms/conf/enanocms.conf
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    71
Alias /enanocms "$bitnami/apps/enanocms/htdocs"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    72
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    73
<Directory "$bitnami/apps/enanocms/htdocs">
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    74
    Options -Indexes MultiViews FollowSymLinks
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    75
    AllowOverride All
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    76
    Order allow,deny
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    77
    Allow from all
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    78
</Directory>
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    79
EOF
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    80
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    81
echo "Patching Apache configuration."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    82
if test x$(cat $bitnami/apache2/conf/httpd.conf | grep '^Include' | grep enanocms | wc -l) = x0; then
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    83
  echo -ne "\nInclude "'"'"$bitnami/apps/enanocms/conf/enanocms?conf"'"'"\n" >> $bitnami/apache2/conf/httpd.conf
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    84
fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    85
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    86
echo "Adding Enano to BitNami's applications.html."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    87
if test x$(cat $bitnami/apache2/htdocs/applications.html | fgrep 'START BitNami Enano CMS Module enanocms' | wc -l) = x0; then
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    88
  cp enanocms-module.png $bitnami/apache2/htdocs/img/
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    89
  line=$(cat $bitnami/apache2/htdocs/applications.html | fgrep -n '<!-- @@BITNAMI_MODULE_PLACEHOLDER@@ -->' | cut -d ':' -f 1)
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    90
  head -n $(($line - 1)) $bitnami/apache2/htdocs/applications.html > ./applications-temp.html
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    91
  cat application.html >> ./applications-temp.html
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    92
  tail -n +$line $bitnami/apache2/htdocs/applications.html >> ./applications-temp.html
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    93
  mv ./applications-temp.html $bitnami/apache2/htdocs/applications.html
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    94
fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    95
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    96
echo "Starting Enano installer."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    97
while true; do
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    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
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    99
  then
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   100
    break
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   101
  else
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   102
    read -n 1 -p "Try installation again? [y/N] " RETRY
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   103
    if test "$RETRY" != "y"; then
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   104
      cat <<EOF
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   105
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   106
Enano installation failed. To install Enano using the web interface,
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   107
navigate to http://localhost/enanocms (or http://localhost:8080/enanocms,
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   108
depending on how you installed LAMPStack), and use the following settings:
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   109
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   110
  Database type:       MySQL
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   111
  Database hostname:   localhost
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   112
  Database name:       $bitnami_db
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   113
  Database username:   $bitnami_user
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   114
  Database password:   $bitnami_pass
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   115
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   116
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   117
EOF
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   118
      break
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   119
    fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   120
  fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   121
done
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   122
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   123
echo "Restarting Apache."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   124
$bitnami/ctlscript.sh restart apache
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
   125