Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Generate private public ssh-keys
- if [ ! -f "$HOME/.ssh/id_rsa" ] && [ ! -f "$HOME/.ssh/id_rsa.pub" ]; then
- ssh-keygen -b 4096
- fi
- read -p "Enter your ssh host:" ssh_host
- read -p "Enter your ssh username:" ssh_user
- read -p "Enter your remote ssh port:" ssh_port
- # REMOTE SSH
- if [ -z "$ssh_user" ]; then
- echo -e "Config: SSH Username missing"
- echo $ssh_user
- exit
- fi
- if [ -z "$ssh_host" ]; then
- echo -e "Config: SSH Host is missing"
- exit
- fi
- if [ -z "$ssh_port" ]; then
- echo -e "Config: SSH Port missing"
- exit
- fi
- ssh-copy-id $ssh_user@$ssh_host -p $ssh_port -i "$HOME/.ssh/id_rsa" &>/dev/null
- # REMOTE DATABASE
- read -p "Enter path for wp-config.php:" wp_config_path
- # INIT
- db_details="cat $wp_config_path/wp-config.php"
- scp -P $ssh_port -r $ssh_user@$ssh_host:"$wp_config_path/*" .
- # Might be dangerous if file contains malicious input in the values?
- eval $(awk -F "[()']" '/^define(/{printf "%s='''%s'''n", $3, $5;}' < wp-config.php | grep DB_*)
- if [ -z "$DB_USER" ]; then
- echo -e "Config: RDB user missing"
- exit
- fi
- if [ -z "$DB_PASSWORD" ]; then
- echo -e "Config: RDB password missing"
- exit
- fi
- if [ -z "$DB_NAME" ]; then
- echo -e "Config: RDB name missing"
- exit
- fi
- dump="mysqldump -u $DB_USER --password='$DB_PASSWORD' $DB_NAME"
- read -p "Enter your LOCAL database user:" local_db_user
- read -p "Enter your LOCAL database name:" local_db_name
- read -s -p "Enter your local database password:" local_db_password
- printf "