You are here

install.sh.txt in Hostmaster (Aegir) 5.x

#!/usr/bin/env sh

AEGIR_VERSION=0.2
DRUPAL_VERSION=5.18

DRUSH_TAG=DRUPAL-6--2-0
PROVISION_TAG=DRUPAL-6--0-2
HOSTING_TAG=DRUPAL-5--0-2
AMENU_TAG=DRUPAL-5--2-8

NO_COLOR='\e[0m'
UL='\E[0;4m'
BOLD='\E[0;1m'

aegir_title () {
  echo "$BOLD$UL$1$NO_COLOR"; 
}

aegir_prompt () {
  echo "\n$BOLD$1$NO_COLOR \c";
}

SUDO_PASS=''
root_sudo () {
  while [ -z $SUDO_PASS ]; do
    echo "Enter sudo password: \c";
    read -s TEMP_SUDO_PASS;
    echo ""
    echo $TEMP_SUDO_PASS | sudo -S true 2> /dev/null
    if [ $? != 1 ]; then
      SUDO_PASS=$TEMP_SUDO_PASS;
    else
      echo "Sudo password incorrect, please try again.";
    fi;
  done;

  if [ -n $1 ]; then
    echo $SUDO_PASS | sudo -S "$1";
  fi;
}


AEGIR_PASS=''
aegir_sudo () {
  while [ -z $AEGIR_PASS ]; do
    echo "Enter password $AEGIR_USER user: \c";
    read -s TEMP_AEGIR_PASS;
    echo ""
    echo $TEMP_AEGIR_PASS | sudo -H -u $AEGIR_USER -S - true 2> /dev/null
    if [ $? != 1 ]; then
      AEGIR_PASS=$TEMP_AEGIR_PASS;
    else
      echo "Sudo password incorrect, please try again.";
    fi;
  done;
  if [ -n $1 ]; then
    echo $AEGIR_PASS | sudo -H -u $AEGIR_USER -S - "$1";
  fi;
}

find_apachectl () {
  found=`which apache2ctl || which apachectl`
  if [ $? = 1 ]; then
    echo "Could not find apache2ctl or apachectl in your path. exiting";
    exit;
  fi;
  export APACHECTL_BIN=$found
}

find_phpcli () {
  found=`which php5 || which php`
  if [ $? = 1 ]; then
    echo "Could not find php5 or php binaries in your path. exiting";
    exit;
  fi;
  export PHP_BIN=$found
}

find_httpd () {
  found=`which apache2 || which apache || which httpd`
  if [ $? = 1 ]; then
    echo "Could not find apache2, apache or httpd in your path. exiting";
    exit;
  fi;
  export HTTPD_BIN=$found
}

find_httpdconf () {
  HTTPD_CONF=`$APACHECTL_BIN -V | grep SERVER_CONFIG_FILE | sed -e 's/.*=//' -e 's/"//g'`
}

find_web_group () {
  bnfound=`basename $HTTPD_BIN`
  group=`ps -eo user,group,comm  | grep $bnfound | grep -v 'root' | awk '{print $2}'`
}

edit_visudo () {
  sudo cat /etc/sudoers > /tmp/sudoers; 
  echo "$AEGIR_USER ALL= NOPASSWD: $APACHECTL_BIN" >> /tmp/sudoers
  sudo visudo -c -f /tmp/sudoers
  if [ $? != 0 ]; then
    sudo rm /tmp/sudoers;
    exit 1;
  fi
  if [ -e /etc/sudoers.tmp ]; 
    sudo rm /tmp/sudoers;
    then exit 1; 
  fi
  sudo mv /tmp/sudoers /etc/sudoers
}

edit_httpdconf () {
  echo "\nInclude $CONF_DIR" >> $HTTPD_CONF
}

aegir_user () {

  AEGIR_USER=''

  aegir_title "SECTION 1 : Aegir user account"
  echo "Aegir is designed to run as it's own user that was created specifically for it."
  echo "This script will not create the user account, but will install Aegir for the currently logged in user."
  aegir_prompt "Install Aegir as the $USER user? yes/no (Y/n) :"
  read yesno
  if `echo $yesno | grep -qi y`; then
    AEGIR_USER=$USER;
    aegir_user_home
  else
    while [ -z $AEGIR_USER ]; do
      aegir_prompt "Which user do you want to install aegir as? [aegir] :"
      read USER_CHECK
      if [ -z $USER_CHECK ]; then
        USER_CHECK=aegir;
      fi;

      AEGIR_UID=`id -u $USER_CHECK 2> /dev/null`
      if [ $? = 0 ]; then
        echo "User $USER_CHECK already exists.";
        AEGIR_USER=USER_CHECK
        aegir_user_home
      else
        echo "User does not exist, do you want to create this user?"
      fi;
    done;
  fi;
}

aegir_user_home() {
  if [ `uname` = 'Darwin' ]; then
    AEGIR_HOME=`dscl localhost -read /Local/Default/Users/$AEGIR_USER NFSHomeDirectory | awk '{print $2}'`
  else
    AEGIR_HOME=`cat /etc/passwd | grep $AEGIR_USER | awk -F: '{print $6}'`
  fi;
  if [ -z $AEGIR_HOME ]; then
    echo "Aegir requires the user to have a home directory";
    exit 1;
  fi;
  return $?;
}

aegir_password() {

}


check_requirements () {
  aegir_title "SECTION 2 : Checking dependencies"
  echo "Checking that all the required commands are available :"

  DOEXIT=0

  found=`type php`
  if [ $? != 0 ]; then
    echo "PHP command line interface not available."
    DOEXIT=1;
  else
    echo $found;
  fi;

  found=`type mysql`
  if [ $? != 0 ]; then
    echo "Mysql client binary not available."
    DOEXIT=1;
  else
    echo $found;
  fi;

  found=`type cvs`
  if [ $? != 0 ]; then
    echo "CVS command not available."
    DOEXIT=1
  fi;

  found=`type wget`
  if [ $? != 0 ]; then
    echo "Wget command not available."
    DOEXIT=1;
  else
    echo $found;
  fi;

  if [ $DOEXIT = 1 ]; then
    echo "\n Aegir can not be installed because of missing dependencies."
    echo "Please install the missing packages and run this script again.\n\n\n"
    exit
  fi;

  echo "All the requirements are available."
}


aegir_download () {
  aegir_title "SECTION 3 : Downloading Aegir"
  echo "Logging in to Drupal CVS"
  export CVSROOT=:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib
  cvs login

  echo "Downloading Drush"
  cvs_co modules/drush $DRUSH_TAG ~/drush

  echo "Downloading Provision"
  cvs_co modules/provision $PROVISION_TAG ~/.drush/provision

  echo "Download hostmaster install profile"
  cvs_co profiles/hostmaster $HOSTING_TAG ~/hostmaster

  echo "Download hosting front end"
  cvs_co modules/hosting $HOSTING_TAG ~/hostmaster/modules/hosting

  echo "Download eldir theme"
  cvs_co themes/eldir $HOSTING_TAG ~/hostmaster/themes/eldir

  echo "Download admin_menu module"
  cvs_co modules/admin_menu $AMENU_TAG ~/hostmaster/modules/admin_menu

  echo "Downloading Drupal"
  drush/drush.php dl drupal-$DRUPAL_VERSION
  mv hostmaster $DRUPAL_DIR/profiles/

  echo "Making settings.php file writeable"
  chmod 777 $DRUPAL_DIR/sites/default/settings.php
}

cvs_co () {
  bn=`basename $3`
  cvs -z6 co -d $bn.tmp -r$2 contributions/$1
  mv $bn.tmp $3
}

aegir_vhost () {
  aegir_title "SECTION 4 : Creating Virtual host configuration file"

  aegir_prompt "Choose a domain for your hosting site: "
  read $DOMAIN

  CONF_DIR=~/config/vhost.d
  DRUPAL_DIR=~/drupal-$DRUPAL_VERSION

  echo Creating $CONF_DIR to store configuration files
  mkdir -p $CONF_DIR

  sed -e "s+aegir.example.com+$DOMAIN+g" $DRUPAL_DIR/profiles/hostmaster/apache2.conf.txt |
  sed -e "s+/var/aegir/drupal-5.x+$DRUPAL_DIR+g" |
  sed -e "s+/var/aegir/config/vhost.d+$CONF_DIR+g" > $CONF_DIR/$DOMAIN

  echo "You will need to modify your http.conf file to add the following line to it :"
  echo "Include $CONF_DIR"
}

aegir_database () {
  aegir_title "SECTION 5 : Setting up MySQL"
  aegir_prompt "MySQL root user password : "
  read DBPASS

  echo "Creating mysql database for hostmaster site :"
  mysqladmin -uroot -p$DBPASS create hostmaster

  echo "Creating hostmaster user account :"
  aegir_prompt "Username [hostmaster]:"
  read HMUSER

  aegir_prompt "Password:"
  read HMPASS

  echo "GRANT ALL ON hostmaster.* TO '$HMUSER'@'localhost' IDENTIFIED BY '$HMPASS'" | 
   mysql -uroot  -p$DBPASS hostmaster
}

clear
aegir_title "Installing Aegir $AEGIR_VERSION"
echo "This script is not safe to use yet, please follow the instructions in install.txt"
exit

#cd ~/
root_sudo ls
#aegir_user
#check_requirements
#aegir_download
#aegir_vhost
#aegir_database

File

install.sh.txt
View source
  1. #!/usr/bin/env sh
  2. AEGIR_VERSION=0.2
  3. DRUPAL_VERSION=5.18
  4. DRUSH_TAG=DRUPAL-6--2-0
  5. PROVISION_TAG=DRUPAL-6--0-2
  6. HOSTING_TAG=DRUPAL-5--0-2
  7. AMENU_TAG=DRUPAL-5--2-8
  8. NO_COLOR='\e[0m'
  9. UL='\E[0;4m'
  10. BOLD='\E[0;1m'
  11. aegir_title () {
  12. echo "$BOLD$UL$1$NO_COLOR";
  13. }
  14. aegir_prompt () {
  15. echo "\n$BOLD$1$NO_COLOR \c";
  16. }
  17. SUDO_PASS=''
  18. root_sudo () {
  19. while [ -z $SUDO_PASS ]; do
  20. echo "Enter sudo password: \c";
  21. read -s TEMP_SUDO_PASS;
  22. echo ""
  23. echo $TEMP_SUDO_PASS | sudo -S true 2> /dev/null
  24. if [ $? != 1 ]; then
  25. SUDO_PASS=$TEMP_SUDO_PASS;
  26. else
  27. echo "Sudo password incorrect, please try again.";
  28. fi;
  29. done;
  30. if [ -n $1 ]; then
  31. echo $SUDO_PASS | sudo -S "$1";
  32. fi;
  33. }
  34. AEGIR_PASS=''
  35. aegir_sudo () {
  36. while [ -z $AEGIR_PASS ]; do
  37. echo "Enter password $AEGIR_USER user: \c";
  38. read -s TEMP_AEGIR_PASS;
  39. echo ""
  40. echo $TEMP_AEGIR_PASS | sudo -H -u $AEGIR_USER -S - true 2> /dev/null
  41. if [ $? != 1 ]; then
  42. AEGIR_PASS=$TEMP_AEGIR_PASS;
  43. else
  44. echo "Sudo password incorrect, please try again.";
  45. fi;
  46. done;
  47. if [ -n $1 ]; then
  48. echo $AEGIR_PASS | sudo -H -u $AEGIR_USER -S - "$1";
  49. fi;
  50. }
  51. find_apachectl () {
  52. found=`which apache2ctl || which apachectl`
  53. if [ $? = 1 ]; then
  54. echo "Could not find apache2ctl or apachectl in your path. exiting";
  55. exit;
  56. fi;
  57. export APACHECTL_BIN=$found
  58. }
  59. find_phpcli () {
  60. found=`which php5 || which php`
  61. if [ $? = 1 ]; then
  62. echo "Could not find php5 or php binaries in your path. exiting";
  63. exit;
  64. fi;
  65. export PHP_BIN=$found
  66. }
  67. find_httpd () {
  68. found=`which apache2 || which apache || which httpd`
  69. if [ $? = 1 ]; then
  70. echo "Could not find apache2, apache or httpd in your path. exiting";
  71. exit;
  72. fi;
  73. export HTTPD_BIN=$found
  74. }
  75. find_httpdconf () {
  76. HTTPD_CONF=`$APACHECTL_BIN -V | grep SERVER_CONFIG_FILE | sed -e 's/.*=//' -e 's/"//g'`
  77. }
  78. find_web_group () {
  79. bnfound=`basename $HTTPD_BIN`
  80. group=`ps -eo user,group,comm | grep $bnfound | grep -v 'root' | awk '{print $2}'`
  81. }
  82. edit_visudo () {
  83. sudo cat /etc/sudoers > /tmp/sudoers;
  84. echo "$AEGIR_USER ALL= NOPASSWD: $APACHECTL_BIN" >> /tmp/sudoers
  85. sudo visudo -c -f /tmp/sudoers
  86. if [ $? != 0 ]; then
  87. sudo rm /tmp/sudoers;
  88. exit 1;
  89. fi
  90. if [ -e /etc/sudoers.tmp ];
  91. sudo rm /tmp/sudoers;
  92. then exit 1;
  93. fi
  94. sudo mv /tmp/sudoers /etc/sudoers
  95. }
  96. edit_httpdconf () {
  97. echo "\nInclude $CONF_DIR" >> $HTTPD_CONF
  98. }
  99. aegir_user () {
  100. AEGIR_USER=''
  101. aegir_title "SECTION 1 : Aegir user account"
  102. echo "Aegir is designed to run as it's own user that was created specifically for it."
  103. echo "This script will not create the user account, but will install Aegir for the currently logged in user."
  104. aegir_prompt "Install Aegir as the $USER user? yes/no (Y/n) :"
  105. read yesno
  106. if `echo $yesno | grep -qi y`; then
  107. AEGIR_USER=$USER;
  108. aegir_user_home
  109. else
  110. while [ -z $AEGIR_USER ]; do
  111. aegir_prompt "Which user do you want to install aegir as? [aegir] :"
  112. read USER_CHECK
  113. if [ -z $USER_CHECK ]; then
  114. USER_CHECK=aegir;
  115. fi;
  116. AEGIR_UID=`id -u $USER_CHECK 2> /dev/null`
  117. if [ $? = 0 ]; then
  118. echo "User $USER_CHECK already exists.";
  119. AEGIR_USER=USER_CHECK
  120. aegir_user_home
  121. else
  122. echo "User does not exist, do you want to create this user?"
  123. fi;
  124. done;
  125. fi;
  126. }
  127. aegir_user_home() {
  128. if [ `uname` = 'Darwin' ]; then
  129. AEGIR_HOME=`dscl localhost -read /Local/Default/Users/$AEGIR_USER NFSHomeDirectory | awk '{print $2}'`
  130. else
  131. AEGIR_HOME=`cat /etc/passwd | grep $AEGIR_USER | awk -F: '{print $6}'`
  132. fi;
  133. if [ -z $AEGIR_HOME ]; then
  134. echo "Aegir requires the user to have a home directory";
  135. exit 1;
  136. fi;
  137. return $?;
  138. }
  139. aegir_password() {
  140. }
  141. check_requirements () {
  142. aegir_title "SECTION 2 : Checking dependencies"
  143. echo "Checking that all the required commands are available :"
  144. DOEXIT=0
  145. found=`type php`
  146. if [ $? != 0 ]; then
  147. echo "PHP command line interface not available."
  148. DOEXIT=1;
  149. else
  150. echo $found;
  151. fi;
  152. found=`type mysql`
  153. if [ $? != 0 ]; then
  154. echo "Mysql client binary not available."
  155. DOEXIT=1;
  156. else
  157. echo $found;
  158. fi;
  159. found=`type cvs`
  160. if [ $? != 0 ]; then
  161. echo "CVS command not available."
  162. DOEXIT=1
  163. fi;
  164. found=`type wget`
  165. if [ $? != 0 ]; then
  166. echo "Wget command not available."
  167. DOEXIT=1;
  168. else
  169. echo $found;
  170. fi;
  171. if [ $DOEXIT = 1 ]; then
  172. echo "\n Aegir can not be installed because of missing dependencies."
  173. echo "Please install the missing packages and run this script again.\n\n\n"
  174. exit
  175. fi;
  176. echo "All the requirements are available."
  177. }
  178. aegir_download () {
  179. aegir_title "SECTION 3 : Downloading Aegir"
  180. echo "Logging in to Drupal CVS"
  181. export CVSROOT=:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib
  182. cvs login
  183. echo "Downloading Drush"
  184. cvs_co modules/drush $DRUSH_TAG ~/drush
  185. echo "Downloading Provision"
  186. cvs_co modules/provision $PROVISION_TAG ~/.drush/provision
  187. echo "Download hostmaster install profile"
  188. cvs_co profiles/hostmaster $HOSTING_TAG ~/hostmaster
  189. echo "Download hosting front end"
  190. cvs_co modules/hosting $HOSTING_TAG ~/hostmaster/modules/hosting
  191. echo "Download eldir theme"
  192. cvs_co themes/eldir $HOSTING_TAG ~/hostmaster/themes/eldir
  193. echo "Download admin_menu module"
  194. cvs_co modules/admin_menu $AMENU_TAG ~/hostmaster/modules/admin_menu
  195. echo "Downloading Drupal"
  196. drush/drush.php dl drupal-$DRUPAL_VERSION
  197. mv hostmaster $DRUPAL_DIR/profiles/
  198. echo "Making settings.php file writeable"
  199. chmod 777 $DRUPAL_DIR/sites/default/settings.php
  200. }
  201. cvs_co () {
  202. bn=`basename $3`
  203. cvs -z6 co -d $bn.tmp -r$2 contributions/$1
  204. mv $bn.tmp $3
  205. }
  206. aegir_vhost () {
  207. aegir_title "SECTION 4 : Creating Virtual host configuration file"
  208. aegir_prompt "Choose a domain for your hosting site: "
  209. read $DOMAIN
  210. CONF_DIR=~/config/vhost.d
  211. DRUPAL_DIR=~/drupal-$DRUPAL_VERSION
  212. echo Creating $CONF_DIR to store configuration files
  213. mkdir -p $CONF_DIR
  214. sed -e "s+aegir.example.com+$DOMAIN+g" $DRUPAL_DIR/profiles/hostmaster/apache2.conf.txt |
  215. sed -e "s+/var/aegir/drupal-5.x+$DRUPAL_DIR+g" |
  216. sed -e "s+/var/aegir/config/vhost.d+$CONF_DIR+g" > $CONF_DIR/$DOMAIN
  217. echo "You will need to modify your http.conf file to add the following line to it :"
  218. echo "Include $CONF_DIR"
  219. }
  220. aegir_database () {
  221. aegir_title "SECTION 5 : Setting up MySQL"
  222. aegir_prompt "MySQL root user password : "
  223. read DBPASS
  224. echo "Creating mysql database for hostmaster site :"
  225. mysqladmin -uroot -p$DBPASS create hostmaster
  226. echo "Creating hostmaster user account :"
  227. aegir_prompt "Username [hostmaster]:"
  228. read HMUSER
  229. aegir_prompt "Password:"
  230. read HMPASS
  231. echo "GRANT ALL ON hostmaster.* TO '$HMUSER'@'localhost' IDENTIFIED BY '$HMPASS'" |
  232. mysql -uroot -p$DBPASS hostmaster
  233. }
  234. clear
  235. aegir_title "Installing Aegir $AEGIR_VERSION"
  236. echo "This script is not safe to use yet, please follow the instructions in install.txt"
  237. exit
  238. #cd ~/
  239. root_sudo ls
  240. #aegir_user
  241. #check_requirements
  242. #aegir_download
  243. #aegir_vhost
  244. #aegir_database