mirror of
https://github.com/rancher/os.git
synced 2025-08-27 02:39:18 +00:00
58 lines
1.5 KiB
Plaintext
58 lines
1.5 KiB
Plaintext
|
#!/bin/bash
|
||
|
set -e -x
|
||
|
|
||
|
gateway_address="http://ros.rancher.io/gateway"
|
||
|
|
||
|
_sigProcess() {
|
||
|
echo "SIGINT/SIGTERM signal..."
|
||
|
kill -9 $$
|
||
|
}
|
||
|
|
||
|
trap _sigProcess SIGINT SIGKILL SIGTERM
|
||
|
|
||
|
__read_policy() {
|
||
|
policy=`ros c get rancher.upgrade.policy`
|
||
|
if [ -z $policy ]; then
|
||
|
echo "can not read upgrade.policy"
|
||
|
exit 1
|
||
|
fi
|
||
|
return $(($policy))
|
||
|
}
|
||
|
|
||
|
__report_activity() {
|
||
|
arch=`uname -m`
|
||
|
uuid=`cat /sys/class/dmi/id/product_uuid`
|
||
|
release=`ros -v | awk '{print $2}'`
|
||
|
response=`wget --server-response ${gateway_address}/report --header 'Accept: application/json' --header 'Content-type: application/json' --header "arch: $arch" --header "uuid: $uuid" --header "release: $release" 2>&1 | awk '/^ HTTP/{print $2}'`
|
||
|
if [ $response -ge 200 -a $response -le 300 ]; then
|
||
|
echo "report activity success"
|
||
|
else
|
||
|
echo "report activity failed"
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
__upgrade_operate() {
|
||
|
recommend_version=`wget ${gateway_address}/version -q -O -`
|
||
|
case $policy in
|
||
|
download)
|
||
|
echo "upgrade.policy is 'download'"
|
||
|
__report_activity
|
||
|
system-docker pull $recommend_version
|
||
|
;;
|
||
|
auto)
|
||
|
echo "upgrade.policy is 'auto'"
|
||
|
__report_activity
|
||
|
ros os upgrade -i $recommend_version -f
|
||
|
;;
|
||
|
none)
|
||
|
echo "upgrade.policy is 'none'"
|
||
|
;;
|
||
|
*)
|
||
|
echo "upgrade.policy is 'illegal'"
|
||
|
;;
|
||
|
esac
|
||
|
}
|
||
|
|
||
|
__read_policy
|
||
|
|
||
|
__upgrade_operate
|