Skip to Content.
Sympa Menu

sm-commit - [SM-Commit] GIT changes to devel-flux cauldron by Karsten Behrmann (02f2fc7eec51d448a81c5ff9fa5c26a944e28fe1)

sm-commit AT lists.ibiblio.org

Subject: Source Mage code commit list

List archive

Chronological Thread  
  • From: Karsten Behrmann <scm AT sourcemage.org>
  • To: sm-commit AT lists.ibiblio.org
  • Subject: [SM-Commit] GIT changes to devel-flux cauldron by Karsten Behrmann (02f2fc7eec51d448a81c5ff9fa5c26a944e28fe1)
  • Date: Thu, 21 Aug 2008 13:53:52 -0500

GIT changes to devel-flux cauldron by Karsten Behrmann
<BearPerson AT sourcemage.org>:

src/enchant/menu/libmenu | 48 +++++++++---
src/enchant/menu/menu.sh | 13 ++-
src/enchant/menu/modules/disk | 88 ----------------------
src/enchant/menu/modules/disk-format | 137
+++++++++++++++++++++++++++++++++++
4 files changed, 181 insertions(+), 105 deletions(-)

New commits:
commit 02f2fc7eec51d448a81c5ff9fa5c26a944e28fe1
Author: Karsten Behrmann <BearPerson AT sourcemage.org>
Commit: Karsten Behrmann <BearPerson AT sourcemage.org>

rename to match name of implemented step

commit 47e346e7f03001db12608aecf8426ff4e830d37f
Author: Karsten Behrmann <BearPerson AT sourcemage.org>
Commit: Karsten Behrmann <BearPerson AT sourcemage.org>

Implement a disk-formatting menu, on some sort of high level

commit e2a9c5bb8e84f7bc84965a111ca13347c9bef3b3
Author: Karsten Behrmann <BearPerson AT sourcemage.org>
Commit: Karsten Behrmann <BearPerson AT sourcemage.org>

Better exit codes and stuff

