#!/bin/bash set -e -x SCRIPTS_DIR=$(dirname ${0}) . "${SCRIPTS_DIR}/build.conf" VERSION=${VERSION:?"VERSION not set"} while getopts "i:f:c:d:t:r:o:p:ka:" OPTION do case ${OPTION} in i) DIST="$OPTARG" ;; f) FILES="$OPTARG" ;; c) CLOUD_CONFIG="$OPTARG" ;; d) DEVICE="$OPTARG" ;; o) OEM="$OPTARG" ;; p) PARTITION="$OPTARG" ;; r) ROLLBACK_VERSION="$OPTARG" ;; k) KEXEC=y ;; a) APPEND="$OPTARG" ;; t) ENV="$OPTARG" ;; *) exit 1 ;; esac done [[ "$ARCH" == "arm" && "$ENV" != "rancher-upgrade" ]] && ENV=arm DIST=${DIST:-/dist} CLOUD_CONFIG=${CLOUD_CONFIG:-"${SCRIPTS_DIR}/conf/empty.yml"} CONSOLE=tty0 BASE_DIR="/mnt/new_img" # TODO: Change this to a number so that users can specify. # Will need to make it so that our builds and packer APIs remain consistent. PARTITION=${PARTITION:=${DEVICE}1} device_defined() { if [[ -z "$1" ]]; then echo "Need to Pass a device name -d ." 1>&2 exit 1 fi } format_device() { device_defined ${DEVICE} mkfs.ext4 -F -i 4096 -L RANCHER_STATE ${PARTITION} } mount_device() { local label=RANCHER_STATE local raw="${1:-false}" mkdir -p ${BASE_DIR} if [ "$(lsblk -o label|grep RANCHER_BOOT | wc -l)" -gt "0" ]; then label=RANCHER_BOOT fi local mount_opts="-L ${label}" if [ "${raw}" == "true" ]; then device_defined ${DEVICE} mount_opts=${PARTITION} fi mount ${mount_opts} ${BASE_DIR} trap "umount ${BASE_DIR}" EXIT } create_boot_dirs() { mkdir -p ${BASE_DIR}/boot/grub } install_grub() { grub-install --boot-directory=${BASE_DIR}/boot ${DEVICE} } grub2_config(){ local grub_cfg=${BASE_DIR}/boot/grub/grub.cfg local append_line="${1}" cat >${grub_cfg} <>${grub_cfg} < ${grub_file}<> ${grub_file}<&2 exit 1 ;; esac fi grub2_config "${KERNEL_ARGS}" pvgrub_config "${KERNEL_ARGS}" install_rancher if [ "$KEXEC" = "y" ]; then if [ "$APPEND" = "" ]; then APPEND=$(cat /proc/cmdline) fi kexec -l ${DIST}/vmlinuz --initrd=${DIST}/initrd --append="$APPEND" -f fi