-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathupdate.sh
More file actions
75 lines (62 loc) · 2.23 KB
/
update.sh
File metadata and controls
75 lines (62 loc) · 2.23 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
#!/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
HAS_LOCAL_CHANGES=0
if [ -n "$($SUDO "${GIT_BASE[@]}" status --porcelain 2>/dev/null || true)" ]; then
HAS_LOCAL_CHANGES=1
# IMPORTANT:
# Do not stash runtime/config files (they are untracked by design).
# If we stash -u and stash pop fails, the app may boot with a regenerated .env/.docker state,
# causing forced logout and "looks like password changed" reports.
$SUDO "${GIT_BASE[@]}" stash push -u -m "getfy-update" -- . \
':!.env' \
':!.docker' \
>/dev/null 2>&1 || true
fi
$SUDO "${GIT_BASE[@]}" fetch --all --prune
$SUDO "${GIT_BASE[@]}" checkout -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: havia alterações locais. O script fez stash, mas não conseguiu reaplicar automaticamente." >&2
echo "Para ver e resolver manualmente: cd \"$INSTALL_DIR\" && git stash list && git stash show -p" >&2
fi
fi
cd "$INSTALL_DIR"
$SUDO sh docker/up.sh
echo ""
echo "Atualização concluída e stack reiniciado."
echo "Dica: para conferir limites de upload do PHP no container, na pasta da instalação (ex.: cd \"$INSTALL_DIR\"): sh docker/check-php-upload-limits.sh"