1
1
#! /bin/bash
2
2
# Copyright (C) 2019 Intel Corporation.
3
3
# SPDX-License-Identifier: BSD-3-Clause
4
- # This script is aim to setup or upgrade sos & uos automatically.
4
+ #
5
+ # This script is aim to quick setup sos and uos automatically.
6
+ # You can also use this to upgrade sos with a specified clear linux version.
7
+ # Also you should know that system may have boot problems once the script is running failed
8
+ # since it will modify various system parameters with full root access.
9
+ #
10
+ # Usages:
11
+ # Upgrade sos to 28100
12
+ # sudo <script> -t 28100
13
+ # Upgrade sos to 28100 with specified proxy server
14
+ # sudo <script> -t 28100 -p <your proxy server>:<port>
15
+ # Upgrade uos to 28100 with specified proxy server
16
+ # sudo <script> -t 28100 -p <your proxy server>:<port> -u
17
+ # Upgrade uos to 28100 without downloading uos image, you should put uos image in /root directory previously.
18
+ # sudo <script> -t 28100 -u -s
5
19
6
- # switch for download uos function
7
- skip_download_uos=0
8
- # turn on if you need to setup uos
9
- upgrade_uos=0
10
20
11
21
function print_help()
12
22
{
13
23
echo " Usage:"
14
24
echo " Launch this script as: sudo $0 -t 28100"
15
25
echo -e " \t-t to specify clear linux version for upgrading"
16
- echo " -p to specify a proxy server"
17
- echo " -m to use swupd mirror url"
18
- echo " -u to upgrade uos, if you just upgrade sos using this script, you'd better to manually reboot sos then continue to use this function ."
19
- echo " -s, skip downloading uos; if enabled, you have to download uos img firstly before upgrading, default is off"
26
+ echo -e " \t -p to specify a proxy server"
27
+ echo -e " \t -m to use swupd mirror url"
28
+ echo -e " \t -u to upgrade UOS ."
29
+ echo -e " \t -s, skip downloading uos; if enabled, you have to download uos img firstly before upgrading, default is off"
20
30
exit 1
21
31
}
22
32
33
+ # switch for download uos function
34
+ skip_download_uos=0
35
+ # turn on if you need to setup uos
36
+ upgrade_uos=0
37
+
38
+ # acrn.conf path
39
+ acrn_conf_path=/usr/share/acrn/samples/nuc/acrn.conf
40
+ # acrn.efi path
41
+ acrn_efi_path=/usr/lib/acrn/acrn.efi
42
+
23
43
function upgrade_sos()
24
44
{
25
- # setup mirror, proxy env if specified parameters to p & m opt.
26
- swupd mirror -u
45
+ # setup mirror and proxy url while specified with m and p options
27
46
if [[ -n $mirror ]]; then
28
- echo " Add swupd mirror... "
47
+ echo " Setting swupd mirror to: $mirror "
29
48
swupd mirror -s $mirror
30
49
fi
31
- unset https_proxy
32
50
if [[ -n $proxy ]]; then
33
- echo " Add proxy... "
51
+ echo " Setting proxy to: $proxy "
34
52
export https_proxy=$proxy
35
53
fi
36
- echo " disable auto update..."
54
+
55
+ # get partitions
56
+ type_efi=EFI\ System
57
+ partition_number=` fdisk -l | grep " $type_efi " | awk -F' ' ' {print $1}' | wc -l`
58
+ if [ $partition_number != " 1" ]; then
59
+ echo " Multiple partitions detected."
60
+ c=0
61
+ for i in ` fdisk -l | grep " $type_efi " | awk -F' ' ' {print $1}' ` ; do
62
+ if [[ ! -z $efi_partition ]]; then break ; fi
63
+ c=$(( c+ 1 ))
64
+ echo " $c . $i "
65
+ while true ; do
66
+ read -p " Do you wish to setup on this partition ? (Y/N)" yn
67
+ case $yn in
68
+ [Yy]* ) efi_partition=$i ; break ;;
69
+ [Nn]* ) break ;;
70
+ * ) echo " Please input yes or no." ;;
71
+ esac
72
+ done
73
+ done
74
+ else
75
+ efi_partition=` fdisk -l | grep " $type_efi " | awk -F' ' ' {print $1}' `
76
+ fi
77
+
78
+ if [[ -z $efi_partition ]]; then echo " You didn't choose a partition, please try it again." ; exit 1; fi
79
+ efi_mount_point=` findmnt $efi_partition -n | cut -d' ' -f1`
80
+ root_partition=` echo $efi_partition | sed ' s/[0-9]$/3/g' `
81
+ partition=` echo $efi_partition | sed ' s/[0-9]$//g' `
82
+ # unmount efi partition if it's already mounted
83
+ if [[ -n $efi_mount_point ]]; then
84
+ echo " Unmount EFI partition: $efi_mount_point ..."
85
+ umount $efi_mount_point
86
+ fi
87
+
88
+ echo " Disable auto update..."
37
89
swupd autoupdate --disable
38
90
39
91
# Compare with current clear linux and skip upgrade sos if get the same version.
40
- if [[ $( echo -e ` swupd info` | cut -d' ' -f3) -eq $target_version ]]; then
41
- echo " Specified to the same clear linux version, continue to setup sos env."
92
+ source /etc/os-release
93
+ if [[ $VERSION_ID -eq $target_version ]]; then
94
+ echo " Specify with the same clear linux version, continue to setup sos..."
42
95
else
43
96
echo " Upgrade clear linux version to : $target_version ..."
44
97
swupd verify --fix --picky -m $target_version
@@ -49,16 +102,24 @@ if [[ $? -eq 0 ]]; then
49
102
echo " Add service-os kernel-iot-lts2018 bundle"
50
103
swupd bundle-add service-os kernel-iot-lts2018
51
104
52
- echo " mount /dev/sda1 to /mnt"
53
- mount /dev/sda1 /mnt
54
-
105
+ mount $efi_partition /mnt
55
106
echo " Add /mnt/EFI/acrn folder"
56
107
mkdir -p /mnt/EFI/acrn
57
- echo " Copy /usr/share/acrn/samples/nuc/acrn.conf /mnt/loader/entries/"
58
- cp -r /usr/share/acrn/samples/nuc/acrn.conf /mnt/loader/entries/
59
- echo " Copy acrn.efi to /mnt/EFI/acrn"
60
- cp -r /usr/lib/acrn/acrn.efi /mnt/EFI/acrn/
61
-
108
+ echo " Copy $acrn_conf_path /mnt/loader/entries/"
109
+ if [[ ! -f $acrn_conf_path ]]; then
110
+ echo " Missing acrn.conf file in folder: $acrn_conf_path "
111
+ umount /mnt && sync
112
+ exit 1
113
+ fi
114
+ cp -r $acrn_conf_path /mnt/loader/entries/
115
+ if [[ $? -ne 0 ]]; then echo " You didn't choose an right EFI partition." && exit 1; fi
116
+ echo " Copy $acrn_efi_path to /mnt/EFI/acrn"
117
+ if [[ ! -f $acrn_efi_path ]]; then
118
+ echo " Missing acrn.efi file in folder: $acrn_efi_path "
119
+ umount /mnt && sync
120
+ exit 1
121
+ fi
122
+ cp -r $acrn_efi_path /mnt/EFI/acrn/
62
123
echo " Check ACRN efi boot event"
63
124
check_acrn_bootefi=` efibootmgr | grep ACRN`
64
125
if [[ " $check_arcn_bootefi " -ge " ACRN" ]]; then
@@ -73,22 +134,22 @@ if [[ $? -eq 0 ]]; then
73
134
fi
74
135
75
136
echo " Add new ACRN efi boot event"
76
- efibootmgr -c -l " \EFI\acrn\acrn.efi" -d /dev/sda -p 1 -L " ACRN"
137
+ efibootmgr -c -l " \EFI\acrn\acrn.efi" -d $partition -p 1 -L " ACRN"
77
138
78
139
echo " Create loader.conf"
79
- rm /mnt/loader/loader.conf && touch /mnt/loader/loader.conf
140
+ mv /mnt/loader/loader.conf /mnt/loader/loader.conf.bck && touch /mnt/loader/loader.conf
80
141
echo " Add default boot wait time"
81
142
echo " timeout 5" > /mnt/loader/loader.conf
82
143
echo " Add default boot to ACRN"
83
144
echo " default acrn" >> /mnt/loader/loader.conf
84
145
85
- echo " Getting latest Service OS kernel version: "
86
146
new_kernel=` ls /mnt/EFI/org.clearlinux/* sos* -tl | grep kernel | head -n1 | awk -F' /' ' {print $5}' `
87
- echo " Get current sos kernel from acrn.conf file: "
147
+ echo " Getting latest Service OS kernel version: $new_kernel "
88
148
cur_kernel=` cat /mnt/loader/entries/acrn.conf | sed -n 2p | cut -d' /' -f4`
149
+ echo " Getting current Service OS kernel version: $cur_kernel "
89
150
90
- echo " Replace root uuid from acrn.conf"
91
- sed -i " s/<UUID of rootfs partition>/` blkid -s PARTUUID -o value /dev/sda3 ` /g" /mnt/loader/entries/acrn.conf
151
+ echo " Replacing root partition uuid in acrn.conf"
152
+ sed -i " s/<UUID of rootfs partition>/` blkid -s PARTUUID -o value $root_partition ` /g" /mnt/loader/entries/acrn.conf
92
153
93
154
if [[ " $cur_kernel " == " $new_kernel " ]]; then
94
155
echo " No need to replace kernel conf info"
@@ -97,68 +158,77 @@ if [[ $? -eq 0 ]]; then
97
158
sed -i " s/$cur_kernel /$new_kernel /g" /mnt/loader/entries/acrn.conf
98
159
fi
99
160
100
- echo " Sos process done!"
101
- echo " ***** Please reboot device to test on new sos. ***** "
161
+ echo " Service OS setup done!"
162
+ echo " Rebooting Service OS to taking effect changes. "
102
163
else
103
164
echo -e " Fail to upgrade sos $target_clearlinux from mirror url."
104
165
fi
105
166
106
- echo " Init swupd mirror & proxy"
107
- swupd mirror -u
108
- unset https_proxy
109
167
umount /mnt
168
+ sync
169
+ reboot
110
170
}
111
171
112
172
function upgrade_uos()
113
173
{
114
- # Add proxy if you need to download uos img automatically.
174
+ # UOS download link
175
+ uos_image_link=" https://download.clearlinux.org/releases/$target_version /clear/clear-$target_version -kvm.img.xz"
176
+
177
+ # Set proxy if needed.
115
178
if [[ -n $proxy ]]; then
116
- echo " Add proxy... "
179
+ echo " Setting proxy to: $proxy "
117
180
export https_proxy=$proxy
118
181
fi
119
182
183
+ if [[ ! -z ` findmnt /mnt -n` ]]; then umount /mnt; fi
184
+
120
185
# Do upgrade uos process.
121
186
if [[ $skip_download_uos == 1 ]]; then
122
- uos_img_xz_path =$( find ~ / -name clear-$target_version -kvm.img.xz)
123
- uos_img_path =$( find ~ / -name clear-$target_version -kvm.img)
124
- if [[ ! -f $uos_img_xz_path ]] && [[ ! -f $uos_img_path ]]; then
125
- echo " You should download uos clear-$target_version -kvm.img.xz file firstly." && exit
187
+ uos_img_xz =$( find ~ / -name clear-$target_version -kvm.img.xz)
188
+ uos_img =$( find ~ / -name clear-$target_version -kvm.img)
189
+ if [[ ! -f $uos_img_xz ]] && [[ ! -f $uos_img ]]; then
190
+ echo " You should download uos clear-$target_version -kvm.img.xz file firstly." && exit 1
126
191
fi
127
- if [[ -f $uos_img_xz_path ]]; then
128
- echo " get uos xz file in : $uos_img_xz_path "
129
- unxz $uos_img_xz_path
130
- uos_img_path= $( find ~ / -name clear- $target_version -kvm.img )
192
+ if [[ -f $uos_img_xz ]]; then
193
+ echo " Unxz uos file: $uos_img_xz "
194
+ unxz $uos_img_xz
195
+ uos_img= ` echo $uos_img_xz | sed ' s/.xz$//g ' `
131
196
fi
132
- echo " get uos img file in : $uos_img_path "
197
+ echo " get uos img file: $uos_img "
133
198
if [[ $? -eq 0 ]]; then
134
- losetup -f -P --show $uos_img_path
199
+ uos_partition= ` losetup -f -P --show $uos_img ` p3
135
200
else
136
201
echo " fail to losetup uos img, please check uos img status" && exit 1
137
202
fi
138
- mount /dev/loop0p3 /mnt
203
+ mount $uos_partition /mnt
139
204
cp -r /usr/lib/modules/" ` readlink /usr/lib/kernel/default-iot-lts2018 | awk -F ' 2018.' ' {print $2}' ` .iot-lts2018" /mnt/lib/modules
140
- umount /mnt
141
- sync
142
205
else
143
206
cd ~
144
- curl https://download.clearlinux.org/releases/$target_version /clear/clear-$target_version -kvm.img.xz -o clear-$target_version -kvm.img.xz
207
+ echo " Downloading UOS image: $uos_image_link "
208
+ curl $uos_image_link -o clear-$target_version -kvm.img.xz
209
+ uos_img=clear-$target_version -kvm.img
210
+ if [[ -f $uos_img ]] && [[ -f $uos_img .xz ]]; then echo " Moving $uos_img to $uos_img .old." ; mv $uos_img $uos_img .old; fi
145
211
if [[ $? -eq 0 ]]; then
212
+ echo " Unxz UOS image: clear-$target_version -kvm.img.xz"
146
213
unxz clear-$target_version -kvm.img.xz
147
214
fi
148
215
if [[ $? -eq 0 ]]; then
149
- losetup -f -P --show clear-$target_version -kvm.img
216
+ uos_partition=` losetup -f -P --show $uos_img ` p3
217
+ else
218
+ echo " Missing UOS file: $uos_img , please check if UOS is exist." && exit 1
150
219
fi
151
- mount /dev/loop0p3 /mnt
220
+ mount $uos_partition /mnt
152
221
cp -r /usr/lib/modules/" ` readlink /usr/lib/kernel/default-iot-lts2018 | awk -F ' 2018.' ' {print $2}' ` .iot-lts2018" /mnt/lib/modules
153
- umount /mnt
154
- sync
155
222
fi
156
- uos_img_path=$( find ~ / -name clear-$target_version -kvm.img)
223
+ umount /mnt
224
+ losetup -D
225
+ sync
226
+
157
227
cp -r /usr/share/acrn/samples/nuc/launch_uos.sh ~ /
158
- sed -i " s/\(virtio-blk.*\)\/home\/clear\/uos\/uos.img/\1$( echo $uos_img_path | sed " s/\//\\\\ \//g" ) /" ~ /launch_uos.sh
159
- echo " Upgrade uos done..."
228
+ sed -i " s/\(virtio-blk.*\)\/home\/clear\/uos\/uos.img/\1$( echo $uos_img | sed " s/\//\\\\ \//g" ) /" ~ /launch_uos.sh
229
+ echo " Upgrade UOS done..."
160
230
echo " Now you can run below command to start UOS..."
161
- echo " # cd ~/ && ./launch_uos.sh -V 1 "
231
+ echo " # cd ~/ && ./launch_uos.sh"
162
232
}
163
233
164
234
# Set script options.
@@ -193,14 +263,14 @@ if [[ `echo $target_version | awk '{print length($0)}'` -ne 5 ]]; then
193
263
fi
194
264
195
265
if [[ $upgrade_uos == 1 ]]; then
196
- echo " Start upgrading uos to: $target_version ..."
266
+ echo " Upgrading UOS to: $target_version ..."
197
267
upgrade_uos
198
268
exit
199
269
fi
200
270
201
- # Exit script if you specified an newer clear linux ver .
271
+ # Exit script if you specified an newer clear linux version .
202
272
if [[ $( echo -e ` swupd info` | cut -d' ' -f3) -gt $target_version ]]; then
203
- echo -e ' No need to upgrade sos .' && exit
273
+ echo -e ' No need to upgrade Service OS .' && exit
204
274
else
205
275
upgrade_sos
206
276
exit
0 commit comments