Skip to content

Instantly share code, notes, and snippets.

@Syrup-tan
Created October 16, 2015 19:28
Show Gist options
  • Save Syrup-tan/c78f781c9b500b802fec to your computer and use it in GitHub Desktop.
Save Syrup-tan/c78f781c9b500b802fec to your computer and use it in GitHub Desktop.
#!/bin/sh
## Load std
. 'lib-std.sh'
transfer_accountlist() {}
transfer_homedir() {}
transfer_wpdb() {}
transfer_account() {}
transfer_loop() {
## Transfer the account list from the source server
if ! ACCOUNTLIST="$(
transfer_accountlist "$SOURCE_SERVER"
)"; then
throw 'FAIL: Failed to transfer source server account list';
else
## Loop through the source domains in the account list
IFS=$'\n';
for DOMAIN in $(
awk -F': ' '{print $1}' "$ACCOUNTLIST"
); do
## Get the source user from the domain
USER="$(
grep "^$DOMAIN" "$ACCOUNTLIST" | awk -F': ' '{print $2}'
)";
## Skip account transfer if the user is invalid
if [ -z "$USER" ]; then
log "WARN: ($DOMAIN/$USER) username is empty, skipping.";
SUCCESS=true;
## Skip account transfer if the homedir is non-existant
elif [ ! -d "/home/$USER" ]; then
log "WARN: ($DOMAIN/$USER) No such directory /home/$USER/, skipping.";
SUCCESS=true;
## Skip account transfer if the domain DNS is already on this server
elif account_live "$DOMAIN"; then
log "WARN: ($DOMAIN/$USER) already hosted by this server, skipping.";
SUCCESS=true;
## Begin transferring the account if the other checks pass
else
log "INFO: ($DOMAIN/$USER) beginning transfer...";
transfer_account "$USER";
SUCCESS="$?";
fi;
## Check the result of the transfer
if ! $SUCCESS; then
log "WARN: ($DOMAIN/$USER) non-zero result ($SUCCESS) occurred during transfer.";
fi;
done;
fi;
}
#!/bin/sh
## Load std
. 'lib-std.sh'
transfer_accountlist() {}
transfer_homedir() {}
transfer_wpdb() {}
transfer_account() {}
transfer_loop() {
## Transfer the account list from the source server
if ! ACCOUNTLIST="$(
transfer_accountlist "$SOURCE_SERVER"
)"; then
throw 'FAIL: Failed to transfer source server account list';
else
## Loop through the source domains in the account list
IFS=$'\n';
for DOMAIN in $(
awk -F': ' '{print $1}' "$ACCOUNTLIST"
); do
## Get the source user from the domain
USER="$(
grep "^$DOMAIN" "$ACCOUNTLIST" | awk -F': ' '{print $2}'
)";
## Begin checks for if we should transfer the account or not
if false; then :;
## Skip account transfer if the user is invalid
elif [ -z "$USER" ]; then
log "WARN: ($DOMAIN/$USER) username is empty, skipping.";
SUCCESS=true;
## Skip account transfer if the homedir is non-existant
elif [ ! -d "/home/$USER" ]; then
log "WARN: ($DOMAIN/$USER) No such directory /home/$USER/, skipping.";
SUCCESS=true;
## Skip account transfer if the domain DNS is already on this server
elif account_live "$DOMAIN"; then
log "WARN: ($DOMAIN/$USER) already hosted by this server, skipping.";
SUCCESS=true;
## Begin transferring the account if the other checks pass
else
log "INFO: ($DOMAIN/$USER) beginning transfer...";
transfer_account "$USER";
SUCCESS="$?";
fi;
## Check the result of the transfer
if ! $SUCCESS; then
log "WARN: ($DOMAIN/$USER) non-zero result ($SUCCESS) occurred during transfer.";
fi;
done;
fi;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment