From 20cdb38810586a4685138953604fa6c07ceb5e9c Mon Sep 17 00:00:00 2001 From: hoelee Date: Wed, 17 Jun 2026 09:00:00 +0800 Subject: [PATCH] feat(shell-sync): sync_account() part 1/3 --- platform/shell-sync/sync.sh | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/platform/shell-sync/sync.sh b/platform/shell-sync/sync.sh index d43daaa5..9f6e5502 100644 --- a/platform/shell-sync/sync.sh +++ b/platform/shell-sync/sync.sh @@ -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" +