|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +domain=dominioC.org |
| 4 | + |
| 5 | +if [ "$(id -u)" != "0" ]; then |
| 6 | + echo "This script must be run as root" 1>&2 |
| 7 | + exit 1 |
| 8 | +fi |
| 9 | + |
| 10 | + if [[ -e ./conf/config ]];then |
| 11 | + source ./conf/config; |
| 12 | + else |
| 13 | + iferror "First you need configure parameters" |
| 14 | + fi |
| 15 | + |
| 16 | + |
| 17 | +# function: read_root_path |
| 18 | +# Read root path from Nginx server |
| 19 | + |
| 20 | +function read_root_path { |
| 21 | + if [[ -e /etc/sites-available/$domain.conf ]];then |
| 22 | + wp_path=$(grep -E "root.*$domain" /etc/sites-available/$domain.conf \ |
| 23 | + | awk -F' ' '{print substr($2, 1, length($2)-1)}'); |
| 24 | + else |
| 25 | + iferror "Site is not available"; |
| 26 | + fi |
| 27 | +} |
| 28 | + |
| 29 | +# function: get_config_parameters |
| 30 | +# Read wp-conging.php to get parameters needed to uninstall |
| 31 | + |
| 32 | +function get_config_parameters { |
| 33 | + wp_cnf=$wp_path/wp-config.php |
| 34 | + |
| 35 | + db_name=$(grep "DB_NAME" $wp_cnf | awk -F"'" '{print $4}') |
| 36 | + db_user=$(grep "DB_USER" $wp_cnf | awk -F"'" '{print $4}') |
| 37 | + db_password=$(grep "DB_PASSWORD" $wp_cnf | awk -F"'" '{print $4}') |
| 38 | + db_host=$(grep "DB_PASSWORD" $wp_cnf | awk -F"'" '{print $4}') |
| 39 | + if [ $db_host -eq '' ]; then |
| 40 | + db_host=localhost |
| 41 | +} |
| 42 | + |
| 43 | +# function: mysql_remove_database |
| 44 | +# Remove database from mysql |
| 45 | + |
| 46 | +function mysql_remove_database { |
| 47 | + SQL="drop database if exists $db_name"; |
| 48 | + mysql -u$db_user -p$db_password -e $SQL || iferror "Database not removed"; |
| 49 | +} |
| 50 | + |
| 51 | +# function: remove_root_path |
| 52 | +# remove path of Wordpress installation |
| 53 | + |
| 54 | +function remove_root_path { |
| 55 | + if [[ -d $wp_path ]]; then |
| 56 | + rm -rf $wp_path; |
| 57 | + else |
| 58 | + iferror "Root path does not exists" |
| 59 | + fi |
| 60 | +} |
| 61 | + |
| 62 | +# function: nginx_disable_site |
| 63 | +# disable site from sites-enabled |
| 64 | + |
| 65 | +function nginx_disable_site { |
| 66 | + if [[ -e /etc/nginx/sites-enabled/$domain.conf]]; then |
| 67 | + rm -f /etc/nginx/sites-enabled/$domain.conf; |
| 68 | + else |
| 69 | + iferror "Site is not enabled" |
| 70 | + fi |
| 71 | +} |
| 72 | + |
| 73 | +#function nginx_remove_site |
| 74 | +# remove server from sites-available |
| 75 | + |
| 76 | +function nginx_remove_site { |
| 77 | + if [[ -e /etc/nginx/sites-available/$domain.conf]]; then |
| 78 | + rm -f /etc/nginx/sites-available/$domain.conf; |
| 79 | + else |
| 80 | + iferror "Site is not available " |
| 81 | + fi |
| 82 | +} |
| 83 | + |
| 84 | +function start { |
| 85 | + read_root_path \ |
| 86 | + && get_config_parameters \ |
| 87 | + && mysql_remove_database \ |
| 88 | + && remove_root_path \ |
| 89 | + && nginx_disable_site \ |
| 90 | + && nginx_remove_site |
| 91 | +} |
| 92 | + |
| 93 | +start |
0 commit comments