1
0
mirror of https://github.com/rancher/os.git synced 2025-06-22 21:17:02 +00:00
os/scripts/installer/lay-down-os

186 lines
4.2 KiB
Plaintext
Raw Normal View History

#!/bin/bash
set -e -x
. $(dirname $0)/version
2015-08-25 05:59:30 +00:00
VERSION=${VERSION:?"VERSION not set"}
while getopts "i:f:c:d:t:r:o:p:" OPTION
do
2015-08-25 05:59:30 +00:00
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" ;;
t) ENV="$OPTARG" ;;
*) exit 1 ;;
esac
done
DIST=${DIST:-/dist}
2015-08-18 14:07:00 +00:00
CLOUD_CONFIG=${CLOUD_CONFIG:-/scripts/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 <dev>." 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 name|grep RANCHER_BOOT | wc -l)" -eq "1" ]; then
label=RANCHER_BOOT
fi
local mount_opts="-L ${label}"
if [ "${raw}" == "true" ]; then
device_defined ${DEVICE}
mount_opts=${PARTITION}
fi
2015-08-25 05:59:30 +00:00
mount ${mount_opts} ${BASE_DIR}
trap "umount ${BASE_DIR}" EXIT
}
create_boot_dirs()
{
mkdir -p ${BASE_DIR}/boot/grub
2015-08-25 05:59:30 +00:00
mkdir -p ${BASE_DIR}/boot/extlinux
}
2015-08-25 05:59:30 +00:00
install_extlinux() {
extlinux -i ${BASE_DIR}/boot/extlinux
dd if=/usr/share/syslinux/mbr.bin of=${DEVICE}
}
2015-08-25 05:59:30 +00:00
extlinux_config(){
local extlinux_conf=${BASE_DIR}/boot/extlinux/extlinux.conf
local append_line="${1}"
2015-08-25 05:59:30 +00:00
cat >${extlinux_conf} <<EOF
default ros
label ros
kernel /boot/vmlinuz-${VERSION}-rancheros
initrd /boot/initrd-${VERSION}-rancheros
append ${append_line} console=${CONSOLE}
EOF
2015-08-25 05:59:30 +00:00
if [ ! -z ${ROLLBACK_VERSION} ]; then
sed -i 's/^#set/set/' ${extlinux_conf}
cat >>${extlinux_conf} <<EOF
label ros-fallback
kernel /boot/vmlinuz-${ROLLBACK_VERSION}-rancheros
initrd /boot/initrd-${ROLLBACK_VERSION}-rancheros
append ${append_line} console=${CONSOLE}
2015-08-25 05:59:30 +00:00
EOF
fi
}
install_rancher()
{
2015-08-25 05:59:30 +00:00
cp ${DIST}/initrd ${BASE_DIR}/boot/initrd-${VERSION}-rancheros
cp ${DIST}/vmlinuz ${BASE_DIR}/boot/vmlinuz-${VERSION}-rancheros
}
pvgrub_config()
{
2015-08-25 05:59:30 +00:00
local grub_file=${BASE_DIR}/boot/grub/menu.lst
local append_line="${1}"
2015-08-25 05:59:30 +00:00
cat > ${grub_file}<<EOF
default 0
timeout 0
#fallback 1
hiddenmenu
title RancherOS ${VERSION}-(current)
root (hd0)
kernel /boot/vmlinuz-${VERSION}-rancheros ${append_line} console=${CONSOLE}
initrd /boot/initrd-${VERSION}-rancheros
EOF
2015-08-25 05:59:30 +00:00
if [ ! -z ${ROLLBACK_VERSION} ]; then
sed -i 's/^#\(fallback\)/\1/' ${grub_file}
cat >> ${grub_file}<<EOF
title RancherOS ${ROLLBACK_VERSION}-(rollback)
root (hd0)
kernel /boot/vmlinuz-${ROLLBACK_VERSION}-rancheros ${append_line} console=${CONSOLE}
initrd /boot/initrd-${ROLLBACK_VERSION}-rancheros
EOF
fi
}
format_and_mount()
{
format_device
mount_device
create_boot_dirs
}
KERNEL_ARGS=${KERNEL_ARGS:-""}
if [ -n ${ENV} ]; then
case ${ENV} in
"generic")
format_and_mount
2015-08-25 05:59:30 +00:00
install_extlinux
/scripts/seed-data ${BASE_DIR} ${CLOUD_CONFIG} ${FILES}
;;
"amazon-ebs-pv"|"amazon-ebs-hvm")
CONSOLE=ttyS0
format_and_mount
if [ "${ENV}" == "amazon-ebs-hvm" ]; then
2015-08-25 05:59:30 +00:00
install_extlinux
fi
# AWS Networking recommends disabling.
2015-08-25 05:59:30 +00:00
/scripts/seed-data ${BASE_DIR} ${CLOUD_CONFIG} ${FILES}
;;
"googlecompute")
CONSOLE=ttyS0
format_and_mount
2015-08-25 05:59:30 +00:00
install_extlinux
/scripts/seed-data ${BASE_DIR} ${CLOUD_CONFIG} ${FILES}
;;
"bootstrap")
CONSOLE=ttyS0
mount_device true
create_boot_dirs
KERNEL_ARGS="${KERNEL_ARGS} rancher.cloud_init.datasources=[ec2,gce]"
;;
"rancher-upgrade")
mount_device
create_boot_dirs
;;
*)
echo "$ENV is not a valid environment" 1>&2
exit 1
;;
esac
fi
2015-08-25 05:59:30 +00:00
extlinux_config "${KERNEL_ARGS}"
pvgrub_config "${KERNEL_ARGS}"
install_rancher