Repository navigation
Expand file tree
/
Copy pathpush_live.sh
More file actions
executable file
·136 lines (128 loc) · 4.82 KB
/
Copy pathpush_live.sh
File metadata and controls
executable file
·136 lines (128 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env bash
# push_live.sh — Push edits from the local source/ tree to the live CA
# install on Unraid via scp. No build / installpkg cycle, no SMB share.
# Use this for iterative edit-and-refresh during development; use
# install_pkg.sh when you want to exercise the real install flow.
#
# Usage:
# ./push_live.sh # full sync (everything in source/.../community.applications)
# ./push_live.sh source/.../Apps.page # one file
# ./push_live.sh source/.../include/exec.php source/.../skins/Narrow/skin.php # several files
# ./push_live.sh source/.../include/ # whole subdirectory
#
# Arguments must live inside ./source/community.applications/ — the
# corresponding remote path is derived by stripping that prefix and
# resolving against the live install root (/usr/local/emhttp/plugins/
# community.applications/).
#
# SSH target resolution (no hostname ever lives in tracked source):
# 1. UNRAID_HOST env var, if set
# 2. ./.unraid-host file at the repo root (single line "user@host")
# Neither -> the script exits with a setup hint.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
HOST_FILE="$ROOT/.unraid-host"
SOURCE_ROOT="$ROOT/source/community.applications"
LIVE_PREFIX="/usr/local/emhttp/plugins/community.applications"
# Resolve the SSH target.
if [ -n "${UNRAID_HOST:-}" ]; then
: # env var wins
elif [ -r "$HOST_FILE" ]; then
UNRAID_HOST="$(sed -n '/^[[:space:]]*#/d; /^[[:space:]]*$/d; p; q' "$HOST_FILE" | tr -d '[:space:]')"
fi
if [ -z "${UNRAID_HOST:-}" ]; then
cat >&2 <<-EOMSG
No Unraid host configured.
Set it one of two ways:
- export UNRAID_HOST=user@host (per-shell, not persisted)
- echo user@host > $HOST_FILE (per-clone, gitignored)
EOMSG
exit 1
fi
if [ ! -d "$SOURCE_ROOT$LIVE_PREFIX" ]; then
echo "Source tree missing at $SOURCE_ROOT$LIVE_PREFIX — run ./copy_to_git.sh first." >&2
exit 1
fi
# No args -> full sync of the entire plugin dir.
if [ "$#" -eq 0 ]; then
echo "==> Full sync source$LIVE_PREFIX/ -> $UNRAID_HOST:$LIVE_PREFIX/"
# Normalize local perms before sending so the on-disk git tree and the
# live install both end up at 0755. Keeps `git status` / future PR diffs
# free of permission-only noise.
chmod -R 0755 "$SOURCE_ROOT$LIVE_PREFIX"
# Wipe the remote install dir first so files that existed in a previous
# version but no longer exist in source/ don't linger (scp only writes
# what's in the source — it doesn't prune the destination). Safety-gate
# the rm to paths under /usr/local/emhttp/plugins/ in case LIVE_PREFIX
# ever gets mis-set, so a typo can't `rm -rf /` the box.
echo "==> Wiping remote $LIVE_PREFIX (clears stragglers from prior versions)"
ssh "$UNRAID_HOST" sh -s -- "$LIVE_PREFIX" <<-'EOF'
set -e
case "$1" in
/usr/local/emhttp/plugins/*) ;;
*) echo "Refusing to rm -rf $1 — not under /usr/local/emhttp/plugins/" >&2; exit 1 ;;
esac
rm -rf "$1"
mkdir -p "$1"
EOF
scp -rq "$SOURCE_ROOT$LIVE_PREFIX/." "$UNRAID_HOST:$LIVE_PREFIX/"
# Mirror the chmod on the remote too — belt-and-braces against scp/umask
# combinations that don't carry the source mode across.
ssh "$UNRAID_HOST" sh -s -- "$LIVE_PREFIX" <<-'EOF'
set -e
chmod -R 0755 "$1"
EOF
echo "==> Done."
exit 0
fi
# Args -> push specific files / dirs. Map each path to its mirror under
# /usr/local/emhttp/plugins/community.applications/ and scp it over.
for arg in "$@"; do
if [ ! -e "$arg" ]; then
echo "Path not found: $arg" >&2
exit 1
fi
# Absolute path of arg (portable: dirname + pwd -P + basename).
abs="$(cd -- "$(dirname -- "$arg")" && pwd -P)/$(basename -- "$arg")"
# Strip the source root to get the relative-from-/ portion.
rel="${abs#"$SOURCE_ROOT"/}"
if [ "$rel" = "$abs" ]; then
echo "Not inside $SOURCE_ROOT: $arg" >&2
exit 1
fi
remote="/$rel"
# Force 0755 on the local path before sending — keeps the git tree and
# the live install consistent at 0755 so future copy_to_git / PR diffs
# don't surface permission-only churn. Recursive for dirs, single chmod
# for files.
if [ -d "$abs" ]; then
chmod -R 0755 "$abs"
echo "==> $arg/ -> $UNRAID_HOST:$remote/"
# Trailing /. on src + trailing / on dst copies *contents* of the
# directory into the existing remote directory.
# Pass $remote as a positional arg so the remote shell never re-parses it.
ssh "$UNRAID_HOST" sh -s -- "$remote" <<-'EOF'
set -e
mkdir -p "$1"
EOF
scp -rq "$abs/." "$UNRAID_HOST:$remote/"
# Mirror the chmod remotely.
ssh "$UNRAID_HOST" sh -s -- "$remote" <<-'EOF'
set -e
chmod -R 0755 "$1"
EOF
else
chmod 0755 "$abs"
echo "==> $arg -> $UNRAID_HOST:$remote"
ssh "$UNRAID_HOST" sh -s -- "$(dirname "$remote")" <<-'EOF'
set -e
mkdir -p "$1"
EOF
scp -q "$abs" "$UNRAID_HOST:$remote"
ssh "$UNRAID_HOST" sh -s -- "$remote" <<-'EOF'
set -e
chmod 0755 "$1"
EOF
fi
done
echo "==> Done."