diff --git a/.travis.yml b/.travis.yml index 8916a91..56fa3b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ -language: bash -addons: - apt: - sources: - - debian-sid # Grab ShellCheck from the Debian repo - packages: - - shellcheck +sudo: required +dist: trusty +before_install: + - sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse' + - sudo apt-get update -q + - sudo apt-get install shellcheck -y script: shellcheck -e SC2086 -s bash create-lx-image create-manifest install diff --git a/README.md b/README.md index 7db9816..da50464 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Debian lx-brand Image Builder -[![Build Status](https://travis-ci.org/joyent/debian-lx-brand-image-builder.svg?branch=master)](https://travis-ci.org/joyent/debian-lx-brand-image-builder) (shecllcheck) +[![Build Status](https://travis-ci.org/joyent/debian-lx-brand-image-builder.svg?branch=master)](https://travis-ci.org/joyent/debian-lx-brand-image-builder) (shellcheck) This is a collection of scripts used for creating an lx-brand Debian image. diff --git a/create-lx-image b/create-lx-image index 3a43d27..9ceac52 100755 --- a/create-lx-image +++ b/create-lx-image @@ -26,7 +26,7 @@ cat < -k -m -i -d -u + $0 -t -k -m -i -d [-u ] Example: $0 -t /var/tmp/lx-debian-7-20150408.tar.gz -k 3.13.0 -m 20150316T201553Z -i lx-debian-7 -d "Debian 7 64-bit lx-brand image." -u https://docs.joyent.com/images/container-native-linux @@ -37,21 +37,35 @@ OPTIONS: -m The minimum platform required for the image -i The name of the image as it would appear in the manifest -d The description of the image as it would appear in the manifest - -u The homepage link of the image as it would appear in the manifest + -u The homepage link of the image as it would appear in the manifest [optional] -h Show this message EOF } -while getopts "ht:k:m:i:d:u:" OPTION +while getopts "ht:k:m:i:d:u:?" OPTION do case $OPTION in - h) + h|\?) usage - exit 1 + exit ;; t) TARBALL=${OPTARG} + + [ ! -e "$TARBALL" ] && echo "==> ERROR: ${TARBALL}: file or directory not found" && exit 1 + [ ! -f "$TARBALL" ] && echo "==> ERROR: $TARBALL must be a file" && exit 1 + [ ! -r "$TARBALL" ] && echo "==> ERROR: $TARBALL is not readable" && exit 1 + [ "${TARBALL:0:1}" != "/" ] && echo "==> ERROR: the pathname '$TARBALL' specified to '-t' must be absolute" && exit 1 + + filetype=$(LC_ALL=C file -b "$TARBALL" 2> /dev/null) + case "$filetype" in + gzip*) gtaropts="-xzf" ;; + bzip2*) gtaropts="-xjf" ;; + compressed*) gtaropts="-xZf" ;; + USTAR*) gtaropts="-xf" ;; + *) echo "==> ERROR: $TARBALL must be a gzip, bzip2, .Z, or uncompressed tar archive." && exit 1 ;; + esac ;; k) KERNEL=${OPTARG} @@ -68,82 +82,20 @@ do u) DOCS=${OPTARG} ;; - ?) - usage - exit - ;; esac done -if [[ -z $TARBALL ]]; then - echo "==> ERROR: the install archive is required" +if [[ -z "$TARBALL" || -z "$KERNEL" || -z "$MIN_PLATFORM" || \ + -z "$IMAGE_NAME" || -z "$DESC" ]] ; then + printf 'FATAL: -t, -k, -m, -i, and -d options are all required.\n' usage exit 1 fi -if [[ ! -a "$TARBALL" ]]; then - printf "==> ERROR: %s: file or directory not found\n" $TARBALL - exit 1 -fi - -if [[ "$(echo $TARBALL | cut -c 1)" != "/" ]]; then - printf "==> Pathname '%s' specified to -t must be absolute\n" $TARBALL - exit 1 -fi - -if [[ ! -r "$TARBALL" ]]; then - printf "==> Cannot read file '%s'\n" $TARBALL - exit 1 -fi - -if [[ ! -f "$TARBALL" ]]; then - echo "==> ERROR: must be a gzip, bzip2, .Z or uncompressed tar archive" - exit 1 -fi - -if [[ -z ${KERNEL} ]]; then - echo "Error: missing kernel version (-k) value" - exit 1 -fi - -if [[ -z ${MIN_PLATFORM} ]]; then - echo "Error: missing minimum platform (-m) value" - exit 1 -fi - -if [[ -z ${IMAGE_NAME} ]]; then - echo "Error: missing image name (-i) value" - exit 1 -fi - -if [[ -z ${DESC} ]]; then - echo "Error: missing image description (-d) value" - exit 1 -fi - -if [[ -z ${DOCS} ]]; then - DOCS="https://docs.joyent.com/images/container-native-linux" -fi +[ -z "$DOCS" ] && DOCS="https://docs.joyent.com/images/container-native-linux" IUUID=${IMAGE_NAME}-$BUILD_DATE -filetype=$({ LC_ALL=C file $TARBALL | awk '{print $2}' ; } 2>/dev/null) - -if [[ "$filetype" = "gzip" ]]; then - gtaropts="-xz" -elif [[ "$filetype" = "bzip2" ]]; then - gtaropts="-xj" -elif [[ "$filetype" = "compressed" ]]; then - gtaropts="-xZ" -elif [[ "$filetype" = "USTAR" ]]; then - gtaropts="-x" -else - printf "==> ERROR: must be a gzip, bzip2, .Z or uncompressed tar archive" - exit 1 -fi - -gtaropts="${gtaropts}f" - zpath="/zones/$IUUID" zroot="/zones/$IUUID/root" @@ -164,8 +116,7 @@ create_dataset() { install_tar() { echo "==> Installing the tar archive, this will take a few minutes..." - ( cd "$zroot" && gtar --strip-components=2 "$gtaropts" "$TARBALL" ) - if [[ "$?" -ne "0" ]] ; then + if [[ ! $(cd "$zroot" && gtar --strip-components=2 "$gtaropts" "$TARBALL") ]] ; then echo "==> Error: extraction from tar archive failed." zfs destroy -r zones/$IUUID fi diff --git a/create-manifest b/create-manifest index 080332d..98f5ceb 100755 --- a/create-manifest +++ b/create-manifest @@ -47,7 +47,6 @@ Example: $0 -f debian-7-20150319.zfs.gz -k 3.4.105 -m 20150316T201553Z -n lx-debian-7 -v 20150319 USAGE - exit 1 } while getopts d:f:k:m:n:o:v:h:? OPTION @@ -79,6 +78,7 @@ do ;; \?) usage + exit ;; esac done @@ -86,6 +86,7 @@ done if [[ -z ${filename} || -z ${kernel} || -z ${min_platform} || -z ${name} || -z ${version} ]]; then echo "FATAL: All of -f, -k, -m, -n and -v are required." usage + exit 1 fi if [[ -z ${description} ]]; then @@ -103,6 +104,7 @@ fi if [[ ! -f ${filename} ]]; then echo "FATAL: ${filename} does not exist." usage + exit 1 fi shasum=$($SUM -x sha1 ${filename} | cut -d' ' -f1) diff --git a/install b/install index 3b28e23..151410c 100755 --- a/install +++ b/install @@ -22,7 +22,7 @@ cat < -d -m -i -p -D -u + $0 -r -d -m -i -p -D [-u ] Example: $0 -r wheezy -d /data/chroot -m http://httpredir.debian.org/debian/ -i lx-debian-7 -p "Debian 7 LX Brand" -D "Debian 7 64-bit lx-brand image." -u https://docs.joyent.com/images/container-native-linux @@ -48,10 +48,10 @@ NAME= DESC= DOCS= -while getopts "hr:d:m:i:p:D:u:" OPTION +while getopts "hr:d:m:i:p:D:u:?" OPTION do case $OPTION in - h) + h|\?) usage exit ;; @@ -76,48 +76,20 @@ do u) DOCS=${OPTARG} ;; - \?) - usage - exit - ;; esac done -if [[ $# -eq 0 ]]; then +if [[ -z "$RELEASE" || "$INSTALL_DIR" || "$MIRROR" || "$IMAGE_NAME" || "$NAME" ]]; then + printf 'FATAL: -r, -d, -m, -i, and -p are all required.\n' usage exit 1 fi -if [[ -z ${RELEASE} ]]; then - echo "Error: missing release (-r) value" - exit 1 -fi - if [[ ! -e ${INSTALL_DIR} ]] ; then echo "Directory $INSTALL_DIR not found" exit 1 fi -if [[ -z ${INSTALL_DIR} ]]; then - echo "Error: missing install directory (-d) value" - exit 1 -fi - -if [[ -z ${MIRROR} ]]; then - echo "Error: missing mirror (-m) value" - exit 1 -fi - -if [[ -z ${IMAGE_NAME} ]]; then - echo "Error: missing image name (-i) value" - exit 1 -fi - -if [[ -z ${NAME} ]]; then - echo "Error: missing proper name (-p) value" - exit 1 -fi - TARGET="${IMAGE_NAME}-${BUILD_DATE}.tar.gz" if [[ -z ${DOCS} ]]; then