summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/fifa.sh24
-rw-r--r--src/lib/lib-misc.sh42
-rw-r--r--src/lib/lib-software.sh35
-rw-r--r--src/lib/lib-ui.sh53
4 files changed, 122 insertions, 32 deletions
diff --git a/src/fifa.sh b/src/fifa.sh
index 818a1db..d0b1d75 100755
--- a/src/fifa.sh
+++ b/src/fifa.sh
@@ -31,6 +31,8 @@ usage ()
##### "These functions would fit more in lib-ui, but we need them immediately" functions ######
+
+# display error message and die
die_error ()
{
if [ "$var_UI_TYPE" = dia ]
@@ -43,6 +45,28 @@ die_error ()
}
+# display warning message
+# $1 title
+# $2 item to show
+# $3 type of item. msg or text if it's a file. (optional. defaults to msg)
+show_warning ()
+{
+ [ -z "$1" ] && die_error "show_warning needs a title"
+ [ -z "$2" ] && die_error "show_warning needs an item to show"
+ [ -n "$3" -a "$3" != msg -a "$3" != text ] && die_error "show_warning \$3 must be text or msg"
+ [ -z "$3" ] && 3=msg
+ if [ "$var_UI_TYPE" = dia ]
+ then
+ dialog --title "$1" --exit-label "Continue" --$3box "$2" 18 70 || die_error "dialog could not show --$3box $2. often this means a file does not exist"
+ else
+ echo "WARNING: $1"
+ [ "$3" = msg ] && echo $2
+ [ "$3" = text ] && cat $2 || die_error "Could not cat $2"
+ fi
+}
+
+
+#notify user
notify ()
{
if [ "$var_UI_TYPE" = dia ]
diff --git a/src/lib/lib-misc.sh b/src/lib/lib-misc.sh
new file mode 100644
index 0000000..bc9b150
--- /dev/null
+++ b/src/lib/lib-misc.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+
+# run a process in the background, and log it's stdout and stderr to a specific logfile
+# $1 identifier
+# $2 command (will be eval'ed)
+# $3 logfile
+run_background ()
+{
+ [ -z "$1" ] && die_error "run_background: please specify an identifier to keep track of the command!"
+ [ -z "$2" ] && die_error "run_background needs a command to execute!"
+ [ -z "$3" ] && die_error "run_background needs a logfile to redirect output to!"
+
+ ( \
+ touch /tmp/$1-running
+ echo "$1 progress ..." > $3; \
+ echo >> $3; \
+ eval "$1" >>$3 2>&1
+ echo $? > /tmp/.$1-retcode
+ echo >> $3
+ rm -f /tmp/$1-running
+ ) &
+
+ sleep 2
+}
+
+
+# wait untill a process is done
+# $1 identifier
+wait_for ()
+{
+ [ -z "$1" ] && die_error "wait_for needs an identifier to known on which command to wait!"
+
+ while [ -f /tmp/$1-running ]
+ do
+ #TODO: follow_progress dialog mode = nonblocking (so check and sleep is good), cli mode (tail -f )= blocking? (so check is probably not needed as it will be done)
+ sleep 1
+ done
+
+ kill $(cat $ANSWER) #TODO: this may not work when mode = cli
+}
+
diff --git a/src/lib/lib-software.sh b/src/lib/lib-software.sh
index d2fc82f..8ec802a 100644
--- a/src/lib/lib-software.sh
+++ b/src/lib/lib-software.sh
@@ -1,39 +1,18 @@
#!/bin/sh
-# run_mkinitcpio() taken from setup. adapted a bit. TODO: GET ALL THE UI CODE OUT OF HERE !!
+# run_mkinitcpio() taken from setup. adapted a bit.
# runs mkinitcpio on the target system, displays output
-#
run_mkinitcpio()
{
target_special_fs on
- # all mkinitcpio output goes to /tmp/mkinitcpio.log, which we tail
- # into a dialog
- ( \
- touch /tmp/setup-mkinitcpio-running
- echo "mkinitcpio progress ..." > /tmp/mkinitcpio.log; \
- echo >> /tmp/mkinitcpio.log; \
- chroot "$TARGET_DIR" /sbin/mkinitcpio -p kernel26 >>/tmp/mkinitcpio.log 2>&1
- echo $? > /tmp/.mkinitcpio-retcode
- echo >> /tmp/mkinitcpio.log
- rm -f /tmp/setup-mkinitcpio-running
- ) &
- sleep 2
+ run_background mkinitcpio "chroot $TARGET_DIR /sbin/mkinitcpio -p kernel26" /tmp/mkinitcpio.log
+ follow_progress "Rebuilding initcpio images ..." /tmp/mkinitcpio.log
+ wait_for mkinitcpio
- DIALOG --title "Rebuilding initcpio images ..." \
- --no-kill --tailboxbg "/tmp/mkinitcpio.log" 18 70 2>$ANSWER
- while [ -f /tmp/setup-mkinitcpio-running ]; do
- sleep 1
- done
- kill $(cat $ANSWER)
+ target_special_fs off
- target_special_fs off
-
- # alert the user to fatal errors
- if [ $(cat /tmp/.mkinitcpio-retcode) -ne 0 ]; then
- DIALOG --title "MKINITCPIO FAILED - SYSTEM MAY NOT BOOT" --exit-label \
- "Continue" --textbox "/tmp/mkinitcpio.log" 18 70
- return 1
- fi
+ # alert the user to fatal errors
+ [ $(cat /tmp/.mkinitcpio-retcode) -ne 0 ] && show_warning "MKINITCPIO FAILED - SYSTEM MAY NOT BOOT" "/tmp/mkinitcpio.log" text
}
diff --git a/src/lib/lib-ui.sh b/src/lib/lib-ui.sh
index 657e07a..bfeae2f 100644
--- a/src/lib/lib-ui.sh
+++ b/src/lib/lib-ui.sh
@@ -37,7 +37,7 @@ ask_yesno ()
# returns 1 if the user cancelled, 0 otherwise
ask_string ()
{
- [ -z "$1"] && die_error "ask_string needs a question!"
+ [ -z "$1" ] && die_error "ask_string needs a question!"
[ "$var_UI_TYPE" = dia ] && { _dia_ask_string $@ ; return $? }
[ "$var_UI_TYPE" = cli ] && { _cli_ask_string $@ ; return $? }
}
@@ -51,7 +51,7 @@ ask_string ()
# returns 1 if the user cancelled or did not enter a numeric, 0 otherwise
ask_number ()
{
- [ -z "$1"] && die_error "ask_number needs a question!"
+ [ -z "$1" ] && die_error "ask_number needs a question!"
[ "$var_UI_TYPE" = dia ] && { _dia_ask_number $@ ; return $? }
[ "$var_UI_TYPE" = cli ] && { _cli_ask_number $@ ; return $? }
}
@@ -66,7 +66,16 @@ ask_option ()
}
-
+# follow the progress of something by showing it's log, updating real-time
+# $1 title
+# $2 logfile
+follow_progress ()
+{
+ [ -z "$1" ] && die_error "follow_progress needs a title!"
+ [ -z "$2" ] && die_error "follow_progress needs a logfile to follow!"
+ [ "$var_UI_TYPE" = dia ] && { _dia_follow_progress $@ ; return $? }
+ [ "$var_UI_TYPE" = cli ] && { _cli_follow_progress $@ ; return $? }
+}
# taken from setup
@@ -137,6 +146,13 @@ _dia_ask_bootloader()
}
+_dia_follow_progress ()
+{
+ title=$1
+ logfile=$2
+}
+
+
_cli_ask_password ()
{
if [ -n "$1" ]
@@ -183,4 +199,33 @@ _cli_ask_option ()
{
}
- \ No newline at end of file
+
+_cli_follow_progress ()
+{
+ title=$1
+ logfile=$2
+ echo "Title: $1"
+ tail -f $2
+}
+
+ ( \
+ touch /tmp/setup-mkinitcpio-running
+ echo "mkinitcpio progress ..." > /tmp/mkinitcpio.log; \
+ echo >> /tmp/mkinitcpio.log; \
+ chroot "$TARGET_DIR" /sbin/mkinitcpio -p kernel26 >>/tmp/mkinitcpio.log 2>&1
+ echo $? > /tmp/.mkinitcpio-retcode
+ echo >> /tmp/mkinitcpio.log
+ rm -f /tmp/setup-mkinitcpio-running
+ ) &
+
+ sleep 2
+
+ DIALOG --title "Rebuilding initcpio images ..." \
+ --no-kill --tailboxbg "/tmp/mkinitcpio.log" 18 70 2>$ANSWER
+ while [ -f /tmp/setup-mkinitcpio-running ]; do
+ sleep 1
+ done
+ kill $(cat $ANSWER)
+
+
+}