-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathto8.sh
201 lines (166 loc) · 7.32 KB
/
to8.sh
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
#!/usr/bin/env bash
# https://github.com/johnj/centos-to8-upgrade
# CentOS no longer provides a supported path for upgrading CentOS-7 systems to
# CentOS-8.
#
# So here is a HIGHLY EXPERIMENTAL and HIGHLY DANGEROUS script for doing an
# in-place/online upgrade to 8.
#
# Backups are your friend, it is entirely possible you will be left with a
# non-functioning and irrepairable system after this process finishes.
function info() {
echo "[$(date)] [info] $1"
}
function preflight_check() {
echo -n "[preflight] checking $1"
if [[ $2 -eq 0 ]]; then
echo " ... PASSED"
else
echo " ... FAILED ($3)"
exit 1
fi
}
STAGING_DIR=${STAGING_DIR:-/to8}
CONFIG_DIRS=${CONFIG_DIRS:-etc}
test "$(whoami)" == "root"
preflight_check "if you are running this as root" $? "you need to run me as root"
test "$(grep VERSION_ID /etc/os-release | awk -F'=' '{ print $2 }')" == '"7"'
preflight_check "if you are running this on a RHEL-like 7 system" $? "you need to run me from a RHEL-like 7 OS"
test -x "$(command -v rsync)"
preflight_check "if rsync is installed" $? "you need to install rsync"
if [[ ! -d $STAGING_DIR ]]; then
mkdir -p $STAGING_DIR
for i in `echo dev proc run`; do
mkdir $STAGING_DIR/$i
mount -o bind /$i $STAGING_DIR/$i
done
fi
available=$(df --total $STAGING_DIR | tail -n1 | awk '{ print $4 }')
test "$((available))" -ge 2000000
preflight_check "if you have at least 2GB in the staging directory (${STAGING_DIR}), you can override this by setting the env var STAGING_DIR (ie, STAGING_DIR='/var/to8' $0)" $? "you need at least 2GB of free space to run me"
echo
echo "Preflight checks PASSED"
echo
which selinuxenabled 2>/dev/null 1> /dev/null
if [[ $? -eq 0 ]]; then
selinuxenabled 2>/dev/null 1> /dev/null
if [[ $? -eq 0 ]]; then
echo "SELinux is enabled, this process will temporarily set SELinux to Permissive mode, continue? [Y/n]"
if [ -z "${NONINTERACTIVE}" ]; then
read -n 1 yn
else
yn="y"
fi
echo
if [[ "${yn}" == "n" ]]; then
echo "Aborting $0"
exit 4
else
echo "Continuing..."
SELINUX_BEFORE="$(getenforce)"
setenforce 0
fi
fi
fi
info "starting to make a copy of /${CONFIG_DIRS} into ${STAGING_DIR}"
rsync -avu /${CONFIG_DIRS} ${STAGING_DIR} 2>&1 | tee -a $STAGING_DIR/to8.log
info "finished making a copy of /${CONFIG_DIRS} into ${STAGING_DIR}"
info "setting up CentOS 8 repository in ${STAGING_DIR}"
mkdir -p $STAGING_DIR/etc/yum.repos.d $STAGING_DIR/etc/pki/rpm-gpg $STAGING_DIR/etc/yum/vars
echo "8" > $STAGING_DIR/etc/yum/vars/releasever
# these will be replaced by dnf symlinks
mkdir -p $STAGING_DIR/etc/yum/yum7
mv $STAGING_DIR/etc/yum/{pluginconf.d,protected.d,vars} $STAGING_DIR/etc/yum/yum7
# from https://www.centos.org/keys/RPM-GPG-KEY-CentOS-Official
# more info: https://www.centos.org/keys/
# pub 4096R/8483C65D 2019-05-03 CentOS (CentOS Official Signing Key) <security@centos.org>
# Key fingerprint = 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
cat >/etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial <<EOF
-----BEG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9XYIokIQXd0T2rD3/lNGxNtORZ2bKjD
vOzYzvh2idUIY1DgGWJ11gtHFIA9CvHcW+SMPEhkcKZJAO51ayFBqTSSpiorVwTq
a0cB+cgmCQOI4/MY+kIvzoexfG7xhkUqe0wxmph9RQQxlTbNQDCdaxSgwbF2T+gw
byaDvkS4xtR6Soj7BKjKAmcnf5fn4C5Or0KLUqMzBtDMbfQQihn62iZJN6ZZ/4dg
q4HTqyVpyuzMXsFpJ9L/FqH2DJ4exGGpBv00ba/Zauy7GsqOc5PnNBsYaHCply0X
407DRx51t9YwYI/ttValuehq9+gRJpOTTKp6AjZn/a5Yt3h6jDgpNfM/EyLFIY9z
V6CXqQQ/8JRvaik/JsGCf+eeLZOw4koIjZGEAg04iuyNTjhx0e/QHEVcYAqNLhXG
rCTTbCn3NSUO9qxEXC+K/1m1kaXoCGA0UWlVGZ1JSifbbMx0yxq/brpEZPUYm+32
o8XfbocBWljFUJ+6aljTvZ3LQLKTSPW7TFO+GXycAOmCGhlXh2tlc6iTc41PACqy
yy+mHmSv
=kkH7
-----END PGP PUBLIC KEY BLOCK-----
EOF
cat >$STAGING_DIR/etc/yum.repos.d/CentOS-Base.repo <<EOF
[BaseOS]
name=CentOS-8 - Base
mirrorlist=http://mirrorlist.centos.org/?release=8&arch=\$basearch&repo=BaseOS&infra=\$infra
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
cat >$STAGING_DIR/etc/yum.repos.d/CentOS-AppStream.repo <<EOF
[AppStream]
name=CentOS-8 - AppStream
mirrorlist=http://mirrorlist.centos.org/?release=8&arch=\$basearch&repo=AppStream&infra=\$infra
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
cat >$STAGING_DIR/etc/yum.repos.d/CentOS-Extras.repo <<EOF
[Extras]
name=CentOS-8 - Extras
mirrorlist=http://mirrorlist.centos.org/?release=8&arch=\$basearch&repo=Extras&infra=\$infra
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
info "starting CentOS-8 setup in ${STAGING_DIR}"
yum install -y --installroot=$STAGING_DIR hostname yum centos-release glibc-langpack-en $(rpmquery -a --queryformat '%{NAME} ') 2>&1 | tee -a $STAGING_DIR/to8.log
info "finished CentOS-8 setup in ${STAGING_DIR}"
info "beginning to sync ${STAGING_DIR} to /"
rsync -irazvAX --progress --backup --backup-dir=$STAGING_DIR/to8_backup_$(date +\%Y-\%m-\%d) $STAGING_DIR/* / --exclude="var/cache/yum/x86_64/8/BaseOS/packages" --exclude="tmp" --exclude="sys" --exclude="lost+found" --exclude="mnt" --exclude="proc" --exclude="dev" --exclude="media" --exclude="to8.yum.log"
info "finished syncing ${STAGING_DIR} to /"
info "refreshing grub config for /boot"
grub2-mkconfig -o /boot/grub2/grub.cfg
info "grub config reload for /boot finished"
info "setting up new repo files"
for f in `ls /etc/yum.repos.d/CentOS*.repo.rpmnew`; do
n=$(echo $f | sed -e 's/\.rpmnew$//')
mv -vf $f $n
done
if [ -e /etc/os-release.rpmnew ]; then
mv /etc/os-release /etc/os-release.rpmold
mv /etc/os-release.rpmnew /etc/os-release
fi
# this locale reference seems to have changed in 8
if [[ "$LANG" == "en_US.UTF-8" ]]; then
localectl set-locale en_US.utf8
fi
if [ -n "$SELINUX_BEFORE" ]; then
info "Almost done, since you had SELinux enabled, attempting to restore the contexts."
restorecon -e $STAGING_DIR -Rv / 2>&1 | tee -a $STAGING_DIR/to8.log
info "SELinux contexts restored."
fi
systemctl daemon-reload
echo "Packages which could not be migrated into CentOS 8 using the base repositories:"
grep -e 'No package .* available' $STAGING_DIR/to8.log | awk '{ print $3 }' | tr $'\n' ' '
echo
info "CentOS-8 has been setup, please reboot to load the CentOS-8 kernel and modules."
info "If you would like to move to CentOS-8-Stream, please install the centos-release-stream package from CentOS Extras by running:"
info 'yum install --enablerepo="extras" centos-release-stream'