diff --git a/src/enchant/menu/libmenu b/src/enchant/menu/libmenu
index 84e3de5..fe1cb22 100644
--- a/src/enchant/menu/libmenu
+++ b/src/enchant/menu/libmenu
@@ -1,3 +1,32 @@
+#!/bin/bash
+# [not actually a script, just to teach vi proper hilighting]
+
+# Constants for exit codes recognized by the menu launcher
+# (menu modules should not exit with anything else,
+# or it'll be treated as an error in the menu module itself)
+
+EXIT_OK=0 # Launches menu on the [now] current step
+EXIT_MAINMENU=21 # Brings up the main menu
+EXIT_SHELL=22 # Switches to shell installer (after user asked)
+EXIT_BAIL=23 # Exit to shell (to be used after weird errors)
+
+# for dialog
+export DIALOG_ESC=1 # Treat esc as cancel
+
+# die_cmd [failed_command [displayed_exitcode [exitcode_for_exit]]]
+function die_cmd() {
+ local rc=${2:-$?}
+ local message
+
+ [[ -n $1 ]] &&
+ message="Error: $1 failed with exit code $rc, "
+
+ message="${message}bailing out."
+
+ echo "$message" >&2
+ exit ${3:-$EXIT_BAIL}
+}
+
# Menu / checklist / whatever
# If this returns 0, use result from dialog, otherwise the user cancelled
function menu_step() {
@@ -8,10 +37,9 @@ function menu_step() {
elif [[ $rc == 1 ]] ;then # back
return 1
elif [[ $rc == 3 ]] ;then # abort/cancel
- exit 1
+ exit $EXIT_MAINMENU
else
- echo "Unrecognized exit code $? from dialog, bailing out" >&2
- exit 3
+ die_cmd "dialog" $rc
fi
return $rc
}
@@ -25,12 +53,11 @@ function menu_docbox() {
if [[ $rc == 0 ]] ;then
((STATE++))
elif [[ $rc == 1 ]] ;then # main menu
- exit 1
+ exit $EXIT_MAINMENU
elif [[ $rc == 3 ]] ;then # shell
- exit 2
+ exit $EXIT_SHELL
else
- echo "Unrecognized exit code $? from dialog, bailing out" >&2
- exit 3
+ die_cmd "dialog" $rc
fi
}

@@ -38,12 +65,9 @@ function menu_loop() {
STATE=initial
while [[ $STATE != mainmenu ]] ;do
$STATE || # Function call
- {
- echo "State $STATE failed (code $?), bailing out" >&2
- exit 3
- }
+ die_cmd "State $STATE"
done

# Exit to main menu on normal completion of loop
- exit 1
+ exit $EXIT_MAINMENU
}
diff --git a/src/enchant/menu/menu.sh b/src/enchant/menu/menu.sh
index 8d57743..030d82d 100644
--- a/src/enchant/menu/menu.sh
+++ b/src/enchant/menu/menu.sh
@@ -1,6 +1,7 @@
#!/bin/bash

. /usr/share/smgl.install/libenchant
+. /wherever/libmenu

function main_menu() {
}
@@ -17,18 +18,20 @@ function main_loop() {
fi
/usr/share/smgl.install/menu/$step
rc=$?
- if [[ $rc == 0 ]] ;then
+ if [[ $rc == $EXIT_OK ]] ;then
: # Carry on with the next step, nothing to do
# (Step will have set the current installer step already)
- elif [[ $rc == 1 ]] ;then
+ elif [[ $rc == $EXIT_MAINMENU ]] ;then
MENU=true
- elif [[ $rc == 2 ]] ;then
+ elif [[ $rc == $EXIT_SHELL ]] ;then
echo "Switching to shell, type \e[1mmenu\e[1m to return to menu"
echo "Type \e[1mtodo\e1m to see the current step's documentation"
exit
- else
- echo "Bailing to shell (gui step returned $rc)..."
+ elif [[ $rc == $EXIT_BAIL ]] ;then
+ echo "Bailing to shell."
exit
+ else
+ die_cmd "gui step $step" $rc
fi
fi
}
diff --git a/src/enchant/menu/modules/disk b/src/enchant/menu/modules/disk
deleted file mode 100644
index eeb71c8..0000000
--- a/src/enchant/menu/modules/disk
+++ /dev/null
@@ -1,88 +0,0 @@
-#!/bin/bash
-# Exit code convention:
-# 0 - [re]launch menu for current step
-# 1 - display main menu
-# 2 - exit to shell (user-initiated)
-# * - exit to shell (unplanned)
-
-function initial() {
- menu_docbox "Do the disk stuff"
- STATE=get_part
- return 0
-}
-
-function get_part() {
- RESULT=$(dialog_menu /dev/hda1 /dev/sda2 custom)
- rc=$?
- if [[ $rc == 1 ]] ;then
- STATE=initial
- return 0
- elif [[ $rc == 3 ]] ;then
- STATE=finish
- return 0
- else
- echo "Unrecognized exit code $? from dialog, bailing out" >&2
- exit 3
- fi
-
- PARTITION=$RESULT
- if [[ $PARTITION == custom ]] ;then
- STATE=enter_part
- else
- STATE=get_fstype
- fi
-}
-
-function enter_part() {
- RESULT=$(menu_txtbox "Enter partition") ||
- {
- STATE=get_part
- return 0
- }
- PARTITION=$RESULT
- STATE=get_fstype
-}
-
-function get_fstype() {
- RESULT=$(menu_menu ext2 ext3 jfs reiserfs xfs custom) ||
- {
- STATE=get_part
- return 0
- }
- FSTYPE=$RESULT
- MKFSCMD="mkfs.$FSTYPE $PARTITION"
- STATE=confirm
-}
-
-function confirm() {
- RESULT=$(menu_menu doit modify) ||
- {
- STATE=get_fstype
- return 0
- }
- if [[ $RESULT == doit ]] ;then
- STATE=result
- else
- STATE=tunecmd
- fi
-}
-
-function result() {
- echo "Creating filesystem..."
- eval "$MKFSCMD"
- rc=$?
- if [[ $rc == 0 ]] ;then
- STATE=get_partition
- else
- STATE=get_partition
- STATE=tunecmd
- fi
-}
-
-function finish() {
- installer_next
- exit 0
-}
-
-register_states initial get_part get_fstype confirm result finish
-menu_loop
diff --git a/src/enchant/menu/modules/disk-format
b/src/enchant/menu/modules/disk-format
new file mode 100644
index 0000000..f77936a
--- /dev/null
+++ b/src/enchant/menu/modules/disk-format
@@ -0,0 +1,137 @@
+#!/bin/bash
+
+load_partitions() {
+ # Device Boot Start End MiB #blocks Id System
+ #/dev/sda1 * 0+ 9538- 9539- 9767488+ 83 Linux
+ #/dev/sda2 9538+ 10236- 699- 714892+ 82 Linux swap / Solaris
+
+ PARTITIONS=()
+ local i=0
+ local PART SIZE TYPE
+ # Poor man's pipe: doesn't spawn a subshell.
+ < <(sfdisk -l -uM | grep '^/' | sed 's/\*//;s/ \+/\t/' |
+ cut -d$'\t' -f1,6,8
+ sed 's/ .* / /') \
+ while read PART _ _ SIZE _ _ TYPE ;do
+ PARTITIONS[i++]=$PARTITION
+ PARTITIONS[i++]="$SIZE MiB, $TYPE"
+ done
+}
+
+mkfs_command() {
+ case $1 in
+ ext2) echo "mke2fs $2" ;;
+ ext3) echo "mke2fs -j $2" ;;
+ reiserfs) echo "mkreiserfs $2" ;;
+ xfs) echo "mkfs.xfs -f $2" ;; # ignore existing partition
+ jfs) echo "mkfs.jfs $2" ;;
+ swap) echo "mkswap $2" ;;
+ custom) echo "... $2" ;;
+ *) return 1 ;;
+ esac
+ return 0
+}
+
+function initial() {
+ menu_docbox "Do the disk stuff"
+ STATE=get_part
+ return 0
+}
+
+function get_part() {
+ load_partitions
+ RESULT=$(menu_central_menu "${PARTITIONS[@]}" custom "Enter one manually")
+ rc=$?
+ if [[ $rc == 1 ]] ;then
+ STATE=initial
+ return 0
+ elif [[ $rc == 3 ]] ;then
+ STATE=finish
+ return 0
+ else
+ die_cmd "dialog" $?
+ fi
+
+ PARTITION=$RESULT
+ if [[ $PARTITION == custom ]] ;then
+ STATE=enter_part
+ else
+ STATE=get_fstype
+ fi
+}
+
+function enter_part() {
+ RESULT=$(menu_txtbox "Enter partition") ||
+ {
+ STATE=get_part
+ return 0
+ }
+ PARTITION=$RESULT
+ STATE=get_fstype
+}
+
+function get_fstype() {
+ RESULT=$(menu_menu "Filesystem Selection Menu" \
+ "Please select what filesystem to use for $PARTITION" \
+ "ext2" "Second Extended file system" \
+ "ext3" "Second Extended journaling file system" \
+ "reiserfs" "Reiserfs journaling file system" \
+ "xfs" "XFS journaling file system" \
+ "jfs" "JFS journaling file system" \
+ "swap" "Swap partition"
+ "custom" "your call") ||
+ {
+ STATE=get_part
+ return 0
+ }
+ FSTYPE=$RESULT
+ MKFSCMD="$(mkfs_command $FSTYPE $PARTITION)"
+ STATE=confirm
+}
+
+function confirm() {
+ RESULT=$(menu_menu "Confirmation Menu" \
+ "Do you want to run the following command:
+$MKFSCMD"
+ "doit" "Energize!"
+ "modify" "Let me edit that line") ||
+ {
+ STATE=get_fstype
+ return 0
+ }
+ if [[ $RESULT == doit ]] ;then
+ STATE=result
+ else
+ STATE=tunecmd
+ fi
+}
+
+function result() {
+ echo "Creating filesystem..."
+ eval "$MKFSCMD" 2>&1 | tee /tmp/mkfs.out
+ rc=$?
+ if [[ $rc == 0 ]] ;then
+ menu_message "Successful mkfs" \
+ "Command ran successfully. Output was:
+$(cat /tmp/mkfs.out)"
+ STATE=get_partition
+ else
+ RESULT=$(menu_menu "mkfs failed" \
+ "Command failed with exit status $rc. Output was:
+$(cat /tmp/mkfs.out)" \
+ "edit" "Edit command and retry" \
+ "return" "Return to partition menu")
+ if [[ $RESULT == "return" ]] ;then
+ STATE=get_partition
+ else # return or "back"
+ STATE=tunecmd
+ fi
+ fi
+}
+
+function finish() {
+ enchant_setnext
+ exit $EXIT_OK
+}
+
+menu_loop



  • [SM-Commit] GIT changes to devel-flux cauldron by Karsten Behrmann (02f2fc7eec51d448a81c5ff9fa5c26a944e28fe1), Karsten Behrmann, 08/21/2008

Archive powered by MHonArc 2.6.24.

Top of Page