From 0bb13002e91d474efbceb1282b604273dad99416 Mon Sep 17 00:00:00 2001 From: Drew Moseley Date: Fri, 11 Oct 2019 13:54:59 +0000 Subject: [PATCH] scripts: Refactor to support different Mender server options. This mirrors the way it is handled in Yocto with the demo server, the production server, and hosted mender. Signed-off-by: Drew Moseley Changelog: Title --- README.md | 19 ++++- .../bootstrap-rootfs-overlay-demo-server.sh | 77 ++++++++++++++++++ ...bootstrap-rootfs-overlay-hosted-server.sh} | 13 +-- ...tstrap-rootfs-overlay-production-server.sh | 80 +++++++++++++++++++ 4 files changed, 182 insertions(+), 7 deletions(-) create mode 100755 scripts/bootstrap-rootfs-overlay-demo-server.sh rename scripts/{bootstrap-rootfs-overlay-demo.sh => bootstrap-rootfs-overlay-hosted-server.sh} (81%) create mode 100755 scripts/bootstrap-rootfs-overlay-production-server.sh diff --git a/README.md b/README.md index 4eebd67..0a91241 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,25 @@ unzip 2019-06-20-raspbian-buster-lite.zip && cd .. Bootstrap the demo rootfs overlay that is configured to connect to https://hosted.mender.io with polling intervals set appropriately for -demonstration purposes: +demonstration purposes. There are three scripts here to support +the Mender demo server, the Mender production server, and hosted +Mender. ``` -./scripts/bootstrap-rootfs-overlay-demo.sh \ +./scripts/bootstrap-rootfs-overlay-demo-server.sh \ + --output-dir ${PWD}/rootfs_overlay_demo \ + --server-ip 192.168.1.1 +``` + +``` +./scripts/bootstrap-rootfs-overlay-production-server.sh \ + --output-dir ${PWD}/rootfs_overlay_demo \ + --server-url https://foobar.mender.io \ + [ --server-cert ~/server.crt ] +``` + +``` +./scripts/bootstrap-rootfs-overlay-hosted-server.sh \ --output-dir ${PWD}/rootfs_overlay_demo \ --tenant-token "Paste token from Hosted Mender" ``` diff --git a/scripts/bootstrap-rootfs-overlay-demo-server.sh b/scripts/bootstrap-rootfs-overlay-demo-server.sh new file mode 100755 index 0000000..21ffc77 --- /dev/null +++ b/scripts/bootstrap-rootfs-overlay-demo-server.sh @@ -0,0 +1,77 @@ +#!/bin/bash +# +# Copyright 2019 Northern.tech AS +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Exit if any command exits with a non-zero exit status. +set -o errexit + +root_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd ) +if [ "${root_dir}" != "${PWD}" ]; then + echo "You must execute $(basename $0) from the root directory: ${root_dir}" + exit 1 +fi + +server_ip="" +output_dir="" +while (( "$#" )); do + case "$1" in + -o | --output-dir) + output_dir="${2}" + shift 2 + ;; + -s | --server-ip) + server_ip="${2}" + shift 2 + ;; + *) + echo "Sorry but the provided option is not supported: $1" + echo "Usage: $(basename $0) --output-dir ./rootfs_overlay_demo --server-ip " + exit 1 + ;; + esac +done + +if [ -z "${output_dir}" ]; then + echo "Sorry, but you need to provide an output directory using the '-o/--output-dir' option" + exit 1 +fi +if [ -z "${server_ip}" ]; then + echo "Sorry, but you need to provide a server IP address using the '-s/--server-ip' option" + exit 1 +fi + +mkdir -p ${output_dir}/etc/mender +cat <<- EOF > ${output_dir}/etc/mender/mender.conf +{ + "InventoryPollIntervalSeconds": 5, + "RetryPollIntervalSeconds": 30, + "ServerURL": "https://docker.mender.io", + "ServerCertificate": "/etc/mender/server.crt", + "UpdatePollIntervalSeconds": 5 +} +EOF +cat <<- EOF > ${output_dir}/etc/hosts +127.0.0.1 localhost + +# The following lines are desirable for IPv6 capable hosts +::1 localhost ip6-localhost ip6-loopback +ff02::1 ip6-allnodes +ff02::2 ip6-allrouters + +${server_ip} docker.mender.io s3.docker.mender.io +EOF +wget -q "https://raw.githubusercontent.com/mendersoftware/mender/master/support/demo.crt" -O ${output_dir}/etc/mender/server.crt + +echo "Configuration file for using Demo Mender Server written to: ${output_dir}/etc/mender" diff --git a/scripts/bootstrap-rootfs-overlay-demo.sh b/scripts/bootstrap-rootfs-overlay-hosted-server.sh similarity index 81% rename from scripts/bootstrap-rootfs-overlay-demo.sh rename to scripts/bootstrap-rootfs-overlay-hosted-server.sh index 57bac6f..cd227f0 100755 --- a/scripts/bootstrap-rootfs-overlay-demo.sh +++ b/scripts/bootstrap-rootfs-overlay-hosted-server.sh @@ -23,9 +23,7 @@ if [ "${root_dir}" != "${PWD}" ]; then exit 1 fi -# Do not actually paste it here, this is just the default value that will -# end up in mender.conf if no token is specified using '--tenant-token' -tenant_token="Paste your Hosted Mender token here" +tenant_token="" output_dir="" while (( "$#" )); do case "$1" in @@ -39,7 +37,7 @@ while (( "$#" )); do ;; *) echo "Sorry but the provided option is not supported: $1" - echo "Usage: $(basename $0) --tenant-token" + echo "Usage: $(basename $0) --output-dir ./rootfs_overlay_demo --tenant-token " exit 1 ;; esac @@ -50,6 +48,11 @@ if [ -z "${output_dir}" ]; then exit 1 fi +if [ -z "${tenant_token}" ]; then + echo "Sorry, but you need to provide a tenant token using the '-t/--tenant-token' option" + exit 1 +fi + mkdir -p ${output_dir}/etc/mender cat <<- EOF > ${output_dir}/etc/mender/mender.conf { @@ -61,4 +64,4 @@ cat <<- EOF > ${output_dir}/etc/mender/mender.conf } EOF -echo "Configuration file written to: ${output_dir}/etc/mender" +echo "Configuration file for using Hosted Mender written to: ${output_dir}/etc/mender" diff --git a/scripts/bootstrap-rootfs-overlay-production-server.sh b/scripts/bootstrap-rootfs-overlay-production-server.sh new file mode 100755 index 0000000..3d079b0 --- /dev/null +++ b/scripts/bootstrap-rootfs-overlay-production-server.sh @@ -0,0 +1,80 @@ +#!/bin/bash +# +# Copyright 2019 Northern.tech AS +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Exit if any command exits with a non-zero exit status. +set -o errexit + +root_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd ) +if [ "${root_dir}" != "${PWD}" ]; then + echo "You must execute $(basename $0) from the root directory: ${root_dir}" + exit 1 +fi + +server_url="" +output_dir="" +while (( "$#" )); do + case "$1" in + -o | --output-dir) + output_dir="${2}" + shift 2 + ;; + -s | --server-url) + server_url="${2}" + shift 2 + ;; + -S | --server-cert) + server_cert="${2}" + shift 2 + ;; + *) + echo "Sorry but the provided option is not supported: $1" + echo "Usage: $(basename $0) --output-dir ./rootfs_overlay_demo --server-url [--server-cert ]" + exit 1 + ;; + esac +done + +if [ -z "${output_dir}" ]; then + echo "Sorry, but you need to provide an output directory using the '-o/--output-dir' option" + exit 1 +fi + +if [ -z "${server_url}" ]; then + echo "Sorry, but you need to provide a server URL using the '-s/--server-url' option" + exit 1 +fi + +mkdir -p ${output_dir}/etc/mender +cat <<- EOF > ${output_dir}/etc/mender/mender.conf +{ + "InventoryPollIntervalSeconds": 5, + "RetryPollIntervalSeconds": 30, + "ServerURL": "${server_url}", +EOF + +if [ -n "${server_cert}" ] ; then +cat <<- EOF >> ${output_dir}/etc/mender/mender.conf + "ServerCertificate": "/etc/mender/server.crt", +EOF +cp -f "${server_cert}" ${output_dir}/etc/mender/server.crt +fi + +cat <<- EOF >> ${output_dir}/etc/mender/mender.conf + "UpdatePollIntervalSeconds": 5 +} +EOF + +echo "Configuration file for using Production Mender Server written to: ${output_dir}/etc/mender"