summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlizhuang <[email protected]>2021-10-19 11:06:29 +0800
committerlizhuang <[email protected]>2021-10-19 11:06:29 +0800
commit6531122db0b41a3d0f615f00041537e9c84e2879 (patch)
tree5daea7d2766f23246edaf4d047d7f22a11958f76
parent01f65eddce7cb7aaaf7a551ab86e0881d666bf6d (diff)
Upgrade the system version and create bin warehouse with updatesystem-upgrade
-rw-r--r--ansible/roles/system-upgrade/files/depository81
-rw-r--r--ansible/roles/system-upgrade/files/upgrade82
-rw-r--r--ansible/roles/system-upgrade/files/upgradepath.sh1
-rw-r--r--ansible/roles/system-upgrade/tasks/main.yml15
-rw-r--r--ansible/stage_one_deploy.yml3
-rwxr-xr-xinstaller/install.sh7
6 files changed, 188 insertions, 1 deletions
diff --git a/ansible/roles/system-upgrade/files/depository b/ansible/roles/system-upgrade/files/depository
new file mode 100644
index 00000000..58c61abc
--- /dev/null
+++ b/ansible/roles/system-upgrade/files/depository
@@ -0,0 +1,81 @@
+#!/usr/bin/env sh
+repo_path='/update/repo/user'
+bin_num=6
+
+function help(){
+ cat <<- EOF
+ Usage: repo [OPTION]... FILE... The file parameter can be null. The specific usage is as follows. File should be full path.
+
+ -h --help
+
+ -a --add repo -a file Add a new bin file to the warehouse and delete one. Keep the number of warehouse files to 5
+
+ -d --delete repo -d file Delete the specified bin file
+
+ -q --query repo -q Query all bin files in the warehouse
+
+ -e --eliminate repo -e Eliminate file,keep the last 5 bin files in the warehouse
+
+EOF
+ exit 0
+}
+
+function query(){
+content=`ls -thl $repo_path/|awk '{print $6,$7,$8,$5,$9}'`
+printf "\e[40;94m %s\n\e[0m" " date"" size"" name"
+IFS=$'\n'
+for line in $content;
+do
+ IFS=$IFS
+ arr=($line)
+ date=`echo $arr|cut -d ' ' -f1,2,3`
+ size=`echo $arr|cut -d ' ' -f4`
+ name=`echo $arr|cut -d ' ' -f5`
+ echo $date " $size" " $name"
+done;
+IFS=$IFS
+exit 0
+}
+
+function delete(){
+if [ ! $del_path ]; then
+ echo "This parameter cannot be empty"
+ exit 1
+else
+ rm -rf $del_path
+ exit 0
+fi
+}
+
+function eliminate(){
+ls -tQ $repo_path/*.bin| tail -n+$bin_num | xargs rm -f
+exit 0
+}
+
+function add(){
+if [ ! $bin_path ]; then
+ echo "This parameter cannot be empty"
+ exit 1
+else
+ cp -ar $bin_path $repo_path
+ eliminate
+ exit 0
+fi
+}
+
+
+while [ -n "$1" ];do
+ case $1 in
+ -a|--add) bin_path=$2 add
+ shift 2;;
+ -d|--delete) del_path=$2 delete
+ shift 2;;
+ -e|--eliminate) eliminate;;
+ -q|--query) query;;
+ -h|--help) help;;
+ --) shift;break;;
+ -*) echo "error: no such option $1."; exit 1;;
+ *) break;;
+ esac
+done
+
diff --git a/ansible/roles/system-upgrade/files/upgrade b/ansible/roles/system-upgrade/files/upgrade
new file mode 100644
index 00000000..0c7a712f
--- /dev/null
+++ b/ansible/roles/system-upgrade/files/upgrade
@@ -0,0 +1,82 @@
+#!/bin/bash
+#Scripts are used to automatically upgrade the system
+repo_path='/update/repo/user/'
+
+if [ `whoami` = "root" ];then
+ echo "Root user"
+else
+ echo "non-root user"
+ exit 1
+fi
+
+function help()
+{
+ cat <<- EOF
+ Usage: upgrade [OPTION]... [FILE]... or upgrade [OPTION]...[OPTION]...[FILE]... File should be full path
+
+ -h --help Print program help and exit
+
+ -p --path The path where the bin file needs to be executed
+
+ -f --force Ignore warning , never prompt
+EOF
+ exit 0
+}
+
+
+function warning(){
+ read -r -p "Next, the upgrade will be carried out. Please be careful. Enter y to continue and N to stop. [Y/n] " input
+
+ case $input in
+ [yY][eE][sS]|[yY])
+ mainpart
+ ;;
+ [nN][oO]|[nN])
+ echo "No"
+ exit 1
+ ;;
+ *)
+ echo "Invalid input..."
+ exit 1
+ ;;
+ esac
+}
+
+function mainpart(){
+ if [ -h '/data/onie-installer-x86_64.bin' ];then
+ rm -rf /data/onie-installer-x86_64.bin
+ (source ./depository -a $path)
+ else
+ (source ./depository -a $path)
+ fi
+ bin_name=`echo ${path##*/}`
+ echo $bin_name
+ ln -s $repo_path$bin_name /data/onie-installer-x86_64.bin
+ echo "After 10 seconds, the operating system will be reinstalled. If you need to stop, press Ctrl + C"
+ sleep 10s
+ rm -rf $path
+ onie-reboot-install
+}
+
+main(){
+ if [ "$force" == "-force" -o "$force" == "-f" ];then
+ mainpart
+ else
+ warning
+ fi
+}
+
+while [ -n "$1" ];do
+ case $1 in
+ -p|--path) path=$2
+ shift 2;;
+ -f|--force) force=$1
+ shift 1;;
+ -h|--help) help;;
+ --) shift;break;;
+ -*) echo "error: no such option $1."; exit 1;;
+ *) break;;
+ esac
+done
+
+main
diff --git a/ansible/roles/system-upgrade/files/upgradepath.sh b/ansible/roles/system-upgrade/files/upgradepath.sh
new file mode 100644
index 00000000..12226019
--- /dev/null
+++ b/ansible/roles/system-upgrade/files/upgradepath.sh
@@ -0,0 +1 @@
+export PATH=/opt/system-upgrade:$PATH
diff --git a/ansible/roles/system-upgrade/tasks/main.yml b/ansible/roles/system-upgrade/tasks/main.yml
new file mode 100644
index 00000000..0f1e59e5
--- /dev/null
+++ b/ansible/roles/system-upgrade/tasks/main.yml
@@ -0,0 +1,15 @@
+- name: "upgrade Script copy"
+ copy:
+ src: '{{ role_path }}/files/upgrade'
+ dest: /opt/system-upgrade/
+ mode: '0755'
+- name: "depository Script copy"
+ copy:
+ src: '{{ role_path }}/files/depository'
+ dest: /opt/system-upgrade/
+ mode: '0755'
+- name: "upgradepath Script copy"
+ copy:
+ src: '{{ role_path }}/files/upgradepath.sh'
+ dest: /etc/profile.d/
+ mode: '0755'
diff --git a/ansible/stage_one_deploy.yml b/ansible/stage_one_deploy.yml
index 41f7ae1d..829836e1 100644
--- a/ansible/stage_one_deploy.yml
+++ b/ansible/stage_one_deploy.yml
@@ -26,6 +26,7 @@
- {role: system-init, tags: system-init}
- {role: wannat_wangw, tags: wannat_wangw}
- {role: wire_graft, tags: wire_graft}
+ - {role: system-upgrade, tags: system-upgrade}
- hosts: 7400-MCN123-P01R01
remote_user: root
@@ -42,6 +43,7 @@
- {role: tsg_sn, tags: tsg_sn}
- {role: tfe, tags: tfe}
- {role: system-init, tags: system-init}
+ - {role: system-upgrade, tags: system-upgrade}
- hosts: 9000-NPB-P01R01
remote_user: root
@@ -74,3 +76,4 @@
- {role: wire_graft, tags: wire_graft}
- {role: nz-talon, tags: nz-talon}
- {role: tsg-os-provision-condition, tags: tsg-os-provision-condition}
+ - {role: system-upgrade, tags: system-upgrade}
diff --git a/installer/install.sh b/installer/install.sh
index 526e9d08..b2e2e32b 100755
--- a/installer/install.sh
+++ b/installer/install.sh
@@ -254,6 +254,11 @@ mount -t sysfs sys ${distro_mnt}/sys
cp -a ${blk_dev} ${distro_mnt}/${blk_dev}
cp -a ${random_dev} ${distro_mnt}/${random_dev}
+mkdir -p ${distro_mnt}/update
+mount -t ext4 /dev/sda${exp_part_tsg_os_update} ${distro_mnt}/update
+mkdir -p ${distro_mnt}/update/repo/user
+mkdir -p ${distro_mnt}/update/repo/factory
+
mkdir -p ${distro_mnt}/data
mount -t ext4 /dev/sda${exp_part_tsg_os_data} ${distro_mnt}/data
@@ -267,7 +272,7 @@ chroot ${distro_mnt} /distro-setup.sh ${distro_dev}
umount ${distro_mnt}/proc
umount ${distro_mnt}/sys
umount ${distro_mnt}/data
-
+umount ${distro_mnt}/update
# Install boot loader
echo "Install GRUB2 bootloader .."