#!/bin/bash # # mkdrupal v0.2: easy drupal installer # feedback: rhatto at riseup.net | gpl # # Mkdrupal is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or any later version. # # Mkdrupal is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., 59 Temple # Place - Suite 330, Boston, MA 02111-1307, USA # # # section 1: default procedures and definitions # TMP="/tmp" CONF="/etc/mksite/mksite.conf" LOCKFILE="$TMP/mksite.lock" MESSAGES="/usr/share/mksite/mksite.messages" HELPER_FUNCTIONS="/usr/libexec/mksite/mksite-helper" # plugin definitions PLUGIN_NAME="drupal" USE_VERSION="1" USE_DATABASE="1" DB_SCRIPTS="database/database.mysql" if [ -f "$HELPER_FUNCTIONS" ]; then source $HELPER_FUNCTIONS mksite_checks else echo Fatal error: function file not found, aborting. echo Erro fatal: arquivo de funcoes nao encontrado, abortando. exit 1 fi # # section 2: plugin specific functions # function usage { echo usage: "`basename $0` site-name [-n drupal-name]" } function create_config_file { # create a fresh drupal config file if [ -z "$PASSWD" ]; then mksite_ask_passwd fi echo " $PLUGIN_DIR/sites/$USER.$DOMAIN.$1/settings.php if [ "$2" == "$DOCROOT" ]; then echo "\$base_url = \"http://$USER.$DOMAIN\";" >> $PLUGIN_DIR/sites/$USER.$DOMAIN.$1/settings.php else echo "\$base_url = \"http://$USER.$DOMAIN/$1\";" >> $PLUGIN_DIR/sites/$USER.$DOMAIN.$1/settings.php fi echo " ini_set('arg_separator.output', '&'); ini_set('magic_quotes_runtime', 0); ini_set('magic_quotes_sybase', 0); ini_set('session.cache_expire', 200000); ini_set('session.cache_limiter', 'none'); ini_set('session.cookie_lifetime', 2000000); ini_set('session.gc_maxlifetime', 200000); ini_set('session.save_handler', 'user'); ini_set('session.use_only_cookies', 1); ini_set('session.use_trans_sid', 0); ?>" >> $PLUGIN_DIR/sites/$USER.$DOMAIN.$1/settings.php # ownership and permissions chown $APACHE_USER.$USER $PLUGIN_DIR/sites/$USER.$DOMAIN.$1/settings.php chmod 460 $PLUGIN_DIR/sites/$USER.$DOMAIN.$1/settings.php mksite_check_user if [ "$USER_EXIST" == "1" ]; then chown -R $USER.$USER $HOME/$USER/$INSTANCE_NAME fi } function create_upload_folder { mkdir -p $PLUGIN_DIR/files/$1/theme_editor ln -s $PLUGIN_DIR/files/$1/theme_editor $HOME/$USER/$INSTANCE_NAME/themes/theme_editor chown $APACHE_USER.$APACHE_GROUP $PLUGIN_DIR/files/$1 } function write_config_file { # write drupal related info in the site config file var_local="tmpfile drupal drupal_version" local $var_local tmpfile="$TMP/$USER-conf.tmp" drupal_version="`echo $PLUGIN_VERSION | sed -e 's/\./\\\./g'`" if [ -f "$MKSITE_BASE/sites/$USER" ]; then mksite_create_tmpfile $tmpfile if [ "$PLUGIN_DIR_TYPE" != "none" ]; then drupal="`mksite_eval_param $MKSITE_BASE/sites/$USER $PLUGIN_NAME_UPPER | sed -e "s/$INSTANCE_NAME:$drupal_version//g" -e 's/ //g'`" else drupal="`mksite_eval_param $MKSITE_BASE/sites/$USER $PLUGIN_NAME_UPPER | sed -e "s/$INSTANCE_NAME//g" -e 's/ //g'`" fi sed "/^$PLUGIN_NAME_UPPER/d" $MKSITE_BASE/sites/$USER > $tmpfile mv $tmpfile $MKSITE_BASE/sites/$USER fi if [ "$PLUGIN_DIR_TYPE" != "none" ]; then drupal="`echo $drupal $INSTANCE_NAME:$PLUGIN_VERSION | sed -e 's/ //g'`" else drupal="`echo $drupal $INSTANCE_NAME | sed -e 's/ //g'`" fi echo "$PLUGIN_NAME_UPPER=\"$drupal\"" >> $tmpfile mv $tmpfile $MKSITE_BASE/sites/$USER mksite_write_config_file unset $var_local } function update_base_url { # update base_url variable of a drupal instance config file sed -e 's/?>//' $PLUGIN_DIR/sites/$USER.$DOMAIN.$1/settings.php | sed '/\$base_url/d' > $PLUGIN_DIR/sites/$USER.$DOMAIN.$1/settings.php.new if [ "$1" == "$DOCROOT" ]; then echo "\$base_url = \"http://$USER.$DOMAIN\"; ?>" >> $PLUGIN_DIR/sites/$USER.$DOMAIN.$1/settings.php.new else echo "\$base_url = \"http://$USER.$DOMAIN/$1\"; ?>" >> $PLUGIN_DIR/sites/$USER.$DOMAIN.$1/settings.php.new fi cp $PLUGIN_DIR/sites/$USER.$DOMAIN.$1/settings.php $PLUGIN_DIR/sites/$USER.$DOMAIN.$1/settings.php.old mv $PLUGIN_DIR/sites/$USER.$DOMAIN.$1/settings.php.new $PLUGIN_DIR/sites/$USER.$DOMAIN.$1/settings.php rm $PLUGIN_DIR/sites/$USER.$DOMAIN.$1/settings.php.old } function update_config { # update the configurations of each drupal instance installed for $USER local drupal drupal_dir drupal_version drupal_docroot base_url for drupal in `mksite_eval_param $MKSITE_BASE/sites/$USER $PLUGIN_NAME_UPPER`; do if [ -f "$MKSITE_BASE/plugins/$PLUGIN_NAME.conf" ]; then drupal_conf="$MKSITE_BASE/plugins/$PLUGIN_NAME.conf" else drupal_conf="$MKSITE_BASE/defaults/plugins/$PLUGIN_NAME.conf" fi drupal_dir="`mksite_eval_param $drupal_conf PLUGIN_DIR`" drupal_version="`echo $drupal | cut -d : -f 2`" drupal="`echo $drupal | cut -d : -f 1`" if [ "$PLUGIN_DIR_TYPE" != "none" ]; then drupal_dir="$drupal_dir-$drupal_version" fi if [ ! -f "$drupal_dir/sites/$USER.$DOMAIN.$drupal/settings.php" ]; then echo $MESSAGE_ERROR_DRUPAL_NOT_INSTALLED $drupal else base_url="`grep '$base_url' $drupal_dir/sites/$USER.$DOMAIN.$drupal/settings.php | sed -e 's/"//g' -e 's/;//g' -e 's/^ *//g' | cut -d = -f 2 | cut -d "#" -f 1`" if [ "$drupal" == "$DOCROOT" ]; then drupal_docroot="$drupal" rm -f $drupal_dir/sites/$USER.$DOMAIN ln -s $drupal_dir/sites/$USER.$DOMAIN.$drupal $drupal_dir/sites/$USER.$DOMAIN if [ "$base_url" != "http://$USER.$DOMAIN" ]; then update_base_url $drupal fi else if [ "$base_url" != "http://$USER.$DOMAIN/$drupal" ]; then update_base_url $drupal fi fi fi done } function check_instance_installed { # check if the instance is installed # should return INSTALLED="installed" if its installed :P if [ "$PLUGIN_DIR_TYPE" != "none" ]; then for instance in `mksite_eval_param $MKSITE_BASE/sites/$USER $PLUGIN_NAME_UPPER`; do instance_version="`echo $instance | cut -d : -f 2`" instance="`echo $instance | cut -d : -f 1`" if [ "$INSTANCE_NAME" == "$instance" ] && [ ! -z "$instance_version" ]; then PLUGIN_VERSION="$instance_version" if [ -f "$MKSITE_BASE/plugins/$PLUGIN_NAME.conf" ]; then drupal_conf="$MKSITE_BASE/plugins/$PLUGIN_NAME.conf" else drupal_conf="$MKSITE_BASE/defaults/plugins/$PLUGIN_NAME.conf" fi PLUGIN_DIR="`mksite_eval_param $drupal_conf PLUGIN_DIR`" PLUGIN_DIR="$PLUGIN_DIR-$PLUGIN_VERSION" fi done if [ -f "$PLUGIN_DIR/sites/$USER.$DOMAIN.$INSTANCE_NAME/settings.php" ]; then INSTALLED="installed" fi elif [ -f "$PLUGIN_DIR/sites/$USER.$DOMAIN.$INSTANCE_NAME/settings.php" ]; then INSTALLED="installed" fi } function create_folders { # cria pasta # arquivos da instancia em $HOME/$USER/$INSTANCE_NAME mkdir -p $HOME/$USER/$INSTANCE_NAME/{themes,modules} ln -s $HOME/$USER/$INSTANCE_NAME/ $PLUGIN_DIR/sites/$USER.$DOMAIN.$INSTANCE_NAME } function create_contrib_folders { # cria pastas adicionais # TODO: como ficam as pastas para projetos com multiplas instancias? create_upload_folder $USER # TODO: fazer automaticamente echo $MESSAGE_SET_UPLOAD_FOLDER files/$site } function plugin_post_install { return } # # section 3: main procedure # mksite_init $*