Repository navigation
Expand file tree
/
Copy pathsdm-spawn
More file actions
executable file
·133 lines (126 loc) · 3.54 KB
/
Copy pathsdm-spawn
File metadata and controls
executable file
·133 lines (126 loc) · 3.54 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
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
#!/bin/bash
# This script runs in the nspawn image
#
function loadparams() {
local arg="$1"
source $SDMPT/etc/sdm/sdm-readparams $arg
}
function upgkeepconf() {
#
# Write /etc/apt/apt.conf.d/02sdm-myconf
# Forcing apt to not query about conf file changes
# $1 = "--yes" or ""
# $2 = $showapt or 0 to not display output
# $3 = 0 [upgrade] or 1 [dist-upgrade]
#
cat > /etc/apt/apt.conf.d/02sdm-myconf <<EOF
Dpkg::Options {
"--force-confdef";
"--force-confold";
}
EOF
[ "$3" == "0" ] && upg="upgrade" || upg="dist-upgrade"
doaptrpterror "$1 $upg" "$2"
rm -f /etc/apt/apt.conf.d/02sdm-myconf
}
function p1exit() {
#
# Clean up when the container commands exit
#
unadjust_initramfs_all
exit
}
function doctrlcp1() {
echo "% Caught CTRL/C. Exiting Phase 1..."
unadjust_initramfs_all #Be clean
exit 1 #Can't use poweroff since no job control in either nspawn or chroot
}
function logfreeandexit() {
local sts=$?
logfreespace "at end of 'apt $cmdoptions'"
exit $sts
}
#
# Read configuration information from sdm
#
loadparams
#
# Handle commands which are run in the context of the container
#
cmd="$(stripquotes "$1")"
cmdoptions="$(stripquotes "$2")"
#logtoboth "DD-1 cmd:|$cmd| cmdoptions:|$cmdoptions| 2:|$2| 3:|$3|"
trap "doctrlcp1" SIGINT
trap p1exit EXIT
case "$cmd" in
apt)
logtoboth "* Start apt maintenance"
logfreespace "at start of 'apt $cmdoptions'"
adjust_initramfs_all
[[ "$cmdoptions" =~ "update" ]] && { logtoboth "> Perform 'apt update'" && doaptrpterror "update" 0 || logfreeandexit ; }
[[ "$cmdoptions" =~ "upgrade" ]] && { logtoboth "> Perform 'apt upgrade'" && upgkeepconf --yes 0 $aptdistupgrade || logfreeandexit ; }
[[ "$cmdoptions" =~ "autoremove" ]] && { logtoboth "> Perform 'apt autoremove'" && doaptrpterror "autoremove" 0 || logfreeandexit ; }
logfreespace "at end of 'apt $cmdoptions'"
logtoboth "* apt maintenance Completed"
exit 0
;;
b1script) # Burn time run script
fn="/etc/sdm/assets/$(basename $cmdoptions)"
if [ -f $fn ]
then
logtoboth "> Run script '$cmdoptions' [$fn] in nspawn"
/etc/sdm/assets/$(basename $cmdoptions)
else
logtobothex "? Internal error: Script '$fn' not found"
fi
exit
;;
burn-enable-lightdm-delay) # Delay lightdm enable until sdm-firstboot
pfx=burning
delaylightdmenable
exit
;;
run-all-plugins) # Run Plugin phase 1 or post-install
phase=$cmdoptions
runplugins "$plugins" $phase || exit
exit
;;
run-plugin-list) # Run list of plugins phase 1 or post-install
phase=$cmdoptions
theseplugins="$(stripquotes "$3")"
runplugins "$theseplugins" $phase || exit
exit
;;
run-one-plugin) # Run Plugin phase 1 or post-install
# $cmdoptions: plugin name and args $3: Phase
p="$cmdoptions"
phase="$(stripquotes "$3")"
runonepluginx "$p" $phase || exit
exit
;;
run-command) # Run a single command in phase 1 or post-install
adjust_initramfs_all
runcmd="$(stripquotes "$cmdoptions") $3 $4 $5 $6 $7 $8"
bash -c "$runcmd" || exit
unadjust_initramfs_all
exit
;;
run-command-quietly) # Run a single command in phase 1 or post-install
adjust_initramfs_all
runcmd="$cmdoptions $3 $4 $5 $6 $7 $8"
$runcmd > /dev/null 2>&1 || exit
unadjust_initramfs_all
exit
;;
run-update-initramfs) # Run initramfs update in phase1 or post-install
adjust_initramfs_all
runcmd="update-initramfs -u $3 $4 $5 $6 $7 $8"
$runcmd || exit
unadjust_initramfs_all
exit
;;
*) # None of the above
logtobothex "? Invalid sdm-spawn function '$cmd'"
exit
;;
esac