|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Args: |
| 4 | +# $1 domain name (example.com) |
| 5 | +# $2 mysql root password |
| 6 | + |
| 7 | +#stuff to do: check root, check arg numbers, print help, standard documenation |
| 8 | + |
| 9 | +randpass() { |
| 10 | + CHAR="[:alnum:]" |
| 11 | + RET=`cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-16}` |
| 12 | +} |
| 13 | + |
| 14 | +INSTALL_DIR="/var/www/$1/htdocs" |
| 15 | +cd $INSTALL_DIR |
| 16 | + |
| 17 | +#Generate all required random passwords/salt/hashes |
| 18 | +randpass |
| 19 | +DB_PASS=$RET |
| 20 | +randpass |
| 21 | +USER_PASS=$RET |
| 22 | + |
| 23 | +#Sanitize domain name to take out periods |
| 24 | +DOMAIN_NAME=$(echo $1 | sed "s/\./__/") |
| 25 | + |
| 26 | +#Get latest version, delete old version |
| 27 | +rm latest.* |
| 28 | +wget http://wordpress.org/latest.tar.gz |
| 29 | + |
| 30 | +#Extract to web directory |
| 31 | +tar xf latest* |
| 32 | +mv wordpress/* . |
| 33 | +rm -rf wordpress/ |
| 34 | + |
| 35 | +#Make user and group |
| 36 | +useradd $DOMAIN_NAME |
| 37 | +groupadd $DOMAIN_NAME |
| 38 | +echo $USER_PASS > tmp |
| 39 | +echo $USER_PASS >> tmp |
| 40 | +passwd $DOMAIN_NAME < tmp |
| 41 | +usermod -g $DOMAIN_NAME $DOMAIN_NAME |
| 42 | + |
| 43 | +#chown and chgrp entire directory to new user |
| 44 | +chown -R $DOMAIN_NAME * |
| 45 | +chgrp -R $DOMAIN_NAME * |
| 46 | + |
| 47 | +#change permissions (not necessary so far) |
| 48 | + |
| 49 | +#Create Database and Database user |
| 50 | +echo "CREATE DATABASE $DOMAIN_NAME; |
| 51 | +GRANT ALL PRIVILEGES ON $DOMAIN_NAME.* TO "$DOMAIN_NAME"@"localhost" IDENTIFIED BY '"$DB_PASS"'; |
| 52 | +FLUSH PRIVILEGES; |
| 53 | +EXIT;" > input |
| 54 | +mysql --user=root --password=$2 < input > output.tab |
| 55 | + |
| 56 | + |
| 57 | +#Make config.php file |
| 58 | +echo "<?php |
| 59 | +/** |
| 60 | + * The base configurations of the WordPress. |
| 61 | + * |
| 62 | + * This file has the following configurations: MySQL settings, Table Prefix, |
| 63 | + * Secret Keys, WordPress Language, and ABSPATH. You can find more information |
| 64 | + * by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing |
| 65 | + * wp-config.php} Codex page. You can get the MySQL settings from your web host. |
| 66 | + * |
| 67 | + * This file is used by the wp-config.php creation script during the |
| 68 | + * installation. You don't have to use the web site, you can just copy this file |
| 69 | + * to "wp-config.php" and fill in the values. |
| 70 | + * |
| 71 | + * @package WordPress |
| 72 | + */ |
| 73 | +
|
| 74 | +// ** MySQL settings - You can get this info from your web host ** // |
| 75 | +/** The name of the database for WordPress */ |
| 76 | +define('DB_NAME', '$DOMAIN_NAME'); |
| 77 | +
|
| 78 | +/** MySQL database username */ |
| 79 | +define('DB_USER', '$DOMAIN_NAME'); |
| 80 | +
|
| 81 | +/** MySQL database password */ |
| 82 | +define('DB_PASSWORD', '$DB_PASS'); |
| 83 | +
|
| 84 | +/** MySQL hostname */ |
| 85 | +define('DB_HOST', 'localhost'); |
| 86 | +
|
| 87 | +/** Database Charset to use in creating database tables. */ |
| 88 | +define('DB_CHARSET', 'utf8'); |
| 89 | +
|
| 90 | +/** The Database Collate type. Don't change this if in doubt. */ |
| 91 | +define('DB_COLLATE', ''); |
| 92 | +
|
| 93 | +/**#@+ |
| 94 | + * Authentication Unique Keys and Salts. |
| 95 | + * |
| 96 | + * Change these to different unique phrases! |
| 97 | + * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service} |
| 98 | + * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again. |
| 99 | + * |
| 100 | + * @since 2.6.0 |
| 101 | + */" > wp-config.php |
| 102 | + |
| 103 | +wget https://api.wordpress.org/secret-key/1.1/salt/ |
| 104 | +cat index.html >> wp-config.php |
| 105 | + |
| 106 | +echo "/**#@-*/ |
| 107 | +
|
| 108 | +/** |
| 109 | + * WordPress Database Table prefix. |
| 110 | + * |
| 111 | + * You can have multiple installations in one database if you give each a unique |
| 112 | + * prefix. Only numbers, letters, and underscores please! |
| 113 | + */ |
| 114 | +\$table_prefix = 'wp_'; |
| 115 | +
|
| 116 | +/** |
| 117 | + * WordPress Localized Language, defaults to English. |
| 118 | + * |
| 119 | + * Change this to localize WordPress. A corresponding MO file for the chosen |
| 120 | + * language must be installed to wp-content/languages. For example, install |
| 121 | + * de.mo to wp-content/languages and set WPLANG to 'de' to enable German |
| 122 | + * language support. |
| 123 | + */ |
| 124 | +define ('WPLANG', ''); |
| 125 | +
|
| 126 | +/** |
| 127 | + * For developers: WordPress debugging mode. |
| 128 | + * |
| 129 | + * Change this to true to enable the display of notices during development. |
| 130 | + * It is strongly recommended that plugin and theme developers use WP_DEBUG |
| 131 | + * in their development environments. |
| 132 | + */ |
| 133 | +define('WP_DEBUG', false); |
| 134 | +
|
| 135 | +/* That's all, stop editing! Happy blogging. */ |
| 136 | +
|
| 137 | +/** Absolute path to the WordPress directory. */ |
| 138 | +if ( !defined('ABSPATH') ) |
| 139 | + define('ABSPATH', dirname(__FILE__) . '/'); |
| 140 | +
|
| 141 | +/** Sets up WordPress vars and included files. */ |
| 142 | +require_once(ABSPATH . 'wp-settings.php');" >> wp-config.php |
| 143 | + |
| 144 | +#Installation is now complete.. |
| 145 | + |
| 146 | +echo "Install completed successfully!" |
| 147 | +echo "Please visit http://$1/wp-admin/install.php to finalize your installation." |
| 148 | + |
0 commit comments