Drupal Installer and Vhost creator

Public

This script can be use to directly download the Drupal package. The Drupal version can be specify by specifying the Drupal version in the parameter - see the manual. After downloading the installer will execute the Drupal setup process. You have to supply the necessary information first like DB and Drupal login creds before running the setup. This script is not intended for production.

Get raw version
bash
  1. #!/bin/bash
  2. #
  3. # Copyright 2013 Gerald Villorente <gerald@ninjas-corner.com>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. # MA 02110-1301, USA.
  19. #
  20. # A utility script to lessen the effort of setting up of Drupal.
  21. #
  22. # This script can be use to directly download the Drupal package.
  23. # The Drupal version can be specify by specifying the Drupal version in the
  24. # parameter - see the manual. After downloading the installer will execute the
  25. # Drupal setup process. You have to supply the necessary informations first like
  26. # DB and Drupal login creds before running the setup.
  27. #
  28. # This script requires Drush.
  29. #
  30. # Note: This is not tested on Drupal 8 yet. Use this script with extra care.
  31.  
  32. # Help
  33. usage() {
  34. echo ""
  35. echo ""
  36. echo " ./install-drupal.sh [project-name] [target] [drupal-version]"
  37. echo ""
  38. echo ""
  39. echo " project-name The name of the project. This will be the name of the downloaded Drupal folder."
  40. echo " target The directory you wanted the Drupal will be save to. Make sure that the target ends with /."
  41. echo " drupal-version The version of Drupal you wanted to download. Options are: drupal, drupal-7.x, drupal-6"
  42. echo ""
  43. echo ""
  44. echo " Examples:"
  45. echo ""
  46. echo " ./install-drupal.sh myportfolio /home/gerald/html/ drupal Download latest recommended release of Drupal core."
  47. echo " ./install-drupal.sh myportfolio /home/gerald/html/ drupal-7.x Download latest 7.x development version of Drupal core."
  48. echo " ./install-drupal.sh myportfolio /home/gerald/html/ drupal-6 Download latest recommended release of Drupal 6.x."
  49. exit 1
  50. }
  51.  
  52. # Get the scripts root directory.
  53. SCRIPTSDIR=$(pwd)
  54.  
  55. # Validate the first parameter.
  56. if [ -z "$1" ]; then
  57. echo "Please check your first parameter, it appears to be empty. Read the guide using ./install-drupal.sh --help"
  58. exit 1
  59. else
  60. # Check if the supplied parameter is --help.
  61. # Display the help if true.
  62. if [ "$1" == "--help" ]; then
  63. usage
  64. else
  65. PROJECT=$1
  66. fi
  67. fi
  68.  
  69. # Validate second parameter.
  70. if [ -z "$2" ]; then
  71. echo "Second parameter is required. Read the guide using ./install-drupal.sh --help"
  72. exit 1
  73. else
  74. # Check if the path specified exists.
  75. if [ -d "$2" ]; then
  76. TARGETPATH=$2
  77. else
  78. echo "The path you specified does not exist."
  79. exit 1
  80. fi
  81. fi
  82.  
  83. # Validate the third parameter.
  84. if [ -z "$3" ]; then
  85. echo "Please check your second parameter, it appears to be empty. Read the guide using ./install-drupal.sh --help"
  86. exit 1
  87. else
  88. # The version that is going download is the latest Drupal 7.
  89. if [ "$3" == "drupal-7.x" ]; then
  90. VERSION=$3
  91. # The version that is going download is the latest Drupal 6.
  92. elif [ "$3" == "drupal-6" ]; then
  93. VERSION=$3
  94. # The version that is going download is the latest stable Drupal.
  95. elif [ "$3" == "drupal" ]; then
  96. VERSION=$3
  97. else
  98. echo "The version you entered is wrong."
  99. exit 1
  100. fi
  101. fi
  102.  
  103. # Navigate to the target directory.
  104. cd $TARGETPATH
  105.  
  106. # Get the Drupal package.
  107. echo "Downloading Drupal package. This may take several seconds or minutes depending on your internet speed..."
  108. drush dl $VERSION
  109.  
  110. # Rename the directory.
  111. LATESTDIR=$(ls -t . | head -1)
  112. mv $LATESTDIR $PROJECT
  113.  
  114. # Update the permission.
  115. #chmod 755 -R $PROJECT
  116. # Create file directory.
  117. #mkdir -p $PROJECT/sites/default/files
  118. #chmod 777 -R $PROJECT/sites/default/files
  119.  
  120. # Navigate inside Drupal directory.
  121. cd $PROJECT
  122.  
  123. # Setup process.
  124. echo -n "Would you like to continue[Yes/No]: "
  125. read CONTINUE
  126. # Execute when the user agree.
  127. if [ "$CONTINUE" == "Yes" ] || [ "$CONTINUE" == "Y" ] || [ "$CONTINUE" == "y" ]; then
  128. # Run the setup.
  129. echo ""
  130. echo "Collect all necessary variables."
  131. echo ""
  132. echo -n "Enter your MySQL username: "
  133. read DBUSERNAME
  134. echo -n "Enter your MySQL password: "
  135. read DBPASSWORD
  136. echo -n "Enter the MySQL port. By default it should be 3306: "
  137. read DBPORT
  138. echo -n "We have to create a new database. Please specify the name: "
  139. read DBNAME
  140. mysqladmin -u $DBUSERNAME -p$DBPASSWORD create $DBNAME
  141.  
  142. echo ""
  143. echo -n "Enter the admin email: "
  144. read DRUPALADMINEMAIL
  145. echo -n "Enter the admin username: "
  146. read DRUPALUSERNAME
  147. echo -n "Enter the Drupal admin password: "
  148. read DRUPALPASSWORD
  149. echo -n 'Enter the Drupal sitename: '
  150. read DRUPALSITENAME
  151. echo -n "Enter the Drupal system email: "
  152. read SITEEMAIL
  153. if [ "$VERSION" == "drupal-6" ]; then
  154. PROFILE="default"
  155. else
  156. PROFILE="standard"
  157. fi
  158.  
  159. # Run the installer.
  160. drush site-install $PROFILE --db-url=mysql://$DBUSERNAME:$DBPASSWORD@localhost:$DBPORT/$DBNAME --account-mail=$DRUPALADMINEMAIL --account-name=$DRUPALUSERNAME --account-pass=$DRUPALPASSWORD --site-name=$DRUPALSITENAME --site-mail=$SITEEMAIL
  161.  
  162. echo "Installation done."
  163. echo ""
  164. echo -n "Would you like to create new virtual host entry[Yes/No]: "
  165. read CONFIRM
  166. if [ "$CONTINUE" == "Yes" ] || [ "$CONTINUE" == "Y" ] || [ "$CONTINUE" == "y" ]; then
  167. ABSOLUTEPATH=$TARGETPATH$PROJECT
  168. echo -n "Enter the fakedomain. Ex. dev.example.com: "
  169. read FAKEDOMAIN
  170. # Navigate back to scripts directory.
  171. cd $SCRIPTSDIR
  172. # Create a new virtual host entry.
  173. sudo ./createvhost.sh $PROJECT $FAKEDOMAIN $TARGETPATH$PROJECT
  174. else
  175. exit 1
  176. fi
  177. else
  178. exit 1
  179. fi

Virtual Host creator for debian-based system. This script is not intended for production.

Get raw version
bash
  1. #!/bin/bash
  2. #
  3. # Copyright 2013 Gerald Villorente <gerald@ninjas-corner.com>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. # MA 02110-1301, USA.
  19. #
  20. #
  21. # Virtual Host creator for debian-based system.
  22. # This piece of code is for creating virtual host entry.
  23. # I used this to create vhost under my Ubuntu/Apache environment.
  24. #
  25. # HowTo:
  26. # This file should be executable in order to make it working.
  27. # You can use chmod u+x createvhost.sh.
  28.  
  29.  
  30. # Usage: sudo ./createvhost.sh [projectName] [fakeDomain] [projectPath]
  31. # Ex: sudo ./createvhost.sh mydrupalblog dev.mydrupalblog.com /home/gerald/dev/html/drupalblog
  32.  
  33. # Help function.
  34. help() {
  35. echo ""
  36. echo "This piece of code is for creating virtual host entry."
  37. echo ""
  38. echo "Usage: sudo ./createvhost.sh [projectName] [fakeDomain] [projectPath]"
  39. echo "Ex: sudo ./createvhost.sh mydrupalblog dev.mydrupalblog.com /home/gerald/dev/html/drupalblog"
  40. echo ""
  41. echo ""
  42. echo "Arguments:"
  43. echo " projectName The name of your project. This will be the filename or the config filename."
  44. echo " fakeDomain This is a fake domain and the value of ServerName."
  45. echo " projectPath The directory where your project currently resides."
  46.  
  47. exit 1
  48. }
  49.  
  50. # Validate that we run this script as sudoer.
  51. ROOT_UID=0
  52. EXECUTOR_ID=$(id -u)
  53. if [ "$EXECUTOR_ID" -ne "$ROOT_UID" ]; then
  54. echo "Must be run as sudoer."
  55. exit 0
  56. fi
  57.  
  58. # Check if the parameter is help.
  59. # Display the help if true.
  60. if [ "$1" == "--help" ]; then
  61. help
  62. fi
  63.  
  64. # Validate the first parameter.
  65. if [ -z "$1" ]; then
  66. echo "Please check your first parameter, it appears to be empty. Read the guide using sudo ./createvhost.sh --help"
  67. else
  68. projectName=$1
  69. fi
  70.  
  71. # Validate the second parameter.
  72. if [ -z "$2" ]; then
  73. echo "Please check your second parameter, it appears to be empty. Read the guide using sudo ./createvhost.sh --help"
  74. else
  75. fakeDomain=$2
  76. fi
  77.  
  78. # Validate the third parameter.
  79. if [ -z "$3" ]; then
  80. echo "Please check your third parameter, it appears to be empty. Read the guide using sudo ./createvhost.sh --help"
  81. else
  82. # Validate if path does exist.
  83. if [ ! -d "$3" ]; then
  84. echo "The path you specified does not exist."
  85. echo ""
  86. echo "Give me the correct path!"
  87. read path
  88. # TODO - Create a function that will check and read the user input.
  89. # This function will be useful so the user dont need to re-run the
  90. # script again.
  91. if [ ! -d "$path" ]; then
  92. echo "Please check the correct path and run the script again."
  93. exit 1
  94. else
  95. projectPath=$path
  96. fi
  97. else
  98. projectPath=$3
  99. fi
  100. fi
  101.  
  102. # Create the config file.
  103. touch /etc/apache2/sites-available/$1
  104.  
  105. # Insert the configuration.
  106. echo -e "<VirtualHost *:80> \n\tServerName $fakeDomain \n\tDocumentRoot $projectPath \n</VirtualHost>" > /etc/apache2/sites-available/$1
  107.  
  108. #Update hosts file
  109. echo "127.0.0.1 $fakeDomain" >> /etc/hosts
  110.  
  111. # Enable the config file.
  112. a2ensite $1
  113.  
  114. # Restart Apache service.
  115. sudo /etc/init.d/apache2 restart
  116.  
  117. echo ""
  118. echo ""
  119. echo "Done!"