Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- domain="$1" && test -z "$domain" && exit 2
- environment() {
- read -sp "Please enter the app DB root password: " dbrootp_1 && echo
- read -sp "Please enter the app DB root password again:" dbrootp_2 && echo
- if [ "$dbrootp_1" != "$dbrootp_2" ]; then echo "Values unmatched. Please try again." && exit 2 fi
- read -sp "Please enter the app DB user password: " dbuserp_1 && echo
- read -sp "Please enter the app DB user password again:" dbuserp_2 && echo
- if [ "$dbuserp_1" != "$dbuserp_2" ]; then echo "Values unmatched. Please try again." && exit 2 fi
- }
- environment
- wordpress() {
- rm -rf "$drt"/"$domain"/ 2>/dev/null
- wp core download --path="$drt"/"$domain"/ --allow-root
- wp config create --path="$drt"/"$domain"/ --dbname="$domain" --dbuser="$domain" --dbpass="$dbuserp" --dbhost="localhost" --allow-root
- }
- wordpress
- nginx() {
- rm "$s_a/$domain.conf" 2>/dev/null
- rm "$s_e/$domain.conf" 2>/dev/null
- cat <<-EOF > "$s_a/$domain.conf"
- server {
- root ${drt}/${domain}/;
- server_name ${domain} www.${domain};
- location ~* .(jpg|jpeg|png|gif|ico|css|js|ttf|woff|pdf)$ {expires 365d;}
- location "/wp-login.php" {access_log "/var/log/httpd/wordpress-logins.log";}
- }
- EOF
- ln -sf "$s_a"/"$domain".conf "$s_e"
- rse
- }
- nginx
- certbot() {
- certbot --nginx -d "$domain" -d www."$domain"
- rse
- }
- certbot
- database() {
- cat <<-EOF | mysql -u root -p"$dbrootp_1"
- DROP USER IF EXISTS "$domain"@"localhost";
- DROP database IF EXISTS "$domain";
- CREATE USER "$domain"@"localhost" IDENTIFIED BY "$dbuserp_1";
- CREATE DATABASE "$domain";
- GRANT ALL PRIVILEGES ON "$domain".* TO "$domain"@"localhost";
- EOF
- }
- database
- finalize() {
- echo "Change http to http2 in your Nginx app conf and run rse"
- }
- finalize
- drt="/var/www/html"
- s_a="etc/nginx/sites-available"
- s_e="etc/nginx/sites-enabled"
- wordpress() {
- local drt="$1"
- local domain="$2"
- local dbpass="$3"
- # should do more checking here, this is the bare minimum.
- # it avoids running `rm -rf /` if both $drt and $domain
- # are empty, and running `rm -rf "$drt/"` if $domain is empty.
- [ -z "$drt" ] && error 1 '$drt is empty. aborting!'
- [ -z "$domain" ] && error 1 '$domain is empty. aborting!'
- [ -z "$dbpass" ] && error 1 '$dbpass is empty. aborting!'
- # should check exit status of each command run here and take
- # appropriate action on any failures. Figure out what you want
- # to happen if any of the following fail and implement it.
- rm -rf "$drt"/"$domain"/ 2>/dev/null
- wp core download --path="$drt"/"$domain"/ --allow-root
- wp config create --path="$drt"/"$domain"/ --dbname="$domain"
- --dbuser="$domain" --dbpass="$dbpass" --dbhost=localhost
- --allow-root
- }
- error() {
- local ec msg
- ec="$1" ; shift
- msg="$*"
- [ -n "$msg" ] && echo "$msg" >&2
- # don't exit if $ec==0 - just return after printing a warning to stderr
- [ "$ec" != 0 ] && exit "$ec"
- }
- function1 () { ... ; }
- function2 () { ... ; }
- function3 () { ... ; }
- function4 () { ... ; }
- main () {
- function1
- function2
- function3
- function4
- }
- main
- case "$var" in
- 1) function1 ;;
- 2) function2 ;;
- 3) function3 ;;
- 4) function4 ;;
- *) error 1 'Unknown case' ;;
- esac
- if [ "$dbrootp_1" != "$dbrootp_2" ]; then echo "Values unmatched. Please try again." && exit 2 fi
- read -sp "Please enter the app DB root password: " dbrootp_1 && echo
- readpw() {
- local pw1 pw2 label=$1
- while :; do
- read -sp "Please enter the $label password: " pw1 && echo
- read -sp "Please enter the $label password again: " pw2 && echo
- [ "$pw1" = "$pw2" ] && break
- echo "The values don't match. Please try again."
- done
- REPLY=$pw1
- }
- readpw "app DB user"
- dbuserpw=$REPLY
- readpw "app DB root"
- dbrootpw=$REPLY
Add Comment
Please, Sign In to add comment