From 4103bae6d29b50d2dabb7af7be7676b705944da2 Mon Sep 17 00:00:00 2001 From: davidovski Date: Sun, 20 Mar 2022 10:46:08 +0000 Subject: added file validation --- src/get.sh | 25 +++++++++++++------------ src/validate.sh | 17 +++++++++++++++++ src/xi.sh | 12 +++++++++++- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/get.sh b/src/get.sh index 6c23767..778dbe6 100755 --- a/src/get.sh +++ b/src/get.sh @@ -165,38 +165,39 @@ get () { total_download=$((total_download+size)) done - # TODO tidy this ${QUIET} || { [ "${missing}" ] && - printf "${LIGHT_RED}The following packages could not be located:${RED} %s\n${RESET}" $missing + printf "${LIGHT_RED}The following packages could not be located:${RED} $missing\n${RESET}" [ "${update}" ] && - printf "${LIGHT_GREEN}The following packages will be updated:\n\t${GREEN}%s\n${RESET}" $update + printf "${LIGHT_GREEN}The following packages will be updated:\n\t${GREEN}$update\n${RESET}" [ "${install}" ] && - printf "${LIGHT_BLUE}The following packages will be installed:\n\t${BLUE}%s\n${RESET}" $install + printf "${LIGHT_BLUE}The following packages will be installed:\n\t${BLUE}$install\n${RESET}" [ ! "${install}" ] && [ ! "${update}" ] && [ "${already}" ] && - printf "${LIGHT_WHITE}The following packages are already up to date:\n\t${WHITE}%s\n${RESET}" $already + printf "${LIGHT_WHITE}The following packages are already up to date:\n\t${WHITE}$already\n${RESET}" } - [ ! "${#install}" = "0" ] && [ "${#update}" = 0 ] && printf "${LIGHT_RED}Nothing to do!\n" && return 0 + [ "${#install}" = "0" ] && [ "${#update}" = 0 ] && { + printf "${LIGHT_RED}Nothing to do!\n" + return 0 + } ${QUIET} || { [ "${SYSROOT}" = "/" ] || printf "${WHITE}To install to ${LIGHT_WHITE}${SYSROOT}${RESET}\n" printf "${WHITE}Total download size:${LIGHT_WHITE} $(format_bytes $total_download)\n" } - if prompt_question "${WHITE}Continue?"; then - download_packages $total_download ${install} ${update} - else + prompt_question "${WHITE}Continue?" && + download_packages $total_download ${install} ${update} || { ${QUIET} || printf "${RED}Action canceled by user\n" - fi + } } fetch () { - local packages=$@ \ - outputs="" + local packages=$@ + local outputs="" local total_download=0 for package in $packages; do diff --git a/src/validate.sh b/src/validate.sh index 42530bb..0c9dd2d 100644 --- a/src/validate.sh +++ b/src/validate.sh @@ -56,3 +56,20 @@ keyimport () { esac set +o noglob } + +validate_files () { + local package=$1 + local ret=0 + + # TODO ensure that all checksums are the same + for file in $(files $package); do + if [ -f "${SYSROOT}$file" ]; then + ${VERBOSE} && printf "${GREEN}%s is present\n" $file + else + ret=$((ret+1)) + ${QUIET} || printf "${RED}%s is missing\n" $file + fi + done + ${QUIET} || printf "${RESET}" + return $ret +} diff --git a/src/xi.sh b/src/xi.sh index 6cbb315..9bb6bbf 100755 --- a/src/xi.sh +++ b/src/xi.sh @@ -47,8 +47,10 @@ Available Commands: search the database for a package files [package] list files belonging to a package + verify [package] + verify that a package's files are intact list - list available packagesa + list available packages list-installed lists installed packages file [path] @@ -176,6 +178,14 @@ else shift file_info $@ ;; + "verify") + shift + [ -z "$*" ] && set -- $(ls ${INSTALLED_DIR}) + while [ ! -z "$*" ]; do + validate_files $1 || printf "${LIGHT_RED}Failed to verify $1\n" + shift + done + ;; "bootstrap") shift . ${LIBDIR}/bootstrap.sh -- cgit v1.2.1