Fix bugs in install script execution.

This commit is contained in:
awalsh128 2022-11-19 17:20:30 -08:00
parent 2fcdd38327
commit f076e88841
2 changed files with 10 additions and 6 deletions

12
lib.sh
View file

@ -12,7 +12,8 @@
############################################################################### ###############################################################################
function execute_install_script { function execute_install_script {
local package_name=$(basename ${2} | awk -F\: '{print $1}') local package_name=$(basename ${2} | awk -F\: '{print $1}')
local install_script_filepath=$(get_install_filepath "${1}" "${package_name}" "${3}") local install_script_filepath=$(\
get_install_filepath "${1}" "${package_name}" "${3}")
if test ! -z "${install_script_filepath}"; then if test ! -z "${install_script_filepath}"; then
log "- Executing ${install_script_filepath}..." log "- Executing ${install_script_filepath}..."
# Don't abort on errors; dpkg-trigger will error normally since it is outside # Don't abort on errors; dpkg-trigger will error normally since it is outside
@ -87,9 +88,10 @@ function get_package_name_from_cached_filepath {
# Filepath of the script file, otherwise an empty string. # Filepath of the script file, otherwise an empty string.
############################################################################### ###############################################################################
function get_install_filepath { function get_install_filepath {
local error_on_exit=$(shopt -op | grep errexit)
# Filename includes arch (e.g. amd64). # Filename includes arch (e.g. amd64).
local filepath="$(ls -1 ${1}/var/lib/dpkg/info/${2}:*.${3} 2> /dev/null | head -1 || true)" local filepath="$(\
ls -1 ${1}var/lib/dpkg/info/${2}*.${3} \
| grep -E ${2}'(:.*)?.'${3} | head -1)"
test "${filepath}" && echo "${filepath}" test "${filepath}" && echo "${filepath}"
} }
@ -125,7 +127,9 @@ function log_empty_line { echo ""; }
function normalize_package_list { function normalize_package_list {
local stripped=$(echo "${1}" | sed 's/,//g') local stripped=$(echo "${1}" | sed 's/,//g')
# Remove extraneous spaces at the middle, beginning, and end. # Remove extraneous spaces at the middle, beginning, and end.
local trimmed="$(echo "${stripped}" | sed 's/\s\+/ /g; s/^\s\+//g; s/\s\+$//g')" local trimmed="$(\
echo "${stripped}" \
| sed 's/\s\+/ /g; s/^\s\+//g; s/\s\+$//g')"
local sorted="$(echo ${trimmed} | tr ' ' '\n' | sort | tr '\n' ' ')" local sorted="$(echo ${trimmed} | tr ' ' '\n' | sort | tr '\n' ' ')"
echo "${sorted}" echo "${sorted}"
} }

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash -x
# Fail on any error. # Fail on any error.
set -e set -e
@ -46,7 +46,7 @@ for cached_pkg_filepath in ${cached_pkg_filepaths}; do
log " done" log " done"
# Execute install scripts if available. # Execute install scripts if available.
if test "${execute_install_scripts}" == "true"; then if test ${execute_install_scripts} == "true"; then
# May have to add more handling for extracting pre-install script before extracting all files. # May have to add more handling for extracting pre-install script before extracting all files.
# Keeping it simple for now. # Keeping it simple for now.
execute_install_script "${cache_restore_root}" "${cached_pkg_filepath}" preinst install execute_install_script "${cache_restore_root}" "${cached_pkg_filepath}" preinst install