#!/bin/bash # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public # License along with this program. If not, see # . # Load. source $APP_BASE/lib/hydra/functions || exit 1 hydra_config_load # Set bootless folder function hydra_bootless_folder { # Check for a bootless repository if [ -e "$HYDRA_FOLDER/bootless" ]; then BOOTLESS_DIR="$HYDRA_FOLDER/bootless" elif [ -e "$HYDRA_FOLDER/conf/bootless" ]; then BOOTLESS_DIR="$HYDRA_FOLDER/conf/bootless" else echo "Please make a symlink $HYDRA_FOLDER/bootless pointing to your devel puppet modules." exit 1 fi } # Make a boot device function hydra_bootless_make { # Set folder hydra_bootless_folder # Set sudo config local sudo device rsync if [ "`whoami`" != 'root' ]; then sudo="sudo" fi # Script description cat < /dev/null ) if [ $? -ne 0 ]; then echo "Error: '${BOOTLESS_DIR}' is not a git repository." exit 1 fi if [ -z "$1" ]; then echo -n "Target device: " read device else device=$1 fi if [ "$2" == "--rsync" ]; then rsync="true" fi usbdevice=`echo ${device} | sed -e s/[0-9]\$//g` # Target device consistency check if [ ! -b ${device} ]; then echo "Error: device \"${device}\" not found." exit 1 fi if [ "`mount | grep ${device}`" != "" ]; then echo "Error: device \"${device}\" is mounted." fi # Issue a warning cat < $HYDRA_FOLDER/bootless/grub/grub.cfg <<-EOF # This is grub.cfg for use with Bootless Management System ### BEGIN header ### if [ -s $prefix/grubenv ]; then load_env fi set default="0" if [ "${prev_saved_entry}" ]; then set saved_entry="${prev_saved_entry}" save_env saved_entry set prev_saved_entry= save_env prev_saved_entry set boot_once=true fi function savedefault { if [ -z "${boot_once}" ]; then saved_entry="${chosen}" save_env saved_entry fi } function load_video { } set timeout=5 ### END header ### ### BEGIN debian_theme ### set menu_color_normal=white/blue set menu_color_highlight=yellow/red ### END debian_theme ### EOF # Initialize git repository ( cd $HYDRA_FOLDER/bootless git init git add . git commit -a -m "Initial import" ) echo "Now add your boot images and edit $HYDRA_FOLDER/bootless/grub/grub.cfg to suit your needs." } # Git wrapper function hydra_bootless_git { # Set folder hydra_bootless_folder ( cd $BOOTLESS_DIR && git $* ) } # Usage function hydra_bootless_usage { echo "Usage: `basename $0` [arguments]" exit 1 } # Check for requirements. for req in parted; do hydra_install_package $req done # Parameter verification if [ -z "$1" ]; then hydra_bootless_usage elif [ -z "$HYDRA_FOLDER" ]; then echo "Parameter HYDRA_FOLDER not configured." exit 1 elif [ "$1" == "make" ]; then shift hydra_bootless_make $* elif [ "$1" == "init" ]; then shift hydra_bootless_init $* elif [ "$1" == "update" ]; then shift hydra_bootless_update $* elif [ "$1" == "git" ]; then shift hydra_bootless_git $* else hydra_bootless_usage fi