blob: d7b4af82118e86dee267a49148508878fd0045c5 (
plain)
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
|
#!/bin/sh
######################################################################
# defaults
dest=""
tarb=""
tool="dnf"
grps="core"
rpms=""
krnl="kernel"
conf=""
quiet="--quiet"
platform=""
######################################################################
# create work dir
function msg() {
local txt="$1"
local bold="\x1b[1m"
local normal="\x1b[0m"
echo -e "${bold}### ${txt}${normal}"
}
function do_cleanup() {
msg "cleaning up ..."
# sudo umount -v "$dest/dev"
sudo rm -rf "$WORK"
}
WORK="${TMPDIR-/var/tmp}/${0##*/}-$$"
mkdir "$WORK" || exit 1
trap 'do_cleanup' EXIT
BASE="$(dirname $0)"
######################################################################
# parse args
function print_help() {
cat <<EOF
usage: $0 [ options ]
options:
what to create (one must be specified)
--tar <tarball>
--dest <dir>
what to install
--groups <groups> (default: $grps)
--packages <rpms> (default: $rpms)
--kernel <kernel> (default: $krnl)
package manager setup
--config <repos>
--platform <name>
--dnf (default)
--yum
EOF
}
while test "$1" != ""; do
case "$1" in
-d | --dest)
dest="$2"
shift; shift
;;
-t | --tar | --tarball)
tarb="$2"
dest="$WORK/install"
shift; shift
;;
-g | --groups)
grps="$2"
shift; shift
;;
-p | --packages)
rpms="$2"
shift; shift
;;
-k | --kernel)
krnl="$2"
shift; shift
;;
-c | --config)
conf="$2"
shift; shift
;;
--platform)
platform="$2"
shift; shift
;;
-v | --verbose)
quiet=""
shift
;;
--dnf)
tool="dnf"
shift
;;
--yum)
tool="yum"
shift
;;
--force)
allow_override="yes"
shift
;;
-h | --help)
print_help
exit 1
;;
*) echo "ERROR: unknown arg: $1 (try --help)"
exit 1
;;
esac
done
######################################################################
# sanity checks
if test "$dest" = ""; then
echo "ERROR: no dest given"
exit 1
fi
if test -d "$dest"; then
echo "ERROR: directory exists: $dest"
exit 1
fi
if test "$conf" != "" -a ! -f "$conf"; then
echo "ERROR: not found: $conf"
exit 1
fi
if test "$tarb" != "" -a -f "$tarb"; then
if test "$allow_override" = "yes"; then
rm -f "$tarb"
else
echo "ERROR: tarball exists: $tarb"
exit 1
fi
fi
######################################################################
# go!
if test "$tool" = "dnf" -a ! -x "$(which dnf 2>/dev/null)"; then
echo "WARNING: dnf not found, try fallback to yum"
tool="yum"
fi
case "$tool" in
dnf)
tool="$tool -y --installroot ${dest}"
if test "$conf" != ""; then
tool="$tool --config=${conf}"
tool="$tool --setopt=reposdir=${dest}/etc/yum.repos.d"
tool="$tool --setopt=zchunk=off"
tool="$tool --setopt=install_weak_deps=False"
tool="$tool --releasever=0"
fi
if test "$platform" != ""; then
tool="$tool --setopt=module_platform_id=platform:$platform"
fi
inst=""
for item in $grps; do inst="${inst} @${item}"; done
for item in $rpms; do
case "$item" in
-*) inst="${inst} -x ${item#-}" ;;
*) inst="${inst} ${item}" ;;
esac
done
;;
yum)
tool="$tool -y --installroot ${dest}"
if test "$conf" != ""; then
tool="$tool --config ${conf}"
fi
# with this yum uses the (empty) installroot repos dir,
# so we don't have to hop through enablerepo/disablerepo
# loops to disable the host repos
mkdir -p ${dest}/etc/yum.repos.d
inst="--"
for item in $grps; do inst="${inst} @${item}"; done
for item in $rpms; do inst="${inst} ${item}"; done
;;
*)
# should not happen
echo "Oops"
exit 1
;;
esac
mkdir -p ${dest}/{dev,proc,sys,mnt}
sudo "$BASE/makedev.sh" "${dest}/dev"
msg "dnf install packages to $dest ..."
#sudo mount --bind /dev $dest/dev
#sudo mount -o remount,bind,ro $dest/dev
(set -x; sudo $tool $quiet install $inst $krnl) || exit 1
if test ! -f ${dest}/etc/sysconfig/kernel; then
echo "UPDATEDEFAULT=yes" > $WORK/sys-kernel
echo "DEFAULTKERNEL=kernel-core" >> $WORK/sys-kernel
sudo cp $WORK/sys-kernel ${dest}/etc/sysconfig/kernel
fi
if test -f ${dest}/etc/selinux/config; then
# Ask for relabel.
# Put selinux into permissive, relabel might fail otherwise.
# After first boot (which relabels) setting enforcing should work.
sudo sed -i \
-e 's/^SELINUX=.*/SELINUX=permissive/' \
${dest}/etc/selinux/config
sudo touch "${dest}/.autorelabel"
fi
sudo rm -rf "${dest}/var/cache/"{dnf,yum}
if test "$tarb" != ""; then
case "$tarb" in
*.gz) topt="--gzip"
;;
*.xz) topt="--xz"
;;
*) topt=""
;;
esac
msg "create tarball $tarb ..."
(cd $dest; sudo tar --create $topt .) > "$tarb"
fi
msg "all done."
|