Skip to content

Commit

Permalink
modfs: fix some problems and add an option to abort to each question …
Browse files Browse the repository at this point in the history
…from console
  • Loading branch information
PeterPawn committed Feb 18, 2022
1 parent 23840e6 commit 5eadfd0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
4 changes: 3 additions & 1 deletion locale/de
Expand Up @@ -142,11 +142,13 @@
204=Das neue root-Dateisystem wurde erfolgreich in die inaktive Partition kopiert.\n\n%{bold}Beim nächsten Start der Box wird weiterhin das aktuell laufende System benutzt.\n%{normal}
205=Die Signatur der Datei konnte nicht erfolgreich verifiziert werden oder die Datei wurde verändert.
206=Überprüfen der Signatur der geladenen Datei ...
207=Ermitteln der Download-URL für die Version %s ...
207=Ermitteln der Download-URL für die Version %s ...
208=Es wurde keine Quelle für den Download der Version %s gefunden.
209=Fehler beim Ermitteln einer Download-URL für die Version %s, Abbruch.
222=Fehler beim Ermitteln des Dateisystemtyps der Image-Datei.
223=\n%{error}Das modifizierte root-Dateisystem wurde nicht gelöscht und steht unter dem Pfad %{normal}'%{bold}%s%{normal}'%{error} weiterhin zur Verfügung.\n%{normal}Das Verzeichnis muss später von Hand gelöscht werden.
224=Überprüfen des verfügbaren Swap-Space ...
225=\n%{error}Es steht kein Swap-Space auf diesem System zur Verfügung, die erfolgreiche Ausführung von '%{normal}%{bold}modfs%{normal}%{error}'\nist unwahrscheinlich. Deshalb wird die Ausführung abgebrochen.%{normal}
226=\n%{error}Es steht nicht genug Swap-Space auf diesem System zur Verfügung (erforderlich: %{normal}%{bold}%s%{normal}%{error} MB, vorhanden: %{normal}%{bold}%s%{normal}%{error} MB),\ndie erfolgreiche Ausführung von '%{normal}%{bold}modfs%{error} ist unwahrscheinlich. Deshalb wird die Ausführung abgebrochen.%{normal}
227=a
228=%{bold}a%{normal}bbrechen
4 changes: 3 additions & 1 deletion locale/en
Expand Up @@ -142,11 +142,13 @@
204=The new root file system has been installed into the inactive Partition.\n\n%{bold}Your device will still use the running system at next restart.\n%{normal}
205=Signature verification failed due to missing components or the firmware image was manipulated.
206=Try to verify image file signature ...
207=Looking up download URL for version %s ...
207=Looking up download URL for version %s ...
208=No download source for version %s could be found.
209=Error looking up download source for version %s, aborted.
222=Error detecting filesystem on image file.
223=\n%{error}The modified root filesystem was kept under the path %{normal}'%{bold}%s%{normal}'%{error} and may be inspected further now.\n%{normal}The directory has to be removed later manually.
224=Check available swap space ...
225=\n%{error}There is no swap space available on this system. A successful execution of '%{normal}%{bold}modfs%{normal}%{error}'\nis not really expected, therefore execution will be aborted now.%{normal}
226=\n%{error}There is not enough swap space available on this system (required: %{normal}%{bold}%s%{normal}%{error} MB, available: %{normal}%{bold}%s%{normal}%{error} MB) and\nthe probability of a successful execution of '%{normal}%{bold}modfs%{error} is low. Therefore execution will be aborted now.%{normal}
227=c
228=%{bold}c%{normal}ancel
53 changes: 39 additions & 14 deletions modfs
Expand Up @@ -385,8 +385,10 @@ ask_yes_or_no()
local def=$1 yes no p_yes p_no answer nl prompt="$2"
yes=$(get_localized $lang 129)
no=$(get_localized $lang 130)
cancel=$(get_localized $lang 227)
p_yes=$yes
p_no=$no
p_cancel="$(get_localized $lang 228)"
if [ $def == n ]; then
p_no=$(uppercase $no)
else
Expand All @@ -399,22 +401,24 @@ ask_yes_or_no()
while [ 1 -eq 1 ]; do
while read -n 10 -s -t 1; do :; done
echo -ne "$prompt" 1>&2
read -n 1 -s -p " ($p_yes/$p_no) " answer 1>&2
read -n 1 -s -p " ($p_yes/$p_no/$p_cancel) " answer 1>&2
nl="$answer\n"
[ ${#answer} -eq 0 ] && answer=$def && nl="\n"
debug "ask_yes_or_no: A=$answer"
if [ "$answer" == $(uppercase $yes) -o $answer == $yes ]; then
echo -n 'Y'
echo -e -n "$nl" 1>&2
return 0
elif [ "$answer" == $(uppercase $no) -o $answer == $no ]; then
echo -n 'N'
echo -e -n "$nl" 1>&2
return 0
elif [ "$answer" == $(uppercase $cancel) -o $answer == $cancel ]; then
echo -n 'C'
echo -e -n "$nl" 1>&2
return 1
else
if [ "$answer" == $(uppercase $no) -o $answer == $no ]; then
echo -n 'N'
echo -e -n "$nl" 1>&2
return 0
else
echo -e "$selection\n$(get_localized $lang 128)" 1>&2
fi
echo -e "$selection\n$(get_localized $lang 128)" 1>&2
fi
done
return 1
Expand Down Expand Up @@ -1100,6 +1104,7 @@ execute_optional_modscript()
msg="$(get_localized $lang 182 "$name" "%description%")"
msg="${msg//%description%/$desc}"
doit=$(ask_yes_or_no n "$msg")
[ "$doit" = "C" ] && exit 1
if [ x$doit == xY ]; then
execute_modscript "$script" "$rootdir" onrequest
fi
Expand All @@ -1118,7 +1123,7 @@ execute_optional_modscript()
return $rc
}
#
# sort the list of modscripts to ensure orepare the executable flags of modscripts listed in a custom selection file
# sort the list of modscripts to ensure execution in order, if a modifications depends on another
# $1 - script list file
#
solve_modscript_dependencies()
Expand Down Expand Up @@ -1146,14 +1151,14 @@ prepare_custom_modscripts_selection()
# scriptname missing
[ ${#scriptname} -eq 0 ] && continue
# file exists?
[ -f "$scripts/$scriptname" ] || continue
[ -f "$scriptpath/$scriptname" ] || continue
flags="a-x"
if [ "$state" == "+" ]; then
flags="a+x"
elif [ "$state" == '?' ]; then
flags="ug+x,o-x"
fi
$bb chmod "$flags" "$scripts/$scriptname"
$bb chmod "$flags" "$scriptpath/$scriptname"
rc=$?
debug "prepare_custom_modscripts_selection: chmod done for '$scriptname' (flags='$flags'), rc=$rc"
done <"$scriptpath/$custom_selection_file"
Expand All @@ -1164,6 +1169,19 @@ prepare_custom_modscripts_selection()
fi
}
#
# filter to remove script files without ANY executable flag set from STDIN,
# write other file names to STDOUT
#
remove_disabled_scripts()
{
while read -r script; do
flags=$($bb stat -c %a $script)
execute=$(( ( ${flags:2:1} & 1 ) + ( ${flags:1:1} & 1 ) + ( ${flags:0:1} & 1 ) ))
[ $execute -lt 3 ] && continue
echo "$script"
done
}
#
# execute modification scripts
# - only execute scripts, which are "world-executable", while in batch mode
# - execute the other scripts in a 2nd step, asking the user to confirm each one
Expand Down Expand Up @@ -1194,7 +1212,7 @@ modify_rootfs()
done
fi
[ -s "$list" ] && lines=$($bb sed -n -e "\$=" "$list") || lines=0
[ $lines -gt 0 ] && solve_modscript_dependencies "$list" "$scripts" >"$filelist" || touch "$filelist"
[ $lines -gt 0 ] && solve_modscript_dependencies "$list" "$scripts" | remove_disabled_scripts >"$filelist" || touch "$filelist"
debug "solve_dependencies: final modscripts list"
cat "$filelist" | $debugoutput
[ -s "$filelist" ] && lines=$($bb sed -n -e "\$=" "$filelist") || lines=0
Expand Down Expand Up @@ -3014,6 +3032,8 @@ if [ $prerc -eq 32 ]; then
echo -e "$(get_localized $lang 183)" 1>&2
prerc=0
fi
elif [ "$copypart" = "C" ]; then
exit 1
else
debug "modfs: continuing with a different kernel version"
prerc=0
Expand Down Expand Up @@ -3151,6 +3171,8 @@ case $source in
baseimage="$target"
remove_directory "$image_directory"
fi
elif [ "$copybase" = "C" ]; then
exit 1
fi
fi
debug "modfs: baseimage=$baseimage"
Expand Down Expand Up @@ -3472,13 +3494,14 @@ if [ $rc -eq 0 -a $install_image_only -eq 0 ]; then
debug "wait_for_key_before_pack: pause skipped due to environment setting"
else
# clear input buffer first
while read -n 10 -s -t 1; do :; done
echo -ne "$(get_localized $lang 150 $unpack_directory/$squashfsdirname)" 1>&2
while [ 1 -eq 1 ]; do
while read -n 10 -s -t 1; do :; done
if [ "$MODFS_ABORT_BEFORE_PACK" = "Q" ]; then
abort=$MODFS_ABORT_BEFORE_PACK
else
read abort
stty echo 2>/dev/null
read -n 1 abort
fi
if [ "$abort" = "q" ] || [ "$abort" = "Q" ]; then
echo -e "$(get_localized $lang 155)" 1>&2
Expand Down Expand Up @@ -3589,6 +3612,8 @@ else
echo -e "$(get_localized $lang $rc)" 1>&2
fi
debug "modfs: switching system done, rc=$rc"
elif [ "$switch" = "C" ]; then
exit 1
else
echo -e "$(get_localized $lang 204)" 1>&2
fi
Expand Down

0 comments on commit 5eadfd0

Please sign in to comment.