-
-
Notifications
You must be signed in to change notification settings - Fork 501
/
dietpi-update
executable file
·561 lines (439 loc) · 20.8 KB
/
dietpi-update
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
#!/bin/bash
{
#////////////////////////////////////
# DietPi Update
#
#////////////////////////////////////
# Created by Daniel Knight / [email protected] / dietpi.com
#
#////////////////////////////////////
#
# Info:
# - Location: /boot/dietpi/dietpi-update
# - Updates DietPi from a chosen GitHub repository
# - Uses pre-patches for patches that need to be done prior to APT calls or DietPi code updates
# - Uses patches for incremental patching after APT calls and DietPi code updates
#
# Usage:
# - dietpi-update = Check for DietPi update and if available open interactive menu
# Else, if CONFIG_CHECK_APT_UPDATES=[12] is set, check for APT updates and store results to /run/dietpi/.apt_updates to be used by DietPi-Banner
# - dietpi-update 1 = Check for DietPi update and in case apply noninteractively
# Else, if CONFIG_CHECK_APT_UPDATES=2 is set, check for and apply APT updates noninteractively
# - dietpi-update 2 = Check for DietPi update and in case store result to /run/dietpi/.update_available to be used by DietPi-Banner
# Else, if CONFIG_CHECK_APT_UPDATES=[12] is set, check for APT updates and store results to /run/dietpi/.apt_updates to be used by DietPi-Banner
# - dietpi-update -1 = Like "1" but internally reduce subversion by 1 to reapply the last update, e.g. to apply latest dev branch changes
#////////////////////////////////////
# Import DietPi-Globals --------------------------------------------------------------
G_LIVE_PATCH_STATUS=() # Reset potentially exported array, to be freshly sourced via DietPi-Globals
. /boot/dietpi/func/dietpi-globals
readonly G_PROGRAM_NAME='DietPi-Update'
G_CHECK_ROOT_USER
G_CHECK_ROOTFS_RW
G_INIT
# Import DietPi-Globals --------------------------------------------------------------
# Grab input
[[ $1 =~ ^(-?1|2)$ ]] && INPUT=$1 || INPUT=0
# Prefix G_DIETPI-NOTIFY 3 header text with "Phase" instead of "Mode" when not checking for available updates only
[[ $INPUT == 2 ]] || G_NOTIFY_3_MODE='Phase'
#/////////////////////////////////////////////////////////////////////////////////////
# UPDATE Vars
#/////////////////////////////////////////////////////////////////////////////////////
readonly FP_LOG='/var/tmp/dietpi/logs/dietpi-update.log'
# Git repo to update from
GITOWNER_TARGET=$(sed -n '/^[[:blank:]]*DEV_GITOWNER=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
GITOWNER_TARGET=${GITOWNER_TARGET:-MichaIng}
GITBRANCH_TARGET=$(sed -n '/^[[:blank:]]*DEV_GITBRANCH=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
GITBRANCH_TARGET=${GITBRANCH_TARGET:-master}
# Remote version variables
# - Available DietPi version
G_REMOTE_VERSION_CORE=
G_REMOTE_VERSION_SUB=
G_REMOTE_VERSION_RC=
# - Minimum DietPi version to allow update
G_MIN_VERSION_CORE=
G_MIN_VERSION_SUB=
# - Alternative Git branch to automatically migrate to when version is too low
G_OLD_VERSION_BRANCH=
# - Minimum Debian version to allow update
G_MIN_DEBIAN=
# - Alternative Git branch to automatically migrate to when Debian version is too low
G_OLD_DEBIAN_BRANCH=
# - Live patch arrays
G_LIVE_PATCH_DESC=()
G_LIVE_PATCH_COND=()
G_LIVE_PATCH=()
# Version info to print to console
INFO_CURRENT_VERSION=
INFO_REMOTE_VERSION=
INFO_VERSIONS_UPDATE(){
INFO_CURRENT_VERSION="Current version : v$G_DIETPI_VERSION_CORE.$G_DIETPI_VERSION_SUB.$G_DIETPI_VERSION_RC"
INFO_REMOTE_VERSION="Latest version : v$G_REMOTE_VERSION_CORE.$G_REMOTE_VERSION_SUB.$G_REMOTE_VERSION_RC"
# Show Git repo, when it changed
[[ $G_GITBRANCH != "$GITBRANCH_TARGET" || $G_GITOWNER != "$GITOWNER_TARGET" ]] || return
INFO_CURRENT_VERSION+=" (branch: $G_GITOWNER/$G_GITBRANCH)"
INFO_REMOTE_VERSION+=" (branch: $GITOWNER_TARGET/$GITBRANCH_TARGET)"
}
Get_Remote_Version(){
local url="https://raw.githubusercontent.com/$GITOWNER_TARGET/DietPi/$GITBRANCH_TARGET/.update/version"
G_DIETPI-NOTIFY 2 "Getting latest version from: $url"
if curl -sSfLO "$url"; then
# Source file
# shellcheck disable=SC1091
. version
# Check if remote version consists of valid integers
if disable_error=1 G_CHECK_VALIDINT "$G_REMOTE_VERSION_CORE" &&
disable_error=1 G_CHECK_VALIDINT "$G_REMOTE_VERSION_SUB" &&
disable_error=1 G_CHECK_VALIDINT "$G_REMOTE_VERSION_RC"; then
G_DIETPI-NOTIFY 0 "Got valid latest version: $G_REMOTE_VERSION_CORE.$G_REMOTE_VERSION_SUB.$G_REMOTE_VERSION_RC"
return 0
else
G_DIETPI-NOTIFY 1 "Got invalid latest version: ${G_REMOTE_VERSION_CORE:-NULL}.${G_REMOTE_VERSION_SUB:-NULL}.${G_REMOTE_VERSION_RC:-NULL}"
fi
else
G_DIETPI-NOTIFY 1 'Unable to get latest version.'
fi
# No valid update server response
G_DIETPI-NOTIFY 2 'Please check the target Git repository and your network connection, then rerun dietpi-update.'
G_DIETPI-NOTIFY 2 'If this error persists, please report at: https://github.com/MichaIng/DietPi/issues'
return 1
}
Apply_1st_Run_Update_Success(){ [[ $G_DIETPI_INSTALL_STAGE == [12] ]] || { G_DIETPI_INSTALL_STAGE=1; G_EXEC eval 'echo 1 > /boot/dietpi/.install_stage'; } }
Check_Git_Migration()
{
# Automatically migrate to alternative branch if Debian or DietPi version is too low.
if (( $G_DISTRO && $G_DISTRO < $G_MIN_DEBIAN ))
then
G_DIETPI-NOTIFY 2 "Your Debian version is too low to update to the current branch: $G_DISTRO_NAME ($G_DISTRO)"
G_DIETPI-NOTIFY 2 "We're switching to an alternative branch: $G_OLD_DEBIAN_BRANCH"
GITBRANCH_TARGET=$G_OLD_DEBIAN_BRANCH
Get_Remote_Version || return 1
G_CONFIG_INJECT 'DEV_GITBRANCH=' "DEV_GITBRANCH=$GITBRANCH_TARGET" /boot/dietpi.txt
elif (( $G_DIETPI_VERSION_CORE < $G_MIN_VERSION_CORE || ( $G_DIETPI_VERSION_CORE == $G_MIN_VERSION_CORE && $G_DIETPI_VERSION_SUB < $G_MIN_VERSION_SUB ) ))
then
G_DIETPI-NOTIFY 2 "Your DietPi version is too low to update to the current branch: v$G_DIETPI_VERSION_CORE.$G_DIETPI_VERSION_SUB"
G_DIETPI-NOTIFY 2 "We're switching to an alternative branch: $G_OLD_VERSION_BRANCH"
GITBRANCH_TARGET=$G_OLD_VERSION_BRANCH
Get_Remote_Version || return 1
G_CONFIG_INJECT 'DEV_GITBRANCH=' "DEV_GITBRANCH=$GITBRANCH_TARGET" /boot/dietpi.txt
fi
}
Check_DietPi_Update(){
# If requested, reduce current subversion by 1 to reapply last update
if (( $INPUT == -1 )); then
((G_DIETPI_VERSION_SUB--))
G_DIETPI_VERSION_RC=0
G_DIETPI-NOTIFY 2 "Repatch was requested: Subversion reduced to \e[33m\"$G_DIETPI_VERSION_SUB\"\e[90m to reapply the last update"
INPUT=1
fi
local result=1
# Update available
if (( $G_DIETPI_VERSION_CORE < $G_REMOTE_VERSION_CORE ||
( $G_DIETPI_VERSION_CORE == $G_REMOTE_VERSION_CORE && ( $G_DIETPI_VERSION_SUB < $G_REMOTE_VERSION_SUB ||
( $G_DIETPI_VERSION_SUB == $G_REMOTE_VERSION_SUB && $G_DIETPI_VERSION_RC < $G_REMOTE_VERSION_RC ) ) ) )); then
result=0
# Write available update version to flag file
[[ -d '/run/dietpi' ]] || G_EXEC mkdir /run/dietpi
echo "$G_REMOTE_VERSION_CORE.$G_REMOTE_VERSION_SUB.$G_REMOTE_VERSION_RC" > /run/dietpi/.update_available
G_DIETPI-NOTIFY 0 'Update available:'
# No update required
else
# Mark 1st run update as completed
Apply_1st_Run_Update_Success
# Remove flag file
[[ -f '/run/dietpi/.update_available' ]] && rm /run/dietpi/.update_available
G_DIETPI-NOTIFY 0 'No update required, your DietPi installation is already up to date:'
fi
INFO_VERSIONS_UPDATE
G_DIETPI-NOTIFY 2 "$INFO_CURRENT_VERSION"
G_DIETPI-NOTIFY 2 "$INFO_REMOTE_VERSION"
return "$result"
}
Check_Live_Patches()
{
# Skip live patches when Git repo changed and remove flag, else patches for repo code may not match installed DietPi code
[[ $G_GITBRANCH == "$GITBRANCH_TARGET" && $G_GITOWNER == "$GITOWNER_TARGET" ]] || { [[ -f '/run/dietpi/.live_patches' ]] && rm /run/dietpi/.live_patches; return 1; }
G_DIETPI-NOTIFY 2 'Checking for new available live patches'
# Loop through live patches sourced from version file in Get_Remote_Version()
local i
for i in "${!G_LIVE_PATCH[@]}"
do
# Check whether all expected array entries are set
if [[ ${G_LIVE_PATCH[$i]} && ${G_LIVE_PATCH_DESC[$i]} && ${G_LIVE_PATCH_COND[$i]} ]]
then
# Skip patches already known
[[ ${G_LIVE_PATCH_STATUS[$i]} ]] && continue
# Check whether patch is applicable or not
if eval "${G_LIVE_PATCH_COND[$i]}"
then
G_LIVE_PATCH_STATUS[$i]='not applied'
# When checking for updates only, store flag file
[[ $INPUT == 2 ]] && > /run/dietpi/.live_patches
else
G_LIVE_PATCH_STATUS[$i]='not applicable'
fi
# Store status of new live patch to /boot/dietpi/.version to be sourced by future DietPi-Update executions
G_CONFIG_INJECT "G_LIVE_PATCH_STATUS\[$i\]=" "G_LIVE_PATCH_STATUS[$i]='${G_LIVE_PATCH_STATUS[$i]}'" /boot/dietpi/.version
else
G_DIETPI-NOTIFY 1 "Found invalid live patch $i:\n${G_LIVE_PATCH_DESC[$i]:-NULL}\n - Condition: ${G_LIVE_PATCH_COND[$i]:-NULL}\n - Patch: ${G_LIVE_PATCH[$i]:-NULL}"
G_DIETPI-NOTIFY 1 "Please report this issue at: https://github.com/$G_GITOWNER/DietPi/issues"
unset -v "G_LIVE_PATCH[$i]" "G_LIVE_PATCH_DESC[$i]" "G_LIVE_PATCH_COND[$i]"
fi
done
# Remove flag file when patches will be applied or shown in menu (no check only mode)
[[ $INPUT != 2 && -f '/run/dietpi/.live_patches' ]] && rm /run/dietpi/.live_patches
# Return 0 if any applicable and not applied live patch is available, else 1
for i in "${G_LIVE_PATCH_STATUS[@]}"
do
[[ $i == 'not applied' ]] && return 0
done
return 1
}
# $1: Optional argument to apply a single live patch only, used in menu
Apply_Live_Patches()
{
# If no argument given, apply all applicable and not applied live patches
# shellcheck disable=SC2066
for i in "${1:-${!G_LIVE_PATCH[@]}}"
do
[[ ${G_LIVE_PATCH_STATUS[$i]} == 'not applied' ]] || continue
G_DIETPI-NOTIFY 2 "Applying live patch $i: ${G_LIVE_PATCH_DESC[$i]}"
eval "${G_LIVE_PATCH[$i]}"
# Store new status of live patch to /boot/dietpi/.version
G_LIVE_PATCH_STATUS[$i]='applied'
G_CONFIG_INJECT "G_LIVE_PATCH_STATUS\[$i\]=" "G_LIVE_PATCH_STATUS[$i]='${G_LIVE_PATCH_STATUS[$i]}'" /boot/dietpi/.version
done
}
#/////////////////////////////////////////////////////////////////////////////////////
# Update DietPi
#/////////////////////////////////////////////////////////////////////////////////////
Run_DietPi_Update(){
# RC-only update: Reapply last subversion patches
if (( $G_DIETPI_VERSION_CORE == $G_REMOTE_VERSION_CORE && $G_DIETPI_VERSION_SUB == $G_REMOTE_VERSION_SUB )); then
((G_DIETPI_VERSION_SUB--))
G_DIETPI_VERSION_RC=0
G_DIETPI-NOTIFY 2 "RC update: Subversion intentionally reduced to \e[33m\"$G_DIETPI_VERSION_SUB\"\e[90m to reapply the last update"
fi
G_DIETPI-NOTIFY 3 "$G_PROGRAM_NAME" 'Applying pre-patches'
G_EXEC_DESC='Downloading pre-patches' G_EXEC curl -sSfLO "https://raw.githubusercontent.com/$GITOWNER_TARGET/DietPi/$GITBRANCH_TARGET/.update/pre-patches"
G_EXEC_DESC='Applying execute permission' G_EXEC chmod +x pre-patches
if ! ./pre-patches "$G_DIETPI_VERSION_CORE" "$G_DIETPI_VERSION_SUB"
then
G_DIETPI-NOTIFY 1 "An error occurred during pre-patching. Please check the above log or $FP_LOG for errors, and rerun \"dietpi-update\" after the cause has been solved."
exit 1
fi
G_DIETPI-NOTIFY 0 'Successfully applied pre-patches'
G_DIETPI-NOTIFY 3 "$G_PROGRAM_NAME" 'Upgrading APT packages'
G_AGUP
G_AGUG
G_DIETPI-NOTIFY 3 "$G_PROGRAM_NAME" 'Installing new DietPi code'
G_EXEC_DESC='Downloading update archive' G_EXEC curl -sSfLO "https://github.com/$GITOWNER_TARGET/DietPi/archive/$GITBRANCH_TARGET.tar.gz"
G_EXEC_DESC='Unpacking update archive' G_EXEC tar xf "${GITBRANCH_TARGET##*/}.tar.gz" # Support for Git branch names with forward slashes
local dir="DietPi-${GITBRANCH_TARGET//\//-}" # GitHub translates forward slashes into dashes
G_EXEC_DESC='Removing unused files' G_EXEC rm "${GITBRANCH_TARGET##*/}.tar.gz"
G_EXEC_DESC='Hardening update archive mode' G_EXEC chmod -R g-w "$dir"
G_EXEC_DESC='Installing new DietPi scripts' G_EXEC cp -a "$dir/dietpi" /boot/
G_EXEC_DESC='Installing new DietPi system files' G_EXEC cp -a "$dir/rootfs/." /
# Save version + Git info now for sub scripts to pull from correct branch
G_GITOWNER=$GITOWNER_TARGET
G_GITBRANCH=$GITBRANCH_TARGET
G_VERSIONDB_SAVE
# Verify/update dietpi.txt entries
if ! /boot/dietpi/func/dietpi-set_software verify_dietpi.txt; then
G_DIETPI-NOTIFY 1 "An error occurred during dietpi.txt updates. Please check the above log or $FP_LOG for errors, and rerun \"dietpi-update\" after the cause has been solved."
exit 1
fi
# Failsafe: Force sync to disk
G_EXEC sync
# Reload systemd units
G_EXEC systemctl daemon-reload
G_DIETPI-NOTIFY 3 "$G_PROGRAM_NAME" 'Applying incremental patches'
INFO_VERSIONS_UPDATE
G_DIETPI-NOTIFY 2 "$INFO_CURRENT_VERSION"
G_DIETPI-NOTIFY 2 "$INFO_REMOTE_VERSION"
if ! "$dir/.update/patches"; then
G_DIETPI-NOTIFY 1 "An error occurred during incremental patching. Please check the above log or $FP_LOG for errors, and rerun \"dietpi-update\" after the cause has been solved."
exit 1
fi
# Autoremove possibly obsolete DEB packages and reload systemd units
G_AGA
G_EXEC systemctl daemon-reload
G_DIETPI_VERSION_CORE=$G_REMOTE_VERSION_CORE
G_DIETPI_VERSION_SUB=$G_REMOTE_VERSION_SUB
G_DIETPI_VERSION_RC=$G_REMOTE_VERSION_RC
G_VERSIONDB_SAVE
G_DIETPI-NOTIFY 0 "Incremental patching to v$G_REMOTE_VERSION_CORE.$G_REMOTE_VERSION_SUB.$G_REMOTE_VERSION_RC completed"
# Reset, check for, and apply all applicable live patches
G_LIVE_PATCH_STATUS=()
Check_Live_Patches && Apply_Live_Patches
}
#/////////////////////////////////////////////////////////////////////////////////////
# MENUS
#/////////////////////////////////////////////////////////////////////////////////////
Get_View_Changelog(){
[[ -f 'CHANGELOG.txt' ]] || G_EXEC_NOEXIT=1 G_EXEC curl -sSfLO "https://raw.githubusercontent.com/$GITOWNER_TARGET/DietPi/$GITBRANCH_TARGET/CHANGELOG.txt" || return 1
G_WHIP_VIEWFILE CHANGELOG.txt
}
Menu_Update(){
while :
do
G_WHIP_BUTTON_CANCEL_TEXT='Exit'
G_WHIP_MENU_ARRAY=(
'' '●─ Update DietPi '
'Update' ": Apply update to: v$G_REMOTE_VERSION_CORE.$G_REMOTE_VERSION_SUB.$G_REMOTE_VERSION_RC"
'' '●─ Additional Options '
'Changelog' ': View recent changelog and patch notes.'
'Backup' ': Create a system backup before updating.'
)
G_WHIP_DEFAULT_ITEM='Update'
if G_WHIP_MENU "Update available:\n - $INFO_CURRENT_VERSION\n - $INFO_REMOTE_VERSION\n
Please select 'Update' option to apply the update."; then
if [[ $G_WHIP_RETURNED_VALUE == 'Update' ]]; then
G_WHIP_SIZE_X_MAX=80
G_WHIP_YESNO ">----------------------------------Notice----------------------------------<
- A benefit of DietPi is: We use standard Linux (Debian) configurations and commands.
- A potential downside is: We can't possibly accommodate or predict all modification to Linux configurations files by the end user, outside of DietPi programs, during updates.\n
Although we test the updates thoroughly, if you have made any custom changes to Linux configuration files outside of the DietPi programs, an update may trigger a potential issue.
>--------------------------------------------------------------------------<\n
Do you wish to continue and update DietPi to v$G_REMOTE_VERSION_CORE.$G_REMOTE_VERSION_SUB.$G_REMOTE_VERSION_RC?" && return 0
elif [[ $G_WHIP_RETURNED_VALUE == 'Changelog' ]]; then
Get_View_Changelog
elif [[ $G_WHIP_RETURNED_VALUE == 'Backup' ]]; then
G_PROMPT_BACKUP
fi
else
return 1 # Exit
fi
done
}
Menu_Live_Patches()
{
local i G_WHIP_MENU_ARRAY G_WHIP_LAST_ITEM=0 info
while :
do
G_WHIP_MENU_ARRAY=()
for i in "${!G_LIVE_PATCH[@]}"
do
G_WHIP_MENU_ARRAY+=("$i" ": [${G_LIVE_PATCH_STATUS[$i]}] ${G_LIVE_PATCH_DESC[$i]}")
done
G_WHIP_BUTTON_CANCEL_TEXT='Exit'
G_WHIP_DEFAULT_ITEM=$G_WHIP_LAST_ITEM
if G_WHIP_MENU 'No DietPi update is available, but live patches have been found for your current version to fix little bugs until the next version is released.\n\nSelect a patch below for further details:'
then
i=$G_WHIP_RETURNED_VALUE
G_WHIP_LAST_ITEM=$i
info="Live patch $i:\n\n${G_LIVE_PATCH_DESC[$i]}\n\nCondition: ${G_LIVE_PATCH_COND[$i]}\n\nPatch: ${G_LIVE_PATCH[$i]}"
# Not applicable
if [[ ${G_LIVE_PATCH_STATUS[$i]} == 'not applicable' ]]
then
G_WHIP_MSG "$info\n\nYour system does not fulfil the conditions for this patch."
# Already applied
elif [[ ${G_LIVE_PATCH_STATUS[$i]} == 'applied' ]]
then
G_WHIP_MSG "$info\n\nThis patch has been applied already."
# Applicable and not applied yet
elif G_WHIP_YESNO "$info\n\nDo you want to apply this patch now?"
then
Apply_Live_Patches "$i"
fi
else
return 0 # Exit
fi
done
}
#/////////////////////////////////////////////////////////////////////////////////////
# Main Loop
#/////////////////////////////////////////////////////////////////////////////////////
#----------------------------------------------------------------
G_DIETPI-NOTIFY 3 "$G_PROGRAM_NAME" 'Checking for available DietPi update'
#----------------------------------------------------------------
# Check network connectivity and sync system clock
G_CHECK_NET
/boot/dietpi/func/run_ntpd
#----------------------------------------------------------------
# Check for valid Git repository
if Get_Remote_Version && Check_Git_Migration
then
# Check for DietPi update and in case store result to /run/dietpi/.update_available for use by DietPi-Banner
if Check_DietPi_Update
then
# Exit if check-only input
(( $INPUT == 2 )) && exit 0
G_DIETPI-NOTIFY 3 "$G_PROGRAM_NAME" 'Checking for update pre-requirements'
# Verify userdata location
G_CHECK_USERDATA
# Check for sufficient free space
G_CHECK_FREESPACE / 100 || exit 1
# Noninteractive update or ask user
if (( $INPUT == 1 )) || Menu_Update
then
# Disable powersaving on main screen
setterm -blank 0 -powersave off 2> /dev/null
# Stop Services
/boot/dietpi/dietpi-services stop
# Run_DietPi_Update: https://github.com/MichaIng/DietPi/issues/1877#issuecomment-403866204
# - Log to file by redirecting to subshell instead of piping, else G_EXEC cannot exit the script via "kill -INT $$": https://github.com/MichaIng/DietPi/issues/3127
Run_DietPi_Update &> >(tee "$FP_LOG"); wait $!
# Mark 1st run update as completed
Apply_1st_Run_Update_Success
# Remove .update_available flag file
rm /run/dietpi/.update_available
G_DIETPI-NOTIFY 3 "$G_PROGRAM_NAME" 'Completed'
INFO_VERSIONS_UPDATE
G_DIETPI-NOTIFY 2 "$INFO_CURRENT_VERSION"
G_DIETPI-NOTIFY 2 "$INFO_REMOTE_VERSION"
# Update DietPi-Survey
/boot/dietpi/dietpi-survey 1
# Failsafe: Force sync to disk
G_EXEC sync
# Offer to do a reboot if required as of missing kernel modules, do it automatically on first run setup
if ! G_CHECK_KERNEL
then
if [[ $G_DIETPI_INSTALL_STAGE == 1 ]]
then
G_DIETPI-NOTIFY 2 'A reboot is done to finalise the kernel upgrade'
reboot
else
G_WHIP_BUTTON_CANCEL_TEXT='Skip' G_WHIP_YESNO "[ INFO ] A reboot is recommended
\nKernel modules for the loaded kernel at /lib/modules/$(uname -r) are missing. This is most likely the case as of a recently applied kernel upgrade where a reboot is required to load the new kernel.
\nWe recommend to perform a reboot now for the system to be able to load kernel modules ondemand. If your kernel does not use dedicated modules, please create the mentioned directory manually to mute this info in the future.
\nDo you want to reboot now?" && reboot
fi
fi
# Start services only on finished install state, else dietpi-software will follow immediately
(( $G_DIETPI_INSTALL_STAGE == 2 )) && /boot/dietpi/dietpi-services restart
fi
# Desktop run, exit key prompt
[[ $DISPLAY ]] && read -rp "Press any key to exit $G_PROGRAM_NAME..."
exit 0
# No update available: Check for live patches
elif Check_Live_Patches
then
# Forced update mode
if (( $INPUT == 1 ))
then
Apply_Live_Patches
# Menu mode
elif (( $INPUT == 0 ))
then
Menu_Live_Patches
exit 0
fi
fi
fi
# If no DietPi update is available, check for and in case apply APT updates based on input mode and dietpi.txt choice
mode=$(sed -n '/^[[:blank:]]*CONFIG_CHECK_APT_UPDATES=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
# Forced update input and mode 2: Apply APT updates if available
if [[ $INPUT == 1 && $mode == 2 ]]
then
G_AGUP -v
# shellcheck disable=SC2154
(( $G_AGUP_COUNT )) && G_AGUG &> >(tee /var/tmp/dietpi/logs/dietpi-upgrade_apt.log)
# No forced update input but APT updates check not disabled: Check for APT updates and store result to /run/dietpi/.apt_updates to be used by DietPi-Banner
elif [[ $mode != 0 ]]
then
G_AGUP -f
fi
#----------------------------------------------------------------
exit 0
#----------------------------------------------------------------
}