feat(shell-sync): sync_account() part 1/3
This commit is contained in:
1 parent
b7ab56c9ca
commit
20cdb38810
1 file changed
+44
@@ -144,3 +144,47 @@ source_oauth_provider() {
|
||||
esac
|
||||
}
|
||||
|
||||
sync_account() {
|
||||
local i="$1"
|
||||
local src_host="$(get_var "ACCOUNT_${i}_SOURCE_HOST")"
|
||||
local src_user="$(get_var "ACCOUNT_${i}_SOURCE_USER")"
|
||||
local src_auth="$(get_var "ACCOUNT_${i}_SOURCE_AUTH")"
|
||||
local src_pass="$(get_var "ACCOUNT_${i}_SOURCE_PASS")"
|
||||
local src_token="$(get_var "ACCOUNT_${i}_SOURCE_TOKEN")"
|
||||
local src_provider="$(get_var "ACCOUNT_${i}_SOURCE_PROVIDER")"
|
||||
local dest_host="$(get_var "ACCOUNT_${i}_DEST_HOST")"
|
||||
local dest_user="$(get_var "ACCOUNT_${i}_DEST_USER")"
|
||||
local dest_pass="$(get_var "ACCOUNT_${i}_DEST_PASS")"
|
||||
local delete_opt="$(get_var "ACCOUNT_${i}_DELETE")"
|
||||
local dry_run="$(get_var "ACCOUNT_${i}_DRY_RUN")"
|
||||
local extra_opts="$(get_var "ACCOUNT_${i}_EXTRA_OPTS")"
|
||||
local logfile="${LOG_DIR}/account${i}.log"
|
||||
local pidfile="${PID_DIR}/account${i}.pid"
|
||||
local oauth_provider
|
||||
local oauth_log
|
||||
local oauth_authorization_detected=false
|
||||
local sync_exit
|
||||
local -a args
|
||||
|
||||
SYNC_ACCOUNT_RESULT="skipped"
|
||||
if [ -z "$src_host" ] && [ -z "$dest_host" ]; then
|
||||
log "Account $i: SKIP (not configured)"
|
||||
return 0
|
||||
fi
|
||||
if [ -z "$src_host" ] || [ -z "$src_user" ] || [ -z "$dest_host" ] || [ -z "$dest_user" ] || [ -z "$dest_pass" ]; then
|
||||
log "Account $i: CONFIGURATION FAILED (source host/user and destination host/user/password are required)"
|
||||
SYNC_ACCOUNT_RESULT="failure"
|
||||
echo "$(date +%s)" > "${LOG_DIR}/account${i}.last_failure"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -f "$pidfile" ]; then
|
||||
local old_pid
|
||||
old_pid="$(cat "$pidfile")"
|
||||
if kill -0 "$old_pid" 2>/dev/null; then
|
||||
log "Account $i: SKIP (already running, PID $old_pid)"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
echo $$ > "$pidfile"
|
||||
|
||||
Reference in new issue
Block a user