Browse code

photon-upgrade: upgrade photon from 2.0 to 3.0.

Package to upgrade photon from version 2.0 to version 3.0.

Change-Id: I66e33007b426574edc086d051cbe2a9921401aff
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/5952
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Sharath George

dweepadvani authored on 2018/10/23 04:37:33
Showing 2 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,108 @@
0
+#!/bin/bash
1
+
2
+FROM_VERSION="$(awk '/VMware Photon OS /{print $4}' /etc/photon-release)"
3
+TO_VERSION='3.0'
4
+
5
+# The package list of deprecated packages from 2.0 to 3.0
6
+depPkgsFrom2To3='urlgrabber librepo ceph-deploy conntrack-tools libhif yum createrepo ceph ostree micro-config-drive gmock deltarpm rpm-ostree kibana docker-volume-vsphere yarn mesos yum-metadata-parser'
7
+
8
+#Some packages are deprecaed from 3.0, lets remove them before moving to 3.0
9
+function remove_unsupported_pkgs() {
10
+  local rc
11
+  for pkg in $depPkgsFrom2To3; do
12
+    if rpm -q $pkg; then
13
+      tdnf erase $pkg -y
14
+      rc=$?
15
+      if [ $rc -ne 0 ]; then
16
+        echo "Could not erase $pkg. Cannot continue."
17
+        exit $rc
18
+      fi
19
+    fi
20
+  done
21
+}
22
+
23
+function upgrade_photon_release() {
24
+   tdnf -y update photon-release --releasever=$TO_VERSION --refresh
25
+}
26
+
27
+function distro_upgrade() {
28
+   tdnf distro-sync --refresh
29
+}
30
+
31
+function rebuilddb() {
32
+   rpm --rebuilddb
33
+}
34
+
35
+#must reboot after an upgrade
36
+function ask_for_reboot() {
37
+  read -p "Reboot is recommended after an upgrade. Reboot now(y/n)?" yn
38
+  case $yn in
39
+    [Yy]* ) reboot;;
40
+    [Nn]* ) exit;;
41
+  esac
42
+}
43
+
44
+#if the current install has packages deprecated in the target version,
45
+#there is no clean upgrade path. confirm if it is okay to remove.
46
+function check_deprecated() {
47
+  pkgs_to_remove=''
48
+  for pkg in ${depPkgsFrom2To3}; do
49
+    installed=`rpm -q $pkg`
50
+    if [ $? -eq 0 ]; then
51
+      pkgs_to_remove="${pkgs_to_remove}${pkg}\n"
52
+    fi
53
+  done
54
+  if [ "$pkgs_to_remove" != "" ];then
55
+    echo "The following packages are deprecated and must be removed before upgrade."
56
+    echo -e $pkgs_to_remove
57
+    read -p "Proceed(y/n)?" yn
58
+    case $yn in
59
+      [Nn]* ) exit;;
60
+    esac
61
+  fi
62
+}
63
+
64
+#there is a chance that /var/run is a directory
65
+#in this case, move its contents to /run and make it a symlink
66
+function make_var_run_a_symlink() {
67
+  if [ -d '/var/run' ] && [ ! -L '/var/run' ] ; then
68
+    mv /var/run/* /run
69
+    rm -rf /var/run
70
+    ln -sf /run /var/run
71
+  fi
72
+}
73
+
74
+#next version of photon uses specs with dependencies
75
+#of the form x or y. update tdnf, libsolv and rpm to support it.
76
+function update_solv_to_support_complex_deps() {
77
+   tdnf -y update libsolv rpm tdnf --refresh
78
+   rebuilddb
79
+}
80
+
81
+function check_and_upgrade() {
82
+  if [ $FROM_VERSION == $TO_VERSION ]; then
83
+    echo "Your current version $FROM_VERSION is the latest version. Nothing to do."
84
+    exit
85
+  fi
86
+  check_deprecated
87
+  echo "You are about to upgrade PhotonOS from $FROM_VERSION to $TO_VERSION."
88
+  echo -n "Please backup your data before proceeding. Continue (y/n)?"
89
+  read
90
+  echo
91
+
92
+  case $REPLY in
93
+    [Yy]*)
94
+      update_solv_to_support_complex_deps
95
+      remove_unsupported_pkgs
96
+      rebuilddb
97
+      make_var_run_a_symlink
98
+      upgrade_photon_release
99
+      distro_upgrade
100
+      rebuilddb
101
+      ask_for_reboot
102
+      ;;
103
+    *) exit;;
104
+  esac
105
+}
106
+
107
+check_and_upgrade
0 108
new file mode 100644
... ...
@@ -0,0 +1,36 @@
0
+Summary:    Photon upgrade scripts
1
+Name:       photon-upgrade
2
+Version:    1.0
3
+Release:    1%{?dist}
4
+License:    Apache License
5
+Group:      System Environment/Base
6
+Source0:    photon-upgrade.sh
7
+URL:        https://vmware.github.io/photon/
8
+Vendor:     VMware, Inc.
9
+Distribution:   Photon
10
+BuildArch:  noarch
11
+Requires:   tdnf
12
+
13
+%description
14
+Photon major upgrade scripts. Addresses 2.0 to 3.0 upgrades.
15
+
16
+%prep
17
+
18
+%build
19
+
20
+%install
21
+mkdir -p %{buildroot}%{_bindir}
22
+install -m755 %{SOURCE0} %{buildroot}%{_bindir}
23
+
24
+%post
25
+
26
+%clean
27
+rm -rf $RPM_BUILD_ROOT
28
+
29
+%files
30
+%defattr(-,root,root,-)
31
+%{_bindir}/*
32
+
33
+%changelog
34
+*       Fri Oct 19 2018 Dweep Advani <dadvani@vmware.com> 1.0-1
35
+-       Initial Photon 2.0 to 3.0 upgrade package