aboutsummaryrefslogtreecommitdiff
path: root/share/hydra/bootless
diff options
context:
space:
mode:
Diffstat (limited to 'share/hydra/bootless')
-rwxr-xr-xshare/hydra/bootless137
1 files changed, 137 insertions, 0 deletions
diff --git a/share/hydra/bootless b/share/hydra/bootless
new file mode 100755
index 0000000..751ae5c
--- /dev/null
+++ b/share/hydra/bootless
@@ -0,0 +1,137 @@
+#!/bin/sh
+#
+# 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
+# <http://www.gnu.org/licenses/>.
+
+# Load.
+source $APP_BASE/lib/hydra/functions || exit 1
+hydra_config_load
+
+# parameter verification
+if [ $# -gt 1 ]; then
+ echo "Usage: $0"
+ exit 1
+fi
+
+if [ -z "$HYDRA_FOLDER" ]; then
+ echo "Parameter HYDRA_FOLDER not configured."
+ exit 1
+fi
+
+# script description
+cat <<EOF
+Bootless Install Script
+=======================
+
+This script installs a bootable copy of the bootless repository in a device
+partition. It will ask for a git repo URL and a device partition, clone the
+repository in the partition and make the device bootable.
+
+Press any key to continue, or ^C to abort.
+EOF
+read tmp
+
+# asks for git repo URL
+echo -n "Git repo url (`pwd`/.git): "
+read gitdir
+if [ -z "${gitdir}" ]; then
+ gitdir="$HYDRA_FOLDER/bootless"
+fi
+
+# git repo consistency check
+git --git-dir=${gitdir} status > /dev/null
+if [ $? -ne 0 ]; then
+ echo "Error: '${gitdir}' is not a git repository."
+ exit 1
+fi
+
+# asks for target device
+if [ $# -lt 1 ]; then
+ echo -n "Target device: "
+ read device
+else
+ device=$2
+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
+
+******************
+* ATTENTION!!! *
+******************
+
+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..."
+ exit 1
+fi
+
+# formatacao e montagem
+mke2fs ${device}
+if [ $? != 0 ]; then
+ echo "Error: mke2fs failed in \"${device}\" (errno: $?)."
+ exit 1;
+fi
+tune2fs -c 0 -i 0 ${device}
+if [ $? != 0 ]; then
+ echo "Error: tune2fs failed in \"${device}\" (errno: $?)."
+ exit 1;
+fi
+tmpdir=`mktemp -d`
+mount ${device} ${tmpdir}
+if [ $? != 0 ]; then
+ echo "Error: failed to mount \"${device}\" filesystem in \"${tmpdir}\" (errno: $?)."
+ exit 1;
+fi
+
+# data copy
+git clone --depth=1 ${gitdir} ${tmpdir}/boot
+if [ $? != 0 ]; then
+ echo "Error: failed to clone repository \"${gitdir}\" 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]\$//`
+grub-install --root-directory=${tmpdir} ${usbdevice} --force
+
+# finalize
+#rm -f ${devicemap}
+umount ${tmpdir}
+rm -rf ${tmpdir}