This repository has been archived by the owner on May 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmakefeduprepo
executable file
·139 lines (115 loc) · 3.91 KB
/
makefeduprepo
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
#!/bin/bash
#
# makefeduprepo - quick script to make a fedup-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=fedup
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: makefeduprepo 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 fedup-dracut."
if [ $createrepo ]; then
command -v createrepo >/dev/null || die "can't find createrepo"
fi
# actual repo creation!
# ---------------------
# make leading dirs
echo "creating fedup-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
sudo -n true &>/dev/null || echo "need root to build initrd."
sudo true || die "failed to become root."
echo "* building $UPGRADEPATH (this will take a moment..)"
sudo sh -c "
export PLYMOUTH_THEME_NAME=$PLYMOUTH_THEME_NAME
dracut --conf /dev/null --confdir $repodir \
--no-hostonly --nolvmconf --nomdadmconf \
--add system-upgrade \
--xz --force \"$repodir/$UPGRADEPATH\" $kver
chown $(id -u):$(id -g) \"$repodir/$UPGRADEPATH\"" || \
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 = fedup
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
PORT=${1:-8000}
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:$PORT/"
done
echo
cat | python - $PORT <<__PYTHON_END__
from SimpleHTTPServer import test
try:
test()
except KeyboardInterrupt:
print("exiting")
__PYTHON_END__
__EOT__
chmod 0755 $repodir/serve
echo "done."
if [ -z "$VERSION_ID" ]; then
echo "You should probably set 'version' in $repodir/.treeinfo"
fi