This repository has been archived by the owner on Jul 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
make-redhat-upgrade-repo
executable file
·128 lines (105 loc) · 3.68 KB
/
make-redhat-upgrade-repo
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
#!/bin/bash
#
# make-redhat-upgrade-repo - quick script to make a redhat-upgrade-tool usable
# instrepo for testing
#
# Copyright (C) 2012 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Author: Will Woods <wwoods@redhat.com>
# constants and helper functions!
# -------------------------------
export PLYMOUTH_THEME_NAME=redhat-upgrade-tool
KERNELPATH=vmlinuz
UPGRADEPATH=upgrade.img
die() { echo $(basename $0): error: $@ >&2; exit 1; }
sha256() { set -- $(sha256sum $1); echo "sha256:$1"; }
# argument validation stuff!
# --------------------------
repodir="$1"
kver="${2:-$(uname -r)}"
[ -z "$1" ] && echo "usage: make-redhat-upgrade-repo REPODIR [KERNELVER]" && exit 1
[ -d "$repodir" ] || die "directory $repodir doesn't exist. create it first."
[ -f $repodir/repodata/repomd.xml ] || createrepo=1
source /etc/os-release 2>/dev/null
kernel="/boot/vmlinuz-$kver" # NOTE: distro-specific
# sanity checks!
# --------------
[ -f "$kernel" ] || die "can't find kernel $kernel"
[ -d "/lib/modules/$kver" ] || die "can't find modules for kernel $kver"
command -v dracut >/dev/null || die "can't find dracut"
dracut --list-modules 2>/dev/null | grep -q system-upgrade || \
die "dracut can't find system-upgrade module. install redhat-upgrade-dracut."
if [ $createrepo ]; then
command -v createrepo >/dev/null || die "can't find createrepo"
fi
# actual repo creation!
# ---------------------
[ $(id -u) = 0 ] || die "be root."
# make leading dirs
echo "creating redhat-upgrade-tool-capable repo at $repodir"
mkdir -p "$repodir/$(dirname $KERNELPATH)" \
"$repodir/$(dirname $UPGRADEPATH)" || \
die "failed to make required directories."
# copy kernel into place
echo "* copying kernel to $KERNELPATH"
cp -f $kernel "$repodir/$KERNELPATH" || \
die "couldn't copy kernel."
# build upgrade.img
echo "* building $UPGRADEPATH (this will take a moment..)"
dracut --conf /dev/null --confdir $repodir \
--no-hostonly --nolvmconf --nomdadmconf \
--add "system-upgrade plymouth-label convertfs" \
--xz --force "$repodir/$UPGRADEPATH" "$kver" || \
die "dracut failed to build upgrade.img."
# write .treeinfo
echo "* writing .treeinfo"
arch=$(uname -m)
cat > $repodir/.treeinfo << __EOT__ || die "couldn't write .treeinfo"
[general]
family = redhat-upgrade-tool
timestamp = $(date '+%s')
arch = $arch
version = ${VERSION_ID:-0}
[images-$arch]
kernel = $KERNELPATH
upgrade = $UPGRADEPATH
[checksums]
$KERNELPATH = $(sha256 "$repodir/$KERNELPATH")
$UPGRADEPATH = $(sha256 "$repodir/$UPGRADEPATH")
__EOT__
# create repodata if necessary
if [ $createrepo ]; then
echo "* creating repodata"
createrepo $repodir >/dev/null || die "createrepo failed."
else
echo "* repodata exists, skipping createrepo"
fi
chmod -R a+r $repodir
cat > $repodir/serve << '__EOT__'
#!/bin/bash
echo "This repo will be reachable at:"
echo
for ip in $(ip addr | sed -rn 's| *inet ([0-9.]+)/.*|\1|p'); do
echo " http://$ip:${1:-8000}/"
done
echo
python -m SimpleHTTPServer $1
__EOT__
chmod 0755 $repodir/serve
echo "done."
if [ -z "$VERSION_ID" ]; then
echo "You should probably set 'version' in $repodir/.treeinfo"
fi