Added try operation
This commit is contained in:
parent
54f7b0f322
commit
0d952d5a34
|
@ -233,7 +233,7 @@ download_stage3() {
|
||||||
|| die "Checksum mismatch!"
|
|| die "Checksum mismatch!"
|
||||||
|
|
||||||
# Create verification file in case the script is restarted
|
# Create verification file in case the script is restarted
|
||||||
touch "$CURRENT_STAGE3_VERIFIED"
|
touch_or_die "$CURRENT_STAGE3_VERIFIED"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ disable_logging() {
|
||||||
exec 1>&3
|
exec 1>&3
|
||||||
# Close fd 3
|
# Close fd 3
|
||||||
exec 3<&-
|
exec 3<&-
|
||||||
}
|
}; export -f disable_logging
|
||||||
|
|
||||||
gentoo_umount() {
|
gentoo_umount() {
|
||||||
if mountpoint -q -- "$ROOT_MOUNTPOINT"; then
|
if mountpoint -q -- "$ROOT_MOUNTPOINT"; then
|
||||||
|
@ -285,6 +285,16 @@ env_update() {
|
||||||
export PS1="(chroot) \$PS1"
|
export PS1="(chroot) \$PS1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mkdir_or_die() {
|
||||||
|
mkdir -p "$1" \
|
||||||
|
|| die "Could not create directory '$1'"
|
||||||
|
}
|
||||||
|
|
||||||
|
touch_or_die() {
|
||||||
|
touch "$1" \
|
||||||
|
|| die "Could not touch '$1'"
|
||||||
|
}
|
||||||
|
|
||||||
gentoo_chroot() {
|
gentoo_chroot() {
|
||||||
if [[ $# -eq 0 ]]; then
|
if [[ $# -eq 0 ]]; then
|
||||||
cat > "$TMP_DIR/.bashrc" <<EOF
|
cat > "$TMP_DIR/.bashrc" <<EOF
|
||||||
|
|
|
@ -65,14 +65,14 @@ main_install_gentoo_in_chroot() {
|
||||||
|
|
||||||
# Sync portage
|
# Sync portage
|
||||||
einfo "Syncing portage tree"
|
einfo "Syncing portage tree"
|
||||||
emerge-webrsync\
|
try emerge-webrsync \
|
||||||
|| die "Failed to sync portage tree"
|
|| die "Failed to sync portage tree"
|
||||||
|
|
||||||
# Set timezone
|
# Set timezone
|
||||||
einfo "Selecting timezone"
|
einfo "Selecting timezone"
|
||||||
echo "$TIMEZONE" > /etc/timezone \
|
echo "$TIMEZONE" > /etc/timezone \
|
||||||
|| die "Could not write /etc/timezone"
|
|| die "Could not write /etc/timezone"
|
||||||
emerge -v --config sys-libs/timezone-data
|
try emerge -v --config sys-libs/timezone-data
|
||||||
|
|
||||||
# Set locale
|
# Set locale
|
||||||
einfo "Selecting locale"
|
einfo "Selecting locale"
|
||||||
|
@ -80,12 +80,22 @@ main_install_gentoo_in_chroot() {
|
||||||
|| die "Could not write /etc/locale.gen"
|
|| die "Could not write /etc/locale.gen"
|
||||||
locale-gen \
|
locale-gen \
|
||||||
|| die "Could not generate locales"
|
|| die "Could not generate locales"
|
||||||
eselect locale set "$LOCALE" \
|
try eselect locale set "$LOCALE"
|
||||||
|| die "Could not select locale"
|
|
||||||
|
|
||||||
# Update environment
|
# Update environment
|
||||||
env_update
|
env_update
|
||||||
|
|
||||||
|
# Prepare /etc/portage for autounmask
|
||||||
|
mkdir_or_die "/etc/portage/package.use"
|
||||||
|
touch_or_die "/etc/portage/package.use/zz-autounmask"
|
||||||
|
mkdir_or_die "/etc/portage/package.keywords"
|
||||||
|
touch_or_die "/etc/portage/package.keywords/zz-autounmask"
|
||||||
|
|
||||||
|
# Install git (for git portage overlays)
|
||||||
|
einfo "Installing git"
|
||||||
|
try emerge --verbose dev-vcs/git \
|
||||||
|
|| die "Error while installing git"
|
||||||
|
|
||||||
#get kernel
|
#get kernel
|
||||||
|
|
||||||
#compile minimal kernel to boot system
|
#compile minimal kernel to boot system
|
||||||
|
@ -125,7 +135,7 @@ main_umount() {
|
||||||
# Main dispatch
|
# Main dispatch
|
||||||
|
|
||||||
# Instantly kill when pressing ctrl-c
|
# Instantly kill when pressing ctrl-c
|
||||||
trap "kill $GENTOO_BOOTSTRAP_SCRIPT_PID" INT
|
trap 'kill "$GENTOO_BOOTSTRAP_SCRIPT_PID"' INT
|
||||||
|
|
||||||
einfo "Verbose script output will be logged to: '$GENTOO_BOOTSTRAP_DIR/log-$LOGDATE.out'"
|
einfo "Verbose script output will be logged to: '$GENTOO_BOOTSTRAP_DIR/log-$LOGDATE.out'"
|
||||||
# Save old stdout
|
# Save old stdout
|
||||||
|
|
|
@ -2,9 +2,17 @@
|
||||||
|
|
||||||
source "$GENTOO_BOOTSTRAP_DIR/scripts/protection.sh" || exit 1
|
source "$GENTOO_BOOTSTRAP_DIR/scripts/protection.sh" || exit 1
|
||||||
|
|
||||||
|
echo_console() {
|
||||||
|
if { true >&3; } 2<> /dev/null; then
|
||||||
|
echo "$@" >&3
|
||||||
|
else
|
||||||
|
echo "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
log_stdout() {
|
log_stdout() {
|
||||||
echo "$*"
|
echo "$*"
|
||||||
if { >&3; } 2<> /dev/null; then
|
if { true >&3; } 2<> /dev/null; then
|
||||||
echo "$*" >&3
|
echo "$*" >&3
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -42,13 +50,15 @@ for_line_in() {
|
||||||
done <"$1"
|
done <"$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
ask() {
|
flush_stdin() {
|
||||||
# Empty stdin
|
|
||||||
local empty_stdin
|
local empty_stdin
|
||||||
while read -r -t 0.01 empty_stdin; do true; done
|
while read -r -t 0.01 empty_stdin; do true; done
|
||||||
unset empty_stdin
|
}
|
||||||
|
|
||||||
|
ask() {
|
||||||
|
local response
|
||||||
while true; do
|
while true; do
|
||||||
|
flush_stdin
|
||||||
read -r -p "$* (Y/n) " response
|
read -r -p "$* (Y/n) " response
|
||||||
case "${response,,}" in
|
case "${response,,}" in
|
||||||
'') return 0 ;;
|
'') return 0 ;;
|
||||||
|
@ -59,6 +69,41 @@ ask() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try() {
|
||||||
|
local response
|
||||||
|
local cmd_status
|
||||||
|
local prompt_parens="([1mS[mhell/[1mr[metry/[1mc[mancel/[1mp[mrint)"
|
||||||
|
|
||||||
|
# Outer loop, allows us to retry the command
|
||||||
|
while true; do
|
||||||
|
# Try command
|
||||||
|
"$@"
|
||||||
|
cmd_status="$?"
|
||||||
|
|
||||||
|
if [[ "$cmd_status" != 0 ]]; then
|
||||||
|
echo_console "[1;31m * Command failed: [1;33m\$[m $*"
|
||||||
|
echo_console -n "Last command failed (code $cmd_status), specify next action $prompt_parens "
|
||||||
|
|
||||||
|
# Prompt until input is valid
|
||||||
|
while true; do
|
||||||
|
flush_stdin
|
||||||
|
read -r response
|
||||||
|
case "${response,,}" in
|
||||||
|
''|s|shell)
|
||||||
|
echo_console "Hint: The script log is at '$GENTOO_BOOTSTRAP_DIR/log.out'"
|
||||||
|
echo_console "You will be prompted for action again after exiting this shell."
|
||||||
|
/bin/bash --init-file <(echo "disable_logging; source $TMP_DIR/.bashrc")
|
||||||
|
;;
|
||||||
|
r|retry) continue 2 ;;
|
||||||
|
c|cancel) die "Installation cancelled" ;;
|
||||||
|
p|print) echo_console "[1;33m\$[m $*" ;;
|
||||||
|
*) echo_console -n "Response not understood $prompt_parens " ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
countdown() {
|
countdown() {
|
||||||
echo -n "$1" >&3
|
echo -n "$1" >&3
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue