snapshot while working out backup/restore issues

master
phanes 2023-02-26 19:31:42 -05:00
parent b513be8d4d
commit c4192e2328
8 changed files with 710 additions and 144 deletions

View File

@ -66,18 +66,37 @@ function clear_stage() {
make clean make clean
} }
function fail_easy() {
logprint "$1"
exit 0
}
function restore() { function restore() {
# select a backup file backup_files=($(ls $project_root | grep "backup.tgz"))
FILE=$(dialog --title "Choose a restore point." --stdout --title "Please choose an archive to restore from." --fselect ${project_root} 14 48) # Create an array to store the options for the dialog
options=()
for file in "${backup_files[@]}"; do
options+=("$file" "$file" off)
done
[ ! -z $FILE ] || logprint "User canceled restore." && exit 0
selected=$(dialog --clear --title "Backup Files" \
--radiolist "Select a backup file:" 20 75 15 \
"${options[@]}" \
3>&1 1>&2 2>&3)
response=$?
echo "User selected '$selected'"
[ ! -z $selected ] || fail_easy "User canceled restore."
dialog --backtitle "Dark Horse Linux: Pyrois" --title "Restore From Backup" --yesno "Selected: '$selected'." 10 60
response=$?
if [ $response -eq 0 ]; then
logprint "Entering backup routine. Clearing stage." logprint "Entering backup routine. Clearing stage."
clear_stage clear_stage
sleep 1
logprint "Restoring backup...This will take a long time..." logprint "Restoring backup...This will take a long time..."
tar xphf $FILE tar xphf ${project_root}/$selected
assert_zero $? assert_zero $?
logprint "Backup restored successfully. Arming chroot." logprint "Backup restored successfully. Arming chroot."
@ -87,6 +106,12 @@ function restore() {
echo echo
logprint "You may now proceed to run 'make build_stage4' or higher." logprint "You may now proceed to run 'make build_stage4' or higher."
echo echo
else
logprint "User canceled. Moving on."
exit 0
fi
} }

View File

@ -0,0 +1,222 @@
#!/bin/bash
# desc:
# stages, builds, installs
# make variables persist in subprocesses for logging function
set -a
# ----------------------------------------------------------------------
# Configuration:
# ----------------------------------------------------------------------
# the name of this application
APPNAME="file"
# the version of this application
VERSION="5.39"
# ----------------------------------------------------------------------
# Variables and functions sourced from Environment:
# ----------------------------------------------------------------------
# assert_zero()
# Checks if $1 is 0. If non-0 value, halts the execution of the script.
#
# LOGS_ROOT
# The parent directory where logs from this project will go.
#
# TEMP_STAGE_DIR
# The parent directory of where source archives are extracted to.
# register mode selections
ARGUMENT_LIST=(
"stage"
"build_temp"
"install_temp"
"all_temp"
"help"
)
# modes to associate with switches
# assumes you want nothing done unless you ask for it.
MODE_STAGE=false
MODE_BUILD_TEMP=false
MODE_INSTALL_TEMP=false
MODE_ALL_TEMP=false
MODE_HELP=false
# the file to log to
LOGFILE="${APPNAME}.log"
# ISO 8601 variation
TIMESTAMP="$(date +%Y-%m-%d_%H:%M:%S)"
# the path where logs are written to
# note: LOGS_ROOT is sourced from environment
LOG_DIR="${LOGS_ROOT}/${APPNAME}-${TIMESTAMP}"
# the path where the source will be located when complete
# note: TEMP_STAGE_DIR is sourced from environment
T_SOURCE_DIR="${TEMP_STAGE_DIR}/${APPNAME}"
# read defined arguments
opts=$(getopt \
--longoptions "$(printf "%s," "${ARGUMENT_LIST[@]}")" \
--name "$APPNAME" \
--options "" \
-- "$@"
)
# process supplied arguments into flags that enable execution modes
eval set --$opts
while [[ $# -gt 0 ]]; do
case "$1" in
--stage)
MODE_STAGE=true
shift 1
;;
--build_temp)
MODE_BUILD_TEMP=true
shift 1
;;
--install_temp)
MODE_INSTALL_TEMP=true
shift 1
;;
--all_temp)
MODE_ALL_TEMP=true
shift 1
;;
--help)
MODE_HELP=true
shift 1
;;
*)
break
;;
esac
done
# print to stdout, print to log
logprint() {
mkdir -p "${LOG_DIR}"
echo "[$(date +%Y-%m-%d_%H:%M:%S)] [${APPNAME}] $1" \
| tee -a "${LOG_DIR}/${LOGFILE}"
}
# Tell the user we're alive...
logprint "Initializing the ${APPNAME} utility..."
# when the stage mode is enabled, this will execute
mode_stage() {
logprint "Starting stage of ${APPNAME}..."
logprint "Removing any pre-existing staging for ${APPNAME}."
rm -Rf "${T_SOURCE_DIR}"*
logprint "Extracting ${APPNAME}-${VERSION} source archive to ${TEMP_STAGE_DIR}"
tar xf "${SOURCES_DIR}/${APPNAME}-${VERSION}.tar."* -C "${TEMP_STAGE_DIR}"
assert_zero $?
# conditionally rename if it needs it
stat "${T_SOURCE_DIR}-"* && mv "${T_SOURCE_DIR}-"* "${T_SOURCE_DIR}"
logprint "Staging operation complete."
}
# when the build_pass1 mode is enabled, this will execute
mode_build_temp() {
# patch, configure and build
logprint "Starting build of ${APPNAME}..."
logprint "Entering stage dir."
pushd "${T_SOURCE_DIR}"
assert_zero $?
logprint "Building a local file for signature file generation"
mkdir -pv build
pushd build
assert_zero $?
../configure --disable-bzlib --disable-libseccomp --disable-xzlib --disable-zlib
assert_zero $?
make
assert_zero $?
popd
logprint "Configuring ${APPNAME}..."
./configure \
--prefix=/usr \
--host=${T_TRIPLET} \
--build=$(./config.guess)
assert_zero $?
logprint "Compiling..."
make FILE_COMPILE=$(pwd)/build/src/file
assert_zero $?
logprint "Build operation complete."
}
mode_install_temp() {
logprint "Starting install of ${APPNAME}..."
pushd "${T_SOURCE_DIR}/build"
assert_zero $?
logprint "Installing..."
make DESTDIR=${T_SYSROOT} install
assert_zero $?
logprint "Install operation complete."
}
mode_help() {
echo "${APPNAME} [ --stage ] [ --build_temp ] [ --install_temp ] [ --all_temp ] [ --help ]"
exit 1
}
if [ "$MODE_ALL_TEMP" = "true" ]; then
MODE_STAGE=true
MODE_BUILD_TEMP=true
MODE_INSTALL_TEMP=true
fi
# if no options were selected, then show help and exit
if \
[ "$MODE_HELP" != "true" ] && \
[ "$MODE_STAGE" != "true" ] && \
[ "$MODE_BUILD_TEMP" != "true" ] && \
[ "$MODE_INSTALL_TEMP" != "true" ]
then
logprint "No option selected during execution."
mode_help
fi
# if help was supplied at all, show help and exit
if [ "$MODE_HELP" = "true" ]; then
logprint "Help option selected. Printing options and exiting."
mode_help
fi
if [ "$MODE_STAGE" = "true" ]; then
logprint "Staging option selected."
mode_stage
assert_zero $?
fi
if [ "$MODE_BUILD_TEMP" = "true" ]; then
logprint "Build of ${APPNAME} selected."
mode_build_temp
assert_zero $?
fi
if [ "$MODE_INSTALL_TEMP" = "true" ]; then
logprint "Install of ${APPNAME} selected."
mode_install_temp
assert_zero $?
fi
logprint "Execution of ${APPNAME} completed."

View File

@ -0,0 +1,232 @@
#!/bin/bash
# desc:
# stages, builds, installs
# make variables persist in subprocesses for logging function
set -a
# ----------------------------------------------------------------------
# Configuration:
# ----------------------------------------------------------------------
# the name of this application
APPNAME="readline"
# the version of this application
VERSION="8.1"
# ----------------------------------------------------------------------
# Variables and functions sourced from Environment:
# ----------------------------------------------------------------------
# assert_zero()
# Checks if $1 is 0. If non-0 value, halts the execution of the script.
#
# LOGS_ROOT
# The parent directory where logs from this project will go.
#
# TEMP_STAGE_DIR
# The parent directory of where source archives are extracted to.
# register mode selections
ARGUMENT_LIST=(
"stage"
"build"
"install"
"all"
"help"
)
# modes to associate with switches
# assumes you want nothing done unless you ask for it.
MODE_STAGE=false
MODE_BUILD=false
MODE_INSTALL=false
MODE_ALL=false
MODE_HELP=false
# the file to log to
LOGFILE="${APPNAME}.log"
# ISO 8601 variation
TIMESTAMP="$(date +%Y-%m-%d_%H:%M:%S)"
# the path where logs are written to
# note: LOGS_ROOT is sourced from environment
LOG_DIR="${LOGS_ROOT}/${APPNAME}-${TIMESTAMP}"
# the path where the source will be located when complete
# note: TEMP_STAGE_DIR is sourced from environment
T_SOURCE_DIR="${TEMP_STAGE_DIR}/${APPNAME}"
# read defined arguments
opts=$(getopt \
--longoptions "$(printf "%s," "${ARGUMENT_LIST[@]}")" \
--name "$APPNAME" \
--options "" \
-- "$@"
)
# process supplied arguments into flags that enable execution modes
eval set --$opts
while [[ $# -gt 0 ]]; do
case "$1" in
--stage)
MODE_STAGE=true
shift 1
;;
--build)
MODE_BUILD=true
shift 1
;;
--install)
MODE_INSTALL=true
shift 1
;;
--all)
MODE_ALL=true
shift 1
;;
--help)
MODE_HELP=true
shift 1
;;
*)
break
;;
esac
done
# print to stdout, print to log
logprint() {
mkdir -p "${LOG_DIR}"
echo "[$(date +%Y-%m-%d_%H:%M:%S)] [${APPNAME}] $1" \
| tee -a "${LOG_DIR}/${LOGFILE}"
}
# Tell the user we're alive...
logprint "Initializing the ${APPNAME} utility..."
# when the stage mode is enabled, this will execute
mode_stage() {
logprint "Starting stage of ${APPNAME}..."
logprint "Removing any pre-existing staging for ${APPNAME}."
rm -Rf "${T_SOURCE_DIR}"*
logprint "Extracting ${APPNAME}-${VERSION} source archive to ${TEMP_STAGE_DIR}"
tar xf "${SOURCES_DIR}/${APPNAME}-${VERSION}.tar."* -C "${TEMP_STAGE_DIR}"
assert_zero $?
# conditionally rename if it needs it
stat "${T_SOURCE_DIR}-"* && mv "${T_SOURCE_DIR}-"* "${T_SOURCE_DIR}"
logprint "Staging operation complete."
}
# when the build_pass1 mode is enabled, this will execute
mode_build() {
# patch, configure and build
logprint "Starting build of ${APPNAME}..."
logprint "Entering stage dir."
pushd "${T_SOURCE_DIR}"
assert_zero $?
logprint "Applying patches..."
patch -Np1 -i ${PATCHES_DIR}/readline-8.1-ldconfig_fix.patch
assert_zero $?
logprint "Configuring ${APPNAME}"
./configure \
--prefix=/usr \
--disable-static \
--with-curses \
--docdir=/usr/share/doc/readline-8.1
assert_zero $?
logprint "Compiling..."
make SHLIB_LIBS="-lncursesw"
assert_zero $?
logprint "Checking ${APPNAME}"
make check
logprint "Build operation complete."
}
mode_install() {
logprint "Starting install of ${APPNAME}..."
pushd "${T_SOURCE_DIR}"
assert_zero $?
logprint "Installing..."
make SHLIB_LIBS="-lncursesw" install
assert_zero $?
logprint "Cleaning up..."
mv -v /usr/lib/lib{readline,history}.so.* /lib
assert_zero $?
ln -sfv ../../lib/$(readlink /usr/lib/libreadline.so) /usr/lib/libreadline.so
assert_zero $?
ln -sfv ../../lib/$(readlink /usr/lib/libhistory.so ) /usr/lib/libhistory.so
assert_zero $?
logprint "Installing documentation..."
install -v -m644 doc/*.{ps,pdf,html,dvi} /usr/share/doc/readline-8.1
assert_zero $?
logprint "Install operation complete."
}
mode_help() {
echo "${APPNAME} [ --stage ] [ --build ] [ --install ] [ --all ] [ --help ]"
exit 1
}
if [ "$MODE_ALL" = "true" ]; then
MODE_STAGE=true
MODE_BUILD=true
MODE_INSTALL=true
fi
# if no options were selected, then show help and exit
if \
[ "$MODE_HELP" != "true" ] && \
[ "$MODE_STAGE" != "true" ] && \
[ "$MODE_BUILD" != "true" ] && \
[ "$MODE_INSTALL" != "true" ]
then
logprint "No option selected during execution."
mode_help
fi
# if help was supplied at all, show help and exit
if [ "$MODE_HELP" = "true" ]; then
logprint "Help option selected. Printing options and exiting."
mode_help
fi
if [ "$MODE_STAGE" = "true" ]; then
logprint "Staging option selected."
mode_stage
assert_zero $?
fi
if [ "$MODE_BUILD" = "true" ]; then
logprint "Build of ${APPNAME} selected."
mode_build
assert_zero $?
fi
if [ "$MODE_INSTALL" = "true" ]; then
logprint "Install of ${APPNAME} selected."
mode_install
assert_zero $?
fi
logprint "Execution of ${APPNAME} completed."

View File

@ -0,0 +1,214 @@
#!/bin/bash
# desc:
# stages, builds, installs
# make variables persist in subprocesses for logging function
set -a
# ----------------------------------------------------------------------
# Configuration:
# ----------------------------------------------------------------------
# the name of this application
APPNAME="zstd"
# the version of this application
VERSION="1.4.8"
# ----------------------------------------------------------------------
# Variables and functions sourced from Environment:
# ----------------------------------------------------------------------
# assert_zero()
# Checks if $1 is 0. If non-0 value, halts the execution of the script.
#
# LOGS_ROOT
# The parent directory where logs from this project will go.
#
# TEMP_STAGE_DIR
# The parent directory of where source archives are extracted to.
# register mode selections
ARGUMENT_LIST=(
"stage"
"build"
"install"
"all"
"help"
)
# modes to associate with switches
# assumes you want nothing done unless you ask for it.
MODE_STAGE=false
MODE_BUILD=false
MODE_INSTALL=false
MODE_ALL=false
MODE_HELP=false
# the file to log to
LOGFILE="${APPNAME}.log"
# ISO 8601 variation
TIMESTAMP="$(date +%Y-%m-%d_%H:%M:%S)"
# the path where logs are written to
# note: LOGS_ROOT is sourced from environment
LOG_DIR="${LOGS_ROOT}/${APPNAME}-${TIMESTAMP}"
# the path where the source will be located when complete
# note: TEMP_STAGE_DIR is sourced from environment
T_SOURCE_DIR="${TEMP_STAGE_DIR}/${APPNAME}"
# read defined arguments
opts=$(getopt \
--longoptions "$(printf "%s," "${ARGUMENT_LIST[@]}")" \
--name "$APPNAME" \
--options "" \
-- "$@"
)
# process supplied arguments into flags that enable execution modes
eval set --$opts
while [[ $# -gt 0 ]]; do
case "$1" in
--stage)
MODE_STAGE=true
shift 1
;;
--build)
MODE_BUILD=true
shift 1
;;
--install)
MODE_INSTALL=true
shift 1
;;
--all)
MODE_ALL=true
shift 1
;;
--help)
MODE_HELP=true
shift 1
;;
*)
break
;;
esac
done
# print to stdout, print to log
logprint() {
mkdir -p "${LOG_DIR}"
echo "[$(date +%Y-%m-%d_%H:%M:%S)] [${APPNAME}] $1" \
| tee -a "${LOG_DIR}/${LOGFILE}"
}
# Tell the user we're alive...
logprint "Initializing the ${APPNAME} utility..."
# when the stage mode is enabled, this will execute
mode_stage() {
logprint "Starting stage of ${APPNAME}..."
logprint "Removing any pre-existing staging for ${APPNAME}."
rm -Rf "${T_SOURCE_DIR}"*
logprint "Extracting ${APPNAME}-${VERSION} source archive to ${TEMP_STAGE_DIR}"
tar xf "${SOURCES_DIR}/${APPNAME}-${VERSION}.tar."* -C "${TEMP_STAGE_DIR}"
assert_zero $?
# conditionally rename if it needs it
stat "${T_SOURCE_DIR}-"* && mv "${T_SOURCE_DIR}-"* "${T_SOURCE_DIR}"
logprint "Staging operation complete."
}
# when the build_pass1 mode is enabled, this will execute
mode_build() {
# patch, configure and build
logprint "Starting build of ${APPNAME}..."
logprint "Entering stage dir."
pushd "${T_SOURCE_DIR}"
assert_zero $?
logprint "Compiling..."
make
assert_zero $?
logprint "Checking ${APPNAME}"
make check
logprint "Build operation complete."
}
mode_install() {
logprint "Starting install of ${APPNAME}..."
pushd "${T_SOURCE_DIR}"
assert_zero $?
logprint "Installing..."
make prefix=/usr install
assert_zero $?
logprint "Cleaning up..."
mv -v /usr/lib/libzstd.so.* /lib
assert_zero $?
# what a weird practice...
ln -sfv ../../lib/$(readlink /usr/liblibzstd.so) /usr/lib/libzstd.so
assert_zero $?
logprint "Install operation complete."
}
mode_help() {
echo "${APPNAME} [ --stage ] [ --build ] [ --install ] [ --all ] [ --help ]"
exit 1
}
if [ "$MODE_ALL" = "true" ]; then
MODE_STAGE=true
MODE_BUILD=true
MODE_INSTALL=true
fi
# if no options were selected, then show help and exit
if \
[ "$MODE_HELP" != "true" ] && \
[ "$MODE_STAGE" != "true" ] && \
[ "$MODE_BUILD" != "true" ] && \
[ "$MODE_INSTALL" != "true" ]
then
logprint "No option selected during execution."
mode_help
fi
# if help was supplied at all, show help and exit
if [ "$MODE_HELP" = "true" ]; then
logprint "Help option selected. Printing options and exiting."
mode_help
fi
if [ "$MODE_STAGE" = "true" ]; then
logprint "Staging option selected."
mode_stage
assert_zero $?
fi
if [ "$MODE_BUILD" = "true" ]; then
logprint "Build of ${APPNAME} selected."
mode_build
assert_zero $?
fi
if [ "$MODE_INSTALL" = "true" ]; then
logprint "Install of ${APPNAME} selected."
mode_install
assert_zero $?
fi
logprint "Execution of ${APPNAME} completed."

View File

@ -55,7 +55,7 @@ function perform_backup() {
disarm_chroot disarm_chroot
disarm_chroot disarm_chroot
logprint "Performing backup...This will take a long time..." logprint "Performing backup...This will take a long time..."
tar czfp ${project_root}/${TIMESTAMP}.backup.tgz ${dir_stage} tar cpzf ${project_root}/${TIMESTAMP}.backup.tgz ${dir_stage}
assert_zero $? assert_zero $?
logprint "Backup completed successfully. Moving on." logprint "Backup completed successfully. Moving on."
logprint "Entering project root." logprint "Entering project root."

View File

@ -1,95 +0,0 @@
#!/bin/bash
# move this to the makefile as a dedicated target
APPNAME="Offer Backup"
# ISO 8601 variation
TIMESTAMP="$(date +%Y-%m-%d_%H:%M:%S)"
LOG_DIR="${LOGS_ROOT}/${APPNAME}-${TIMESTAMP}"
# the file to log to
LOGFILE="${APPNAME}.log"
logprint() {
mkdir -p "${LOG_DIR}"
echo "[$(date +%Y-%m-%d_%H:%M:%S)] [${APPNAME}] $1" \
| tee -a "${LOG_DIR}/${LOGFILE}"
}
logprint "Giving the user the option of backing up before proceeding."
is_mounted() {
findmnt $1 &> /dev/null
if [ $? != 0 ]; then
logprint "Not mounted...skipping."
/usr/bin/false
else
logprint "Mounted..."
/usr/bin/true
fi
}
function disarm_chroot() {
logprint "Unmounting CHROOT VFKS mounts"
logprint "Unmounting ${T_SYSROOT}/dev"
is_mounted ${T_SYSROOT}/dev && umount -l ${T_SYSROOT}/dev
logprint "Unmounting ${T_SYSROOT}/dev/pts"
is_mounted ${T_SYSROOT}/dev/pts && umount -l ${T_SYSROOT}/dev/pts
logprint "Unmounting ${T_SYSROOT}/proc"
is_mounted ${T_SYSROOT}/proc && umount -l ${T_SYSROOT}/proc
# not a symlink on ubuntu
logprint "Unmounting ${T_SYSROOT}/dev/shm"
is_mounted ${T_SYSROOT}/dev/shm && umount -l ${T_SYSROOT}/dev/shm
logprint "Unmounting pyrois inside of chroot"
is_mounted ${T_SYSROOT}/rex_embedded && umount -l ${T_SYSROOT}/rex_embedded
}
function clear_stage() {
pushd ${project_root}
make clean
}
function restore() {
# select a backup file
FILE=$(dialog --title "Choose a restore point." --stdout --title "Please choose an archive to restore from." --fselect ${project_root} 14 48)
logprint "Entering backup routine."
disarm_chroot
disarm_chroot
logprint "Restoring backup...This will take a long time..."
tar xpf $FILE
assert_zero $?
logprint "Backup restored successfully. Arming chroot."
pushd ${project_root}
assert_zero $?
make arm_chroot
echo
logprint "You may now proceed to run 'make build_stage4' or higher."
echo
}
read -r -d '' yn_msg <<-'EOF'
Restore from backup?
EOF
# Use the dialog utility to prompt the user with a yes/no question
dialog --backtitle "Dark Horse Linux: Pyrois" --title "Restore From Backup" --yesno "$yn_msg" 10 60
response=$?
if [ $response -eq 0 ]; then
logprint "User selected to perform backups."
restore
else
logprint "User canceled. Moving on."
exit 0
fi

View File

@ -1,10 +0,0 @@
{
"plan":
[
{
"name": "restore backup",
"dependencies": [ null ],
"comment": "LFS 11.3-systemd-rc1 Ch. 7.13.2"
}
]
}

View File

@ -1,22 +0,0 @@
{
"units": [
{
"name": "restore backup",
"target": "components/stage4backup/restore_backup.bash",
"is_shell_command": true,
"shell_definition": "bash",
"force_pty": true,
"set_working_directory": false,
"working_directory": "",
"rectify": false,
"rectifier": "",
"active": true,
"required": true,
"set_user_context": true,
"user": "root",
"group": "root",
"supply_environment": true,
"environment": "environments/stage2.env.bash"
}
]
}