Skip to content

Commit 0d61c0f

Browse files
committed
Fix missing functions on update script and introducing --reset flag for reset the entire configurazion
1 parent b3824e5 commit 0d61c0f

File tree

1 file changed

+52
-16
lines changed

1 file changed

+52
-16
lines changed

scripts/update-script.sh

+52-16
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,54 @@ log_error() {
4444
}
4545

4646
usage() {
47-
echo "Usage: $0 [fota|ota] [--dry-run]"
47+
echo "Usage: $0 [fota|ota] [--dry-run] [--reset]"
4848
exit 1
4949
}
5050

51-
DRY_RUN=0
52-
53-
if [ "$#" -eq 0 ]; then
54-
usage
55-
fi
56-
57-
MODE="$1"
51+
version_greater() {
52+
printf '%s\n%s\n' "$1" "$2" | sort -V | head -n 1 | grep -q "^$2$"
53+
}
5854

59-
if [ "$#" -eq 2 ]; then
60-
if [ "$2" = "--dry-run" ]; then
61-
DRY_RUN=1
62-
log_info "Dry-run mode activated. No destructive operations will be executed."
55+
check_and_update_compat_version() {
56+
REQUIRED_VERSION="$1"
57+
CURRENT_VERSION=$(uci get system.@system[0].compat_version 2>/dev/null || echo "0.0")
58+
59+
if version_greater "$REQUIRED_VERSION" "$CURRENT_VERSION"; then
60+
log_info "Updating compat_version from $CURRENT_VERSION to $REQUIRED_VERSION..."
61+
uci set system.@system[0].compat_version="$REQUIRED_VERSION"
62+
uci commit system
63+
log_success "compat_version updated to $REQUIRED_VERSION."
6364
else
64-
usage
65+
log_info "Current compat_version ($CURRENT_VERSION) is already compatible or greater."
6566
fi
66-
elif [ "$#" -gt 2 ]; then
67+
}
68+
69+
MODE=""
70+
DRY_RUN=0
71+
RESET=0
72+
73+
while [ "$#" -gt 0 ]; do
74+
case "$1" in
75+
fota|ota)
76+
if [ -n "$MODE" ]; then
77+
usage
78+
fi
79+
MODE="$1"
80+
;;
81+
--dry-run)
82+
DRY_RUN=1
83+
;;
84+
--reset)
85+
RESET=1
86+
;;
87+
*)
88+
usage
89+
;;
90+
esac
91+
shift
92+
done
93+
94+
if [ -z "$MODE" ]; then
6795
usage
6896
fi
6997

@@ -144,7 +172,7 @@ if [ "$MODE" = "fota" ]; then
144172
prefix="\033[1;36mDownloading $filename...\033[0m"
145173
asset_url=$(echo "$RELEASES_JSON" | jq -r ".[$index].assets[] | select(.name==\"$filename\") | .browser_download_url")
146174
[ -z "$asset_url" ] || [ "$asset_url" = "null" ] && { log_error "Asset $filename not found for release $RELEASE_TAG."; exit 1; }
147-
175+
148176
if [ "$DRY_RUN" -eq 1 ]; then
149177
printf "%b\n" "$prefix"
150178
log_info "DRY-RUN: Simulated download of $filename from $asset_url"
@@ -247,13 +275,21 @@ if echo "$SYSUPGRADE_LOG" | grep -q "The device is supported, but the config is
247275
fi
248276
fi
249277

278+
if [ "$RESET" -eq 1 ]; then
279+
log_info "Starting sysupgrade without preserving configuration..."
280+
sysupgrade_cmd="sysupgrade -n"
281+
else
282+
log_info "Starting sysupgrade with configuration preserved..."
283+
sysupgrade_cmd="sysupgrade"
284+
fi
285+
250286
log_info "Starting sysupgrade with file $SYSUPGRADE_IMG..."
251287
sleep 2
252288
if [ "$DRY_RUN" -eq 1 ]; then
253289
log_info "DRY-RUN: Simulated sysupgrade execution with $SYSUPGRADE_IMG."
254290
SYSUPGRADE_OUTPUT="Simulated sysupgrade - closing"
255291
else
256-
SYSUPGRADE_OUTPUT=$(sysupgrade "$SYSUPGRADE_IMG" 2>&1)
292+
SYSUPGRADE_OUTPUT=$($sysupgrade_cmd "$SYSUPGRADE_IMG" 2>&1)
257293
fi
258294

259295
if echo "$SYSUPGRADE_OUTPUT" | grep -iq "closing"; then

0 commit comments

Comments
 (0)