Advertisement
Guest User

Untitled

a guest
Jan 13th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.01 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Usage: basic-install [OPTIONS] file
  4. #
  5. # Index:
  6. #
  7. # 0.- Initial Setup and Functions
  8. # 1.- Set your server correctly
  9. # 2.- Install latest WordPress version
  10. # 3.- Set up anti-spam and security measures
  11. # 4.- Install theme of your choice
  12. # 5.- Install a SEO plugin
  13. # 6.- Install contact form plugin
  14. # 7.- Setup your emails and show you how to connect
  15. # 8.- Resources
  16.  
  17. #####################################################################
  18. # 0.- Initial Setup and Functions
  19. #####################################################################
  20.  
  21. ## 1. Functions
  22.  
  23. # Shows a help message
  24. usage()
  25. {
  26. cat << EOF
  27. Usage: basic_install [OPTIONS]
  28.  
  29. -h Show this message
  30. -------------
  31. -m Set MultiSite
  32. -l <LANG> Set language
  33. -------------
  34. -H <HOST> Host
  35. -u <USER> MySQL user
  36. -p <PASS> MySQL password
  37. -------------
  38. -F <NAME> User First Name
  39. -L <NAME> User Last Name
  40. -E <EMAIL> User Email
  41. -------------
  42. -U <URL> URL
  43. -t <TITLE> Title
  44. -T <THEME> Theme
  45. EOF
  46. }
  47.  
  48. # Generates a random password
  49. mkpw(){ < /dev/urandom tr -dc '[:alnum:]' | head -c${1:-16};echo;}
  50.  
  51. # 2. Global variables
  52. USER_FIRST_NAME=
  53. USER_LAST_NAME=
  54. USER_LOGIN=
  55. USER_EMAIL=
  56. USER_PASS=$(mkpw 8)
  57.  
  58. DB_NAME=$(mkpw 8)
  59. DB_USER=$(mkpw 8)
  60. DB_PASS=$(mkpw 8)
  61. DB_HOST=
  62.  
  63. MYSQL_USER=
  64. MYSQL_PASS=
  65.  
  66. WP_ADMIN_NAME=$(mkpw 8)
  67. WP_ADMIN_PASSWORD=$(mkpw 8)
  68. WP_PREFIX=$(mkpw 4)
  69.  
  70. URL=
  71. TITLE=
  72. THEME=
  73. LANGUAGE=
  74.  
  75.  
  76. while getopts ":hml:u:p:H:F:L:E:U:t:T:" opt; do
  77. case $opt in
  78. h)
  79. usage
  80. exit 0
  81. ;;
  82. m)
  83. MULTISITE='yes'
  84. ;;
  85. l)
  86. LANGUAGE=$OPTARG
  87. ;;
  88. u)
  89. MYSQL_USER=$OPTARG
  90. ;;
  91. p)
  92. MYSQL_PASS=$OPTARG
  93. ;;
  94. H)
  95. DB_HOST=$OPTARG
  96. ;;
  97. F)
  98. USER_FIRST_NAME=$OPTARG
  99. ;;
  100. L)
  101. USER_LAST_NAME=$OPTARG
  102. ;;
  103. E)
  104. USER_EMAIL=$OPTARG
  105. ;;
  106. U)
  107. URL=$OPTARG
  108. ;;
  109. t)
  110. TITLE=$OPTARG
  111. ;;
  112. T)
  113. THEME=$OPTARG
  114. ;;
  115. \?)
  116. echo "Invalid option: -$OPTARG" >&2
  117. exit 1
  118. ;;
  119. :)
  120. echo "Option -$OPTARG requires an argument." >&2
  121. exit 1
  122. ;;
  123. esac
  124. done
  125.  
  126. # 3. Initial setup
  127. echo "
  128. [client]
  129. user=$MYSQL_USER
  130. password=$MYSQL_PASS" > /tmp/mysql-opts
  131.  
  132. #####################################################################
  133. # 1.- Set your server correctly
  134. #####################################################################
  135.  
  136. #####################################################################
  137. # 2.- Install latest WordPress version
  138. #####################################################################
  139.  
  140. # 1. Download WordPress and extract with wp-cli
  141. if [ $LANGUAGE != "" ]
  142. then wp core download --locale=$LANGUAGE
  143. else wp core download
  144. fi
  145.  
  146. ###########
  147.  
  148.  
  149. # 2. Create the Database and User
  150. echo 'Creating the Database and User...'
  151. Q1="CREATE DATABASE IF NOT EXISTS $DB_NAME;"
  152. Q2="GRANT ALL PRIVILEGES ON $DB_NAME.* TO '$DB_USER'@'$DB_HOST' IDENTIFIED BY '$DB_PASS';"
  153. Q3="FLUSH PRIVILEGES;"
  154. SQL="${Q1}${Q2}${Q3}"
  155.  
  156. # Run SQL script
  157. mysql --defaults-file=/tmp/mysql-opts -e "$SQL"
  158.  
  159. # Remove mysql-opts file
  160. rm /tmp/mysql-opts
  161.  
  162. ###########
  163.  
  164.  
  165. # 3. Set up wp-config.php
  166. echo 'Setting up wp-config.php...'
  167. mv wp-config-sample.php wp-config.php
  168.  
  169. sed \
  170. -i \
  171. -e "s/\(define('DB_NAME', '\)[a-z_]*\(');\)/\1"$DB_NAME"\2/" \
  172. -e "s/\(define('DB_USER', '\)[a-z_]*\(');\)/\1"$DB_USER"\2/" \
  173. -e "s/\(define('DB_PASSWORD', '\)[a-z_]*\(');\)/\1"$DB_PASS"\2/" \
  174. -e "s/\(define('DB_HOST', '\)[a-z_]*\(');\)/\1"$DB_HOST"\2/" \
  175. -e s/\'wp_\'/\'$WP_PREFIX\_\'/ wp-config.php
  176.  
  177. if [ $MULTISITE = 'yes' ]
  178. then sed -i '/Feliz/ i \
  179. define('\'ALLOW_WP_MULTISITE\'', true)' wp-config.php
  180. fi
  181.  
  182. ###########
  183.  
  184.  
  185. # 4. Run the Install Script
  186. echo 'Running the Install Script...'
  187. if [ ! $(wp core is-installed) ]
  188. then
  189. wp core install \
  190. --url=$URL \
  191. --title=$TITLE \
  192. --admin_name=$WP_ADMIN_NAME \
  193. --admin_email=$USER_EMAIL \
  194. --admin_password=$WP_ADMIN_PASSWORD
  195. fi
  196.  
  197.  
  198. #####################################################################
  199. # 3.- Set up anti-spam and security measures
  200. #####################################################################
  201.  
  202. # 1. Add a user with author privileges
  203. #wp user create $USER_LOGIN $USER_EMAIL2 --user_pass=$USER_PASS --role=author
  204.  
  205. # 2. Choose a strong password (see section 0.2 and 2.4)
  206. # .... done
  207.  
  208. # 3. Secure Your Password
  209. # : Search Brute Force Attack Plugin
  210.  
  211. # 4. Always update WordPress (see section 8.1)
  212. # .... done
  213.  
  214. # 5. Hide WordPress Version
  215. # 6. Change File Permisions
  216. # 7. Whitelist
  217. # 8. Backup
  218. # 9. Hide Your Plugins
  219. # 10. Analyze Server Logs
  220.  
  221. #wp plugin activate akismet
  222.  
  223. #####################################################################
  224. # 4.- Free Theme Bundle
  225. #####################################################################
  226. if [ $THEME != ""]
  227. then
  228. wp theme install $THEME --activate
  229. fi
  230.  
  231. #####################################################################
  232. # 5.- Install All-in-one SEO Pack
  233. #####################################################################
  234. #wp plugin install all-in-one-seo-pack --activate
  235.  
  236. #####################################################################
  237. # 6.- Install Contact Form 7
  238. #####################################################################
  239. #wp plugin install contact-form-7 --activate
  240.  
  241. #####################################################################
  242. # 7.- Setup your emails and show you how to connect
  243. #####################################################################
  244.  
  245. #####################################################################
  246. # 8.- Finsihing up
  247. #####################################################################
  248.  
  249. # 1. Removing wp-admin/install.php
  250. # K.Viswanathan => Step #6
  251. rm wp-admin/install.php
  252.  
  253. # 2. Complete User Profile
  254. # K.Viswanathan => Step #7
  255. wp user update 1 \
  256. --first-name=$USER_FIRST_NAME \
  257. --last-name=$USER_LAST_NAME
  258.  
  259. # 3. Prepare document for the user
  260.  
  261. # 2. Prepare document for admin
  262. cat > results.txt <<EOF
  263. = WP Admin =
  264. WP Admin Login: $WP_ADMIN_NAME
  265. WP Admin Password: $WP_ADMIN_PASSWORD
  266. EOF
  267. #####################################################################
  268. # 9.- Resources
  269. #####################################################################
  270. # - Karthnik Viswanathan. 20 Steps to a Flexible and Secure WordPress
  271. # installation. WpTuts+
  272.  
  273. # - 10 Steps to Securing Your WordPress Installation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement