Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
Rebase (and rework) on #22
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbowes committed May 18, 2018
1 parent 5fa44ef commit 0d680b2
Showing 1 changed file with 52 additions and 12 deletions.
64 changes: 52 additions & 12 deletions platform-upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ set -euo pipefail
main() {
create_cert_file
set_exit_trap
initialize
process_cmd_line "$@"
initialize
check_kernel_version
create_temp_dir
download_latest_platform
Expand Down Expand Up @@ -81,33 +81,73 @@ fail() {
exit 1
}

initialise() {
local host=https://us-east.manta.joyent.com
local latest_path
latest_path=$(_curl "$host/Joyent_Dev/public/SmartOS/latest")
version="${latest_path##*/}"
platform_file="platform-$version.tgz"
platform_dir="platform-$version"
platform_url="$host$latest_path/$platform_file"
md5sums_url="$host$latest_path/md5sums.txt"
function usage() {
cat <<- "USAGE"
$ platform-upgrade [-u URL -s MD5SUM_URL] [-f]
OPTIONS:
-u URL : Remote/local url of platform-version.tgz file
-s MD5SUM_URL : Remote/local url of md5 checksum file
-f : Force installation if version is already present
EXAMPLE:
# Use default Joyent URL for latest platform image
platform-upgrade
# Use local platform and checksum file
platform-upgrade -u file:///tmp/platform-20180510T153535Z.tgz -s file:///tmp/md5sum.txt
USAGE
exit -1

}

process_cmd_line() {

force="false"
local OPTIND option
while getopts :f option; do
while getopts :fu:s: option; do
case "$option" in
u)
platform_url="$OPTARG"
;;
s)
md5sums_url="$OPTARG"
;;
f)
force="true"
;;
\?)
fail "Invalid option: -$OPTARG"
usage
;;
esac
done
shift $((OPTIND-1))

boot_device="${1:-}"

}

initialize() {

if [[ -n $platform_url ]] && [[ ! -n $md5sums_url ]]; then
usage
fi

if [[ ! -n $platform_url ]]; then
local host latest_path
host=https://us-east.manta.joyent.com
latest_path="${host}$(_curl "$host/Joyent_Dev/public/SmartOS/latest")"
version="$(expr "$latest_path" : '.*\([0-9]\{8\}T[0-9]\{6\}Z\).*')"
platform_url="$latest_path/platform-$version.tgz"
if [[ ! -n $md5sums_url ]]; then
md5sums_url="$latest_path/md5sums.txt"
fi
else
version="$(expr "$platform_url" : '.*\([0-9]\{8\}T[0-9]\{6\}Z\).*')"
fi

platform_file="platform-$version.tgz"
platform_dir="platform-$version"

}

check_kernel_version() {
Expand Down

0 comments on commit 0d680b2

Please sign in to comment.