|
| 1 | +#!/bin/bash |
| 2 | +# Skripta za instaliranje WordPress na Ubuntu |
| 3 | +# |
| 4 | +# Kreiraj nova baza |
| 5 | +function create_new_db { |
| 6 | + echo -n "Enter password for the MySQL root account: " |
| 7 | + read -s rootpass |
| 8 | + echo "" |
| 9 | + Q00="CREATE DATABASE $dbname;" |
| 10 | + Q01="USE $dbname;" |
| 11 | + Q02="CREATE USER $dbuser@localhost IDENTIFIED BY '$dbpass';" |
| 12 | + Q03="GRANT ALL PRIVILEGES ON $dbname.* TO $dbuser@localhost;" |
| 13 | + Q04="FLUSH PRIVILEGES;" |
| 14 | + SQL0="${Q00}${Q01}${Q02}${Q03}${Q04}" |
| 15 | + mysql -v -u "root" -p$rootpass -e"$SQL0" |
| 16 | +} |
| 17 | +# Download na WordPress, modifikacija na wp-config.php i menuvanje permisii |
| 18 | +function install_wp { |
| 19 | + wget http://wordpress.org/latest.tar.gz |
| 20 | + tar xzvf latest.tar.gz |
| 21 | + cp -rf wordpress/** ./ |
| 22 | + rm -R wordpress |
| 23 | + cp wp-config-sample.php wp-config.php |
| 24 | + sed -i "s/database_name_here/$dbname/g" wp-config.php |
| 25 | + sed -i "s/username_here/$dbuser/g" wp-config.php |
| 26 | + sed -i "s/password_here/$dbpass/g" wp-config.php |
| 27 | + wget -O wp.keys https://api.wordpress.org/secret-key/1.1/salt/ |
| 28 | + sed -i '/#@-/r wp.keys' wp-config.php |
| 29 | + sed -i "/#@+/,/#@-/d" wp-config.php |
| 30 | + mkdir wp-content/uploads |
| 31 | + find . -type d -exec chmod 755 {} \; |
| 32 | + find . -type f -exec chmod 644 {} \; |
| 33 | + chown -R :www-data wp-content/uploads |
| 34 | + chown -R $USER: * |
| 35 | + chmod 640 wp-config.php |
| 36 | + rm -f latest.tar.gz |
| 37 | + rm -f wp-install.sh |
| 38 | + rm -f wp.keys |
| 39 | +} |
| 40 | +# Kreiranje na .htaccess |
| 41 | +function generate_htaccess { |
| 42 | + touch .htaccess |
| 43 | + chown :www-data .htaccess |
| 44 | + chmod 644 .htaccess |
| 45 | + bash -c "cat > .htaccess" << _EOF_ |
| 46 | +
|
| 47 | +<IfModule mod_rewrite.c> |
| 48 | +RewriteEngine On |
| 49 | +RewriteBase / |
| 50 | +RewriteRule ^wp-admin/includes/ - [F,L] |
| 51 | +RewriteRule !^wp-includes/ - [S=3] |
| 52 | +RewriteRule ^wp-includes/[^/]+\.php$ - [F,L] |
| 53 | +RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L] |
| 54 | +RewriteRule ^wp-includes/theme-compat/ - [F,L] |
| 55 | +</IfModule> |
| 56 | +
|
| 57 | +<IfModule mod_rewrite.c> |
| 58 | +RewriteEngine On |
| 59 | +RewriteBase / |
| 60 | +RewriteRule ^index\.php$ - [L] |
| 61 | +RewriteCond %{REQUEST_FILENAME} !-f |
| 62 | +RewriteCond %{REQUEST_FILENAME} !-d |
| 63 | +RewriteRule . /index.php [L] |
| 64 | +</IfModule> |
| 65 | +
|
| 66 | +<Files .htaccess> |
| 67 | +order allow,deny deny from all |
| 68 | +</Files> |
| 69 | +
|
| 70 | +<files wp-config.php> |
| 71 | +order allow,deny deny from all |
| 72 | +</files> |
| 73 | +
|
| 74 | +Options All -Indexes |
| 75 | +_EOF_ |
| 76 | +} |
| 77 | +# Kreiranje na robots.txt |
| 78 | +function generate_robots { |
| 79 | + touch robots.txt |
| 80 | + bash -c "cat > robots.txt" << _EOF_ |
| 81 | +# Sitemap: absolute url |
| 82 | +User-agent: * |
| 83 | +Disallow: /cgi-bin/ |
| 84 | +Disallow: /wp-admin/ |
| 85 | +Disallow: /wp-includes/ |
| 86 | +Disallow: /wp-content/plugins/ |
| 87 | +Disallow: /wp-content/cache/ |
| 88 | +Disallow: /wp-content/themes/ |
| 89 | +Disallow: /trackback/ |
| 90 | +Disallow: /comments/ |
| 91 | +Disallow: */trackback/ |
| 92 | +Disallow: */comments/ |
| 93 | +Disallow: wp-login.php |
| 94 | +Disallow: wp-signup.php |
| 95 | +_EOF_ |
| 96 | +} |
| 97 | + |
| 98 | +##### Prasanja za user |
| 99 | +echo "Please insert the information required for the WordPress installation." |
| 100 | +echo -n "WordPress database name: " |
| 101 | +read dbname |
| 102 | +echo -n "WordPress database user: " |
| 103 | +read dbuser |
| 104 | +echo -n "WordPress database password: " |
| 105 | +read -s dbpass |
| 106 | +echo "" |
| 107 | +echo -n "Install Wordpress? [Y/n] " |
| 108 | +read instwp |
| 109 | +echo -n "Create a NEW database with entered info? [Y/n] " |
| 110 | +read newdb |
| 111 | + |
| 112 | +##### Proces i proverka |
| 113 | +if [ "$newdb" = y ] || [ "$newdb" = Y ] |
| 114 | +then |
| 115 | + create_new_db |
| 116 | + install_wp |
| 117 | + generate_htaccess |
| 118 | + generate_robots |
| 119 | + download_plugins |
| 120 | +else |
| 121 | + if [ "$instwp" = y ] || [ "$instwp" = Y ] |
| 122 | + then |
| 123 | + install_wp |
| 124 | + generate_htaccess |
| 125 | + generate_robots |
| 126 | + fi |
| 127 | +fi |
| 128 | + |
| 129 | +echo -n "Now, go to your WordPress site to finish installation!" |
| 130 | +echo "" |
0 commit comments