From 8758658db49688b7cc7b55603db1b8438775ccc4 Mon Sep 17 00:00:00 2001 From: davidovski Date: Wed, 4 May 2022 23:59:42 +0100 Subject: made help screen colorful --- src/get.sh | 24 +++++----- src/install.sh | 36 +++++++-------- src/xi.sh | 141 +++++++++++++++++++++++++++++++-------------------------- 3 files changed, 108 insertions(+), 93 deletions(-) diff --git a/src/get.sh b/src/get.sh index d4a70a0..0107897 100755 --- a/src/get.sh +++ b/src/get.sh @@ -120,16 +120,15 @@ download_packages () { outputs="$outputs ${out_dir}/${checksum}.${package}.xipkg" done fetch_serial $total_download $outputs - - validate_downloads $outputs + ${UNSAFE} || validate_downloads $outputs + echo $outputs >> "${CACHE_DIR}/toinstall" } # validate signatures of downloaded packages # -# outputs: list of xipkg files to verify and install validate_downloads () { local i=0 - ${UNSAFE} || for pkg_file in $@; do + for pkg_file in $@; do ${QUIET} || hbar -T "${LARGE_CIRCLE} validating downloads..." $i $# @@ -140,13 +139,12 @@ validate_downloads () { else i=$((i+1)) fi - done && + done ${QUIET} || hbar -t ${HBAR_COMPLETE} -T "${CHECKMARK} validated downloads" $i $# - - install $@ } -# get and install requested packages +# fetch requested packages +# and ultimately write the list of package files to toinstall # get () { local requested=$@ @@ -154,14 +152,18 @@ get () { local total_download=0 local out="${CACHE_DIR}/deps" + [ "$#" = "0" ] && return 0 + + $DO_SYNC && sync + touch $out resolve_deps $@ for package in $(cat $out); do - if ! package_exists $package; then - missing="$missing $package" + package_exists $package || { + missing="$missing $package" continue - fi + } set -- $(get_package_download_info $package) checksum=$2 diff --git a/src/install.sh b/src/install.sh index 3168fdc..1b7fe9a 100644 --- a/src/install.sh +++ b/src/install.sh @@ -17,6 +17,7 @@ install_package () { set -- $(md5sum $pkg_file) local package_checksum=$1 if [ ! -f $checksum ] || [ "$(cat $checksum)" != "$package_checksum" ]; then + [ ! -d $installed_dir ] && mkdir -p "$installed_dir" [ -f "$files" ] && { @@ -46,8 +47,7 @@ total_filecount() { local packages=$@ local count=0 for package in $packages; do - local name=$(basename $package .xipkg | cut -d. -f2) - local c=$(get_package_filecount $name) + c=$(tar -tvvf $package | grep -v ^d | wc -l) count=$((count+c)) done echo $count @@ -55,26 +55,28 @@ total_filecount() { run_postinstall () { postinstall="${SYSROOT}/var/lib/xipkg/postinstall" - if [ -d $postinstall ]; then + [ -d $postinstall ] && for f in $(ls $postinstall); do file=$postinstall/$f - # run the postinstall file - # chmod 755 $file - if [ "${SYSROOT}" = "/" ]; then - sh "/var/lib/xipkg/postinstall/$f" - else - xichroot ${SYSROOT} "/var/lib/xipkg/postinstall/$f" - fi - if [ "$?" = "0" ]; then + + [ "${SYSROOT}" = "/" ] && { + sh "/var/lib/xipkg/postinstall/$f" 2> ${LOG_FILE} > ${LOG_FILE} + + } || { + xichroot ${SYSROOT} "/var/lib/xipkg/postinstall/$f" 2> ${LOG_FILE} > ${LOG_FILE} + + } + + [ "$?" = "0" ] && { rm $file && - printf "${GREEN}${CHECKMARK} run postinstall for $f!\n" - else - printf "${RED}${CROSSMARK} failed running postinstall for $f!\n" - fi + printf "${GREEN}${CHECKMARK} postinstall $f!\n" + } || { + printf "${RED}${CROSSMARK} failed postinstall $f!\n" + } + done - fi } @@ -93,8 +95,6 @@ install () { if [ "${#missing}" != "0" ]; then ${VERBOSE} && printf "${BLACK}couldnt find: $missing\n${RESET}" - # warning: potential recursion loop here - get $missing else local total=$(total_filecount $packages 2>/dev/null || echo 1) diff --git a/src/xi.sh b/src/xi.sh index 04dfe2d..f63bfd7 100755 --- a/src/xi.sh +++ b/src/xi.sh @@ -1,66 +1,70 @@ #!/bin/sh usage () { -cat << "EOF" -Usage: xi [options] command... - -Available Options: - -r [path] - specify the installation root [default: /] - -c [path] - specify the config file to use [default: /etc/xipkg.conf] - -q - supress unecessary outputs - -v - be more verbose - -n - do not resolve package dependenceies - -l - do not sync databases (ignored when explicitly running sync) - -u - do not validate against keychain - -y - skip prompts - -h - show help and exists - -Available Commands: - sync - sync the local package database with the remote repositories - - install [packages..] - install package(s) into the system - update - update all packages on the system - remove [packages...] - remove packages from the system - reinstall [packages..] - remove and reinstall package(s) into the system - fetch [package] - download a .xipkg file - keyimport [name] [url] - import a key from a url - clean - clean cached files and data - - search [query] - 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 packages - list-installed - lists installed packages - file [path] - shows which package a file belongs to - - bootstrap [additional packages...] - installs base packages and system files to an empty system - - help - shows this message +cat << EOF +${LIGHT_WHITE}XiPkg Version $VERSION + +${BLUE}Available Options: + ${BLUE}-r ${LIGHT_BLUE}[path] + ${LIGHT_CYAN}specify the installation root ${LIGHT_WHITE}[default: /] + ${BLUE}-c [path] + ${LIGHT_CYAN}specify the config file to use ${LIGHT_WHITE}[default: /etc/xipkg.conf] + ${BLUE}-q + ${LIGHT_CYAN}supress unecessary outputs + ${BLUE}-v + ${LIGHT_CYAN}be more verbose + ${BLUE}-n + ${LIGHT_CYAN}do not resolve package dependenceies + ${BLUE}-l + ${LIGHT_CYAN}do not sync databases (ignored when explicitly running sync) + ${BLUE}-u + ${LIGHT_CYAN}do not validate against keychain + ${BLUE}-y + ${LIGHT_CYAN}skip prompts + ${BLUE}-h + ${LIGHT_CYAN}show help and exists + +${BLUE}Available Commands: + ${LIGHT_GREEN}sync + ${LIGHT_CYAN}sync the local package database with the remote repositories + + ${LIGHT_GREEN}install ${LIGHT_BLUE}[packages..] + ${LIGHT_CYAN}install package(s) into the system + ${LIGHT_GREEN}update + ${LIGHT_CYAN}update all packages on the system + ${LIGHT_GREEN}remove ${LIGHT_BLUE}[packages...] + ${LIGHT_CYAN}remove packages from the system + ${LIGHT_GREEN}reinstall ${LIGHT_BLUE}[packages..] + ${LIGHT_CYAN}remove and reinstall package(s) into the system + ${LIGHT_GREEN}fetch ${LIGHT_BLUE}[package] + ${LIGHT_CYAN}download a .xipkg file + ${LIGHT_GREEN}keyimport ${LIGHT_BLUE}[name] [url] + ${LIGHT_CYAN}import a key from a url + ${LIGHT_GREEN}clean + ${LIGHT_CYAN}clean cached files and data + + ${LIGHT_GREEN}search ${LIGHT_BLUE}[query] + ${LIGHT_CYAN}search the database for a package + ${LIGHT_GREEN}files ${LIGHT_BLUE}[package] + ${LIGHT_CYAN}list files belonging to a package + ${LIGHT_GREEN}verify ${LIGHT_BLUE}[package] + ${LIGHT_CYAN}verify that a package's files are intact + ${LIGHT_GREEN}list + ${LIGHT_CYAN}list available packages + ${LIGHT_GREEN}list-installed + ${LIGHT_CYAN}lists installed packages + ${LIGHT_GREEN}file ${LIGHT_BLUE}[path] + ${LIGHT_CYAN}shows which package a file belongs to + ${LIGHT_GREEN}info ${LIGHT_BLUE}[package] + ${LIGHT_CYAN}show info about an installed package + + ${LIGHT_GREEN}bootstrap ${LIGHT_BLUE}[additional packages...] + ${LIGHT_CYAN}installs base packages and system files to an empty system + + ${LIGHT_GREEN}help + ${LIGHT_CYAN}shows this message${RESET} + +${RED}Usage: xi [options] command... EOF } checkroot () { @@ -135,8 +139,6 @@ if [ "$#" = "0" ]; then . ${LIBDIR}/stats.sh show_xipkg_stats else - # showing stats doesn't require root, so we can only check when we are here - # todo check for permissions when we need them and ask them per request case "$1" in "sync") checkroot @@ -145,8 +147,19 @@ else "install" | "update") shift checkroot - $DO_SYNC && sync - install $@ + + [ "$#" = "0" ] && set -- $(list_installed) + + toinstall=${CACHE_DIR}/toinstall + + echo "" > $toinstall + tofetch="" + for f in $@; do + [ -f "$f" ] && echo $f >> $toinstall || tofetch="$tofetch$f " + done + + get $tofetch + install $(cat $toinstall) ;; "search") shift -- cgit v1.2.1