aboutsummaryrefslogtreecommitdiff
path: root/share/hydra/bootless
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2011-10-05 13:38:53 -0300
committerSilvio Rhatto <rhatto@riseup.net>2011-10-05 13:38:53 -0300
commit47f525c969eff1e7b4ce01af31a4cbcaf05664d8 (patch)
tree4132c43298f30059eee5237d667010608af7e6e8 /share/hydra/bootless
parent6829934dab237e33cb8e927b9139116424dd55d2 (diff)
downloadhydra-47f525c969eff1e7b4ce01af31a4cbcaf05664d8.tar.gz
hydra-47f525c969eff1e7b4ce01af31a4cbcaf05664d8.tar.bz2
Adding more actions to bootless subcommand
Diffstat (limited to 'share/hydra/bootless')
-rwxr-xr-xshare/hydra/bootless252
1 files changed, 151 insertions, 101 deletions
diff --git a/share/hydra/bootless b/share/hydra/bootless
index bad5f50..c2621e5 100755
--- a/share/hydra/bootless
+++ b/share/hydra/bootless
@@ -14,26 +14,34 @@
# License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
-# hydra project bootless init refspec
-# hydra project bootless git update
-# hydra project bootless git commit
-# hydra project bootless make /dev/sdb1
-
# Load.
source $APP_BASE/lib/hydra/functions || exit 1
hydra_config_load
-# parameter verification
-if [ $# -gt 1 ]; then
- echo "Usage: `basename $0` [target]"
- exit 1
-elif [ -z "$HYDRA_FOLDER" ]; then
- echo "Parameter HYDRA_FOLDER not configured."
- exit 1
-fi
-
-# script description
-cat <<EOF
+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
+}
+
+function hydra_bootless_make {
+ # Set folder
+ hydra_bootless_folder
+
+ # Set sudo config
+ local sudo
+ if [ "`whoami`" != 'root' ]; then
+ sudo="sudo"
+ fi
+
+ # Script description
+ cat <<EOF
Bootless Install Script
=======================
@@ -43,43 +51,34 @@ partition and make the device bootable.
Press any key to continue, or ^C to abort.
EOF
-read tmp
-
-if [ -e "$HYDRA_FOLDER/bootless" ]; then
- gitdir="$HYDRA_FOLDER/bootless"
-elif [ -e "$HYDRA_FOLDER/conf/bootless" ]; then
- gitdir="$HYDRA_FOLDER/conf/bootless"
-else
- echo "Please make a symlink $HYDRA_FOLDER/bootless pointing to your devel puppet modules."
- exit 1
-fi
-
-# git repo consistency check
-( cd ${gitdir} && git status > /dev/null )
-if [ $? -ne 0 ]; then
- echo "Error: '${gitdir}' is not a git repository."
- exit 1
-fi
-
-if [ -z "$1" ]; then
- echo -n "Target device: "
- read device
-else
- device=$1
-fi
-
-# 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
-
-# verifies that user is sure about that
-cat <<EOF
+ read tmp
+
+ # Git repo consistency check
+ ( cd ${BOOTLESS_DIR} && git status > /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
+
+ # 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 <<EOF
******************
* ATTENTION!!! *
@@ -88,54 +87,105 @@ cat <<EOF
If you continue, all data in device "${device}" will be destroyed!
EOF
-echo -n "Are you sure you want to continue? Type uppercase \"YES\": "
-read go
-
-if [ "${go}" != "YES" ]; then
- echo "Aborting..."
+ echo -n "Are you sure you want to continue? Type uppercase \"YES\": "
+ read go
+
+ if [ "${go}" != "YES" ]; then
+ echo "Aborting..."
+ exit 1
+ fi
+
+ # Format and mount
+ $sudo mke2fs ${device}
+ if [ $? != 0 ]; then
+ echo "Error: mke2fs failed in \"${device}\" (errno: $?)."
+ exit 1
+ fi
+ $sudo tune2fs -c 0 -i 0 ${device}
+ if [ $? != 0 ]; then
+ echo "Error: tune2fs failed in \"${device}\" (errno: $?)."
+ exit 1
+ fi
+ tmpdir=`mktemp -d`
+ $sudo mount ${device} ${tmpdir}
+ if [ $? != 0 ]; then
+ echo "Error: failed to mount \"${device}\" filesystem in \"${tmpdir}\" (errno: $?)."
+ exit 1
+ fi
+
+ # Copy data
+ $sudo git clone --depth=1 ${BOOTLESS_DIR} ${tmpdir}/boot
+ if [ $? != 0 ]; then
+ echo "Error: failed to clone repository \"${BOOTLESS_DIR}\" in \"${tmpdir}\" (errno: $?)."
+ exit 1
+ fi
+
+ # Grub legacy
+ #devicemap=`mktemp`
+ #grub-mkdevicemap --no-floppy --device-map=${devicemap}
+ #usbdevice=`echo ${device} | sed -e s/[0-9]\$//`
+ #grubroot=`grep "${usbdevice}" ${devicemap} | cut -f1`
+ #grubdevice=`echo ${grubroot} | sed -e s/\)/,0\)/`
+ #echo "root ${grubdevice}
+ #setup ${grubroot}
+ #quit" | grub --device-map=${devicemap} --batch
+
+ # Grub 2
+ usbdevice=`echo ${device} | sed -e s/[0-9]\$//`
+ $sudo grub-install --root-directory=${tmpdir} ${usbdevice} --force
+
+ # Finalize
+ #rm -f ${devicemap}
+ $sudo umount ${tmpdir}
+ $sudo rm -rf ${tmpdir}
+}
+
+# Repository initiator
+function hydra_bootless_init {
+ mkdir -p $HYDRA_FOLDER
+
+ if [ ! -z "$1" ]; then
+ # Clone from url
+ git clone $1 $HYDRA_FOLDER/bootless
+ else
+ # Create a fresh repository
+ # TODO
+ mkdir -p $HYDRA_FOLDER/bootless/{default,custom,grub}
+ exit
+ fi
+}
+
+# Git wrapper
+function hydra_bootless_git {
+ # Set folder
+ hydra_bootless_folder
+
+ (
+ cd $BOOTLESS_DIR && git $*
+ )
+}
+
+# Usage
+function hydra_bootless_usage {
+ echo "Usage: `basename $0` <action> [arguments]"
exit 1
-fi
+}
-# formatacao e montagem
-sudo mke2fs ${device}
-if [ $? != 0 ]; then
- echo "Error: mke2fs failed in \"${device}\" (errno: $?)."
- exit 1;
-fi
-sudo tune2fs -c 0 -i 0 ${device}
-if [ $? != 0 ]; then
- echo "Error: tune2fs failed in \"${device}\" (errno: $?)."
- exit 1;
-fi
-tmpdir=`mktemp -d`
-sudo mount ${device} ${tmpdir}
-if [ $? != 0 ]; then
- echo "Error: failed to mount \"${device}\" filesystem in \"${tmpdir}\" (errno: $?)."
- exit 1;
-fi
-
-# data copy
-sudo git clone --depth=1 ${gitdir} ${tmpdir}/boot
-if [ $? != 0 ]; then
- echo "Error: failed to clone repository \"${gitdir}\" in \"${tmpdir}\" (errno: $?)."
- exit 1;
+# 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" == "git" ]; then
+ shift
+ hydra_bootless_git $*
+else
+ hydra_bootless_usage
fi
-
-# grub legacy
-#devicemap=`mktemp`
-#grub-mkdevicemap --no-floppy --device-map=${devicemap}
-#usbdevice=`echo ${device} | sed -e s/[0-9]\$//`
-#grubroot=`grep "${usbdevice}" ${devicemap} | cut -f1`
-#grubdevice=`echo ${grubroot} | sed -e s/\)/,0\)/`
-#echo "root ${grubdevice}
-#setup ${grubroot}
-#quit" | grub --device-map=${devicemap} --batch
-
-# grub 2
-usbdevice=`echo ${device} | sed -e s/[0-9]\$//`
-sudo grub-install --root-directory=${tmpdir} ${usbdevice} --force
-
-# finalize
-#rm -f ${devicemap}
-sudo umount ${tmpdir}
-sudo rm -rf ${tmpdir}