Skip to content

Commit c9f739a

Browse files
authored
Refactor: Komodo update logic (#4231)
1 parent 2ba1aaa commit c9f739a

File tree

1 file changed

+30
-36
lines changed

1 file changed

+30
-36
lines changed

ct/komodo.sh

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,36 @@ color
2020
catch_errors
2121

2222
function update_script() {
23-
header_info
24-
check_container_storage
25-
check_container_resources
26-
if [[ ! -d /opt/komodo ]]; then
27-
msg_error "No ${APP} Installation Found!"
28-
exit
29-
fi
30-
msg_info "Updating ${APP}"
31-
COMPOSE_FILE=""
32-
for file in /opt/komodo/*.compose.yaml; do
33-
if [[ "$file" != "compose.env" ]]; then
34-
COMPOSE_FILE="${file#/opt/komodo/}"
35-
break
36-
fi
37-
done
38-
39-
if [[ -z "$COMPOSE_FILE" ]]; then
40-
msg_error "No valid compose file found in /opt/komodo!"
41-
exit 1
42-
fi
43-
44-
BACKUP_FILE="${COMPOSE_FILE}.bak_$(date +%Y%m%d_%H%M%S)"
45-
mv "/opt/komodo/$COMPOSE_FILE" "/opt/komodo/$BACKUP_FILE" || {
46-
msg_error "Failed to create backup of $COMPOSE_FILE!"
47-
exit 1
48-
}
49-
50-
GITHUB_URL="https://raw.githubusercontent.com/moghtech/komodo/main/compose/${COMPOSE_FILE}"
51-
if ! curl -fsSL "$GITHUB_URL" -o "/opt/komodo/${COMPOSE_FILE}"; then
52-
msg_error "Failed to download ${COMPOSE_FILE} from GitHub!"
53-
mv "/opt/komodo/${BACKUP_FILE}" "/opt/komodo/${COMPOSE_FILE}"
54-
exit 1
55-
fi
56-
57-
$STD docker compose -p komodo -f "/opt/komodo/$COMPOSE_FILE" --env-file /opt/komodo/compose.env up -d
58-
msg_ok "Updated ${APP}"
23+
header_info
24+
check_container_storage
25+
check_container_resources
26+
27+
[[ -d /opt/komodo ]] || {
28+
msg_error "No ${APP} Installation Found!"
29+
exit 1
30+
}
31+
32+
msg_info "Updating ${APP}"
33+
COMPOSE_FILE=$(find /opt/komodo -maxdepth 1 -type f -name '*.compose.yaml' ! -name 'compose.env' | head -n1)
34+
if [[ -z "$COMPOSE_FILE" ]]; then
35+
msg_error "No valid compose file found in /opt/komodo!"
36+
exit 1
37+
fi
38+
COMPOSE_BASENAME=$(basename "$COMPOSE_FILE")
39+
BACKUP_FILE="/opt/komodo/${COMPOSE_BASENAME}.bak_$(date +%Y%m%d_%H%M%S)"
40+
cp "$COMPOSE_FILE" "$BACKUP_FILE" || {
41+
msg_error "Failed to create backup of ${COMPOSE_BASENAME}!"
42+
exit 1
43+
}
44+
GITHUB_URL="https://raw.githubusercontent.com/moghtech/komodo/main/compose/${COMPOSE_BASENAME}"
45+
if ! curl -fsSL "$GITHUB_URL" -o "$COMPOSE_FILE"; then
46+
msg_error "Failed to download ${COMPOSE_BASENAME} from GitHub!"
47+
mv "$BACKUP_FILE" "$COMPOSE_FILE"
48+
exit 1
49+
fi
50+
$STD docker compose -p komodo -f "$COMPOSE_FILE" --env-file /opt/komodo/compose.env up -d
51+
msg_ok "Updated ${APP}"
52+
exit
5953
}
6054

6155
start

0 commit comments

Comments
 (0)