-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathupdate-caddy.sh
More file actions
89 lines (72 loc) · 2.59 KB
/
Copy pathupdate-caddy.sh
File metadata and controls
89 lines (72 loc) · 2.59 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
#!/usr/bin/env bash
set -euo pipefail
REPO_URL="${GETFY_REPO_URL:-https://github.com/getfy-opensource/getfy.git}"
BRANCH="${GETFY_BRANCH:-main}"
INSTALL_DIR="${GETFY_DIR:-/opt/getfy}"
if [ "$(uname -s)" != "Linux" ]; then
echo "Este script é para Linux." >&2
exit 1
fi
SUDO=""
if [ "$(id -u)" -ne 0 ]; then
if command -v sudo >/dev/null 2>&1; then
SUDO="sudo"
else
echo "Rode como root ou instale sudo." >&2
exit 1
fi
fi
if ! command -v git >/dev/null 2>&1; then
echo "git não encontrado." >&2
exit 1
fi
if ! command -v docker >/dev/null 2>&1; then
echo "docker não encontrado." >&2
exit 1
fi
if [ ! -d "$INSTALL_DIR" ]; then
echo "Diretório não encontrado: $INSTALL_DIR" >&2
exit 1
fi
if [ ! -d "$INSTALL_DIR/.git" ]; then
echo "Atualização manual indisponível: diretório não é um repositório Git (.git ausente)." >&2
exit 1
fi
GIT_BASE=(git -c safe.directory="$INSTALL_DIR" -C "$INSTALL_DIR")
$SUDO "${GIT_BASE[@]}" remote set-url origin "$REPO_URL" >/dev/null 2>&1 || true
$SUDO "${GIT_BASE[@]}" merge --abort 2>/dev/null || true
$SUDO "${GIT_BASE[@]}" rebase --abort 2>/dev/null || true
$SUDO "${GIT_BASE[@]}" cherry-pick --abort 2>/dev/null || true
$SUDO "${GIT_BASE[@]}" fetch --all --prune
if $SUDO "${GIT_BASE[@]}" ls-files -u 2>/dev/null | grep -q .; then
echo "Aviso: conflitos pendentes no Git; alinhando com origin/$BRANCH..." >&2
$SUDO "${GIT_BASE[@]}" reset --hard "origin/$BRANCH"
fi
HAS_LOCAL_CHANGES=0
if [ -n "$($SUDO "${GIT_BASE[@]}" status --porcelain 2>/dev/null || true)" ]; then
HAS_LOCAL_CHANGES=1
$SUDO "${GIT_BASE[@]}" stash push -u -m "getfy-update" -- . \
':!.env' \
':!.docker' \
':!public/build' \
':!public/hot' \
>/dev/null 2>&1 || true
fi
echo "Descartando alterações locais em public/build..." >&2
$SUDO "${GIT_BASE[@]}" restore --worktree --staged public/build public/hot 2>/dev/null \
|| $SUDO "${GIT_BASE[@]}" checkout -f -- public/build public/hot 2>/dev/null \
|| true
$SUDO "${GIT_BASE[@]}" checkout -f -B "$BRANCH" "origin/$BRANCH"
$SUDO "${GIT_BASE[@]}" reset --hard "origin/$BRANCH"
if [ "$HAS_LOCAL_CHANGES" -eq 1 ]; then
if ! $SUDO "${GIT_BASE[@]}" stash pop >/dev/null 2>&1; then
echo "Aviso: não foi possível reaplicar alterações locais; mantendo origin/$BRANCH." >&2
$SUDO "${GIT_BASE[@]}" reset --hard "origin/$BRANCH"
$SUDO "${GIT_BASE[@]}" stash drop 2>/dev/null || true
fi
fi
cd "$INSTALL_DIR"
$SUDO rm -f public/hot 2>/dev/null || true
$SUDO env GETFY_COMPOSE_FILES="docker-compose.caddy.yml" sh docker/up.sh
echo ""
echo "Atualização concluída e stack (Caddy) reiniciado."