From 885baa97da68de023939093544607f2472f8100f Mon Sep 17 00:00:00 2001 From: Tatsuya Kitagawa Date: Sun, 31 May 2020 18:13:48 +0900 Subject: [PATCH] Squashed commit of the following: commit ef03350394e3c0670c2ba6d8a7495e21fcf790b9 Author: Tatsuya Kitagawa Date: Sun May 31 18:12:03 2020 +0900 Update README.md commit 6b6e190e695340095b79d688a5b0d8165eeba423 Author: Tatsuya Kitagawa Date: Sun May 31 18:11:56 2020 +0900 Move script commit f17fc0667d63f465d84201411b0e73c33c5f9881 Author: Tatsuya Kitagawa Date: Sun Oct 27 15:10:07 2019 +0900 Add fetch script --- README.md | 58 +++++--------- get-archlinux-cloud.sh | 168 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 186 insertions(+), 40 deletions(-) create mode 100755 get-archlinux-cloud.sh diff --git a/README.md b/README.md index 03b3db1..c22749f 100644 --- a/README.md +++ b/README.md @@ -11,31 +11,17 @@ An [Arch Linux](https://www.archlinux.org) cloud installation image. - Auto login disabled - Root password locked -The build process and E2E tests (using [QEMU](https://www.qemu.org/)) are run entirely on the Docker container. Therefore, it can be easily integrated with modern CI tools. - -## Prerequisites - -- Docker -- GNU Make -- KVM enabled Linux (optional but strongly recommended) - -## Getting started +## Get the latest release -### Build and test the ISO image +You can download the latest and past releases from [GitHub releases](https://github.com/t13a/archlinux-cloud/releases). -The following command generates the ISO image at `out/iso/archlinux-cloud-YYYY.mm.dd-x86_64.iso` then run all E2E tests. +Alternatively, if you have `bash`, `curl` and `jq` installed on your computer, you can get the latest release with the following command. ```sh -$ make init build test # or just simply `make` +$ curl -fsSL https://raw.githubusercontent.com/t13a/archlinux-cloud/master/get-archlinux-cloud.sh | sh ``` -To delete all generated files, run the following command. - -```sh -$ make clean -``` - -### Boot with cloud-init +## Boot with cloud-init Please refer to the [official documentation](https://cloudinit.readthedocs.io/) for a general explanation. @@ -60,35 +46,27 @@ bootcmd: ## Development -### Build the ISO image step-by-step +The build process and E2E tests (using [QEMU](https://www.qemu.org/)) are run entirely on the Docker container. Therefore, it can be easily integrated with modern CI tools. -```sh -$ make init -$ make build/exec -[build@xxxxxxxxxxxx build]$ make profile -[build@xxxxxxxxxxxx build]$ make repo -[build@xxxxxxxxxxxx build]$ make iso -[build@xxxxxxxxxxxx build]$ exit -``` +### Prerequisites -### Run QEMU with the ISO image +- Bash +- Docker +- GNU Make +- KVM enabled Linux (optional but strongly recommended) + +### Build and test the ISO image + +The following command generates the ISO image at `out/archlinux-cloud-YYYY.mm.dd-x86_64.iso` then run all E2E tests. ```sh -$ make test/exec -[test@xxxxxxxxxxxx test]$ make ssh-key -[test@xxxxxxxxxxxx test]$ make cidata -[test@xxxxxxxxxxxx test]$ qemu-daemon -[test@xxxxxxxxxxxx test]$ qemu-serial -[test@xxxxxxxxxxxx test]$ qemu-kill +$ make init build test # or just simply `make` ``` -or +To delete all generated files, run the following command. ```sh -$ make test/exec -[test@xxxxxxxxxxxx test]$ make ssh-key -[test@xxxxxxxxxxxx test]$ make cidata -[test@xxxxxxxxxxxx test]$ qemu-daemon -f # start in foreground +$ make clean ``` ## References diff --git a/get-archlinux-cloud.sh b/get-archlinux-cloud.sh new file mode 100755 index 0000000..b0c9f1c --- /dev/null +++ b/get-archlinux-cloud.sh @@ -0,0 +1,168 @@ +#!/usr/bin/env bash + +set -euo pipefail + +function cmd_iso() { + echo 'Fetching ISO...' >&2 + + local url="$(cmd_iso_url)" + + if [ "${OUTPUT}" == - ] + then + run_or_dryrun curl -L "${url}" + else + local output="${OUTPUT:-$(basename "${url}")}" + local part="${output}.part" + + if [ -e "${output}" ] + then + echo "${output}: Already exists" >&2 + exit 1 + fi + + run_or_dryrun curl -L "${url}" -o "${part}" + run_or_dryrun mv "${part}" "${output}" + fi +} + +function cmd_iso_url() { + echo "https://github.com/${SOURCE}/releases/download/${TAG}/archlinux-cloud-${ISO_VERSION}-x86_64.iso" +} + +function cmd_latest_iso_version() { + if [ -z "${ISO_VERSION}" ] + then + function func() { + curl -LSs "https://api.github.com/repos/${SOURCE}/releases/tags/${TAG}" \ + | jq -r '.assets[] | .name' \ + | grep -o '^archlinux-cloud-.*-x86_64\.iso$' \ + | sed -e 's/^archlinux-cloud-//g' -e 's/-x86_64\.iso$//g' \ + | sort \ + | tail -n1 + } + + echo 'Fetching latest ISO version...' >&2 + + local ret + + if ! ret="$(func)" || [ -z "${ret}" ] + then + echo 'Failed to get latest ISO version' >&2 + return 1 + fi + + ISO_VERSION="${ret}" + fi + + echo "${ISO_VERSION}" +} + +function cmd_latest_tag() { + if [ -z "${TAG}" ] + then + function func() { + curl -LSs "https://api.github.com/repos/${SOURCE}/releases/latest" \ + | jq -r '.tag_name' + } + + echo 'Fetching latest tag...' >&2 + + local ret + + if ! ret="$(func)" || [ "${ret}" == 'null' ] + then + echo 'Failed to get latest tag' >&2 + return 1 + fi + + TAG="${ret}" + fi + + echo "${TAG}" +} + +function help() { + cat << EOF +${0} [OPTION]... [TARGET] + +Options: + -h show help + -n dry run + -o OUTPUT specify output filename (default: basename of ISO) + -s SOURCE specify source repository (default: '${SOURCE}') + -t TAG specify tag (default: latest) + -v ISO_VERSION specify ISO version (default: latest) + +Targets: + iso (default) + iso-url + latest-iso-version + latest-tag +EOF +} + +function run_or_dryrun() { + if [ -z "${DRYRUN}" ] + then + "${@}" + else + echo '[DRYRUN]' "${@}" >&2 + fi +} + +DRYRUN= +ISO_VERSION= +OUTPUT= +SOURCE=t13a/archlinux-cloud +TAG= +TARGET= + +while getopts hno:s:t:v: OPT +do + case "${OPT}" in + h) + help + exit 0 + ;; + n) + DRYRUN=yes + ;; + o) + OUTPUT="${OPTARG}" + ;; + s) + SOURCE="${OPTARG}" + ;; + t) + TAG="${OPTARG}" + ;; + v) + ISO_VERSION="${OPTARG}" + ;; + *) + exit 1 + ;; + esac +done + +shift $((${OPTIND} - 1)) + +if [ -z "${TAG}" ] +then + if ! TAG="$(cmd_latest_tag)" + then + exit 1 + fi +fi + +if [ -z "${ISO_VERSION}" ] +then + if ! ISO_VERSION="$(cmd_latest_iso_version)" + then + exit 1 + fi +fi + +TARGET="${1:-iso}" + +"cmd_${TARGET//-/_}"