From 65940c0cc719311fbac5e11c81cce34563ea3f21 Mon Sep 17 00:00:00 2001 From: davidovski Date: Sun, 20 Feb 2022 00:40:00 +0000 Subject: all works with posix shell --- src/get.sh | 97 ++++++++++++++++++++++++++++++---------------------------- src/install.sh | 34 +++++++++++--------- src/profile.sh | 6 ++-- src/sync.sh | 22 +++++++------ src/util.sh | 46 ++++++++++++++++------------ src/xi.sh | 2 -- 6 files changed, 112 insertions(+), 95 deletions(-) (limited to 'src') diff --git a/src/get.sh b/src/get.sh index 3da2591..edda26e 100755 --- a/src/get.sh +++ b/src/get.sh @@ -15,24 +15,25 @@ list_deps() { # list all dependencies and sub dependencies of a package # resolve_deps () { - local deps=() - local to_check=($@) + local deps="" if ${RESOLVE_DEPS}; then - while [ "${#to_check[@]}" != "0" ]; do - local package=${to_check[-1]} - unset to_check[-1] + while [ "$#" != "0" ]; do + + # pop a value from the args + local package=$1 + shift #only add if not already added - echo ${deps[*]} | grep -q "\b$dep\b" || deps+=($package) + echo ${deps} | grep -q "\b$package\b" || deps="$deps $package" for dep in $(list_deps $package); do # if not already checked - if echo ${deps[@]} | grep -qv "\b$dep\b"; then - to_check+=($dep) + if echo ${deps} | grep -qv "\b$dep\b"; then + set -- $@ $dep fi done done - echo ${deps[@]} + echo ${deps} else echo $@ fi @@ -61,16 +62,18 @@ package_exists () { download_packages () { local total_download=$1; shift - local packages=($@) - local outputs=() + local packages=$@ + local outputs="" local out_dir="${PACKAGE_CACHE}" mkdir -p "$out_dir" - for package in ${packages[*]}; do - local info=($(get_package_download_info $package)) - local url=${info[0]} - local checksum=${info[1]} + for package in $packages; do + local info=$(get_package_download_info $package) + set -- $info + + local url=$1 + local checksum=$2 local output="${out_dir}/${checksum}.${package}.xipkg" local output_info="${output}.info" @@ -84,16 +87,16 @@ download_packages () { curl ${CURL_OPTS} -o "$output" "$url" & fi - outputs+=($output) + outputs="$outputs $output" done - wait_for_download $total_download ${outputs[*]} + wait_for_download $total_download ${outputs} - local i=0 - for pkg_file in ${outputs[*]}; do + set -- $outputs + for pkg_file in ${outputs}; do - ${QUIET} || hbar -T "${LARGE_CIRCLE} validating downloads..." $i ${#outputs[*]} + ${QUIET} || hbar -T "${LARGE_CIRCLE} validating downloads..." $i $# info_file="${pkg_file}.info" if ! validate_sig $pkg_file $info_file; then @@ -103,86 +106,86 @@ download_packages () { i=$((i+1)) fi done - ${QUIET} || hbar -t ${HBAR_COMPLETE} -T "${CHECKMARK} validated downloads" $i ${#outputs[*]} + ${QUIET} || hbar -t ${HBAR_COMPLETE} -T "${CHECKMARK} validated downloads" $i $# - install ${outputs[*]} + install $@ } fetch () { - local requested=($@) + local requested=$@ - local missing=() - local already=() - local install=() - local update=() - local urls=() + local missing="" + local already="" + local install="" + local update="" + local urls="" local total_download=0 for package in $(resolve_deps $@); do if package_exists $package; then - info=($(get_package_download_info $package)) - url=${info[0]} - checksum=${info[1]} - size=${info[2]} - files=${info[3]} + set -- $(get_package_download_info $package) + url=$1 + checksum=$2 + size=$3 + files=$4 if is_installed $package; then if [ "$(get_installed_version $package)" != "$checksum" ]; then - update+=($package) + update="$update $package" total_download=$((total_download+size)) else - already+=($package) + already="$already $package" fi else - install+=($package) + install="$install $package" total_download=$((total_download+size)) fi else - missing+=($package) + missing="$missing $package" fi done if ! ${QUIET}; then - if [ "${#missing[@]}" != "0" ]; then + if [ "${#missing}" != "0" ]; then printf "${LIGHT_RED}The following packages could not be located:" - for package in ${missing[*]}; do + for package in ${missing}; do printf "${RED} $package" done printf "${RESET}\n" fi - if [ "${#update[@]}" != "0" ]; then + if [ "${#update}" != "0" ]; then printf "${LIGHT_GREEN}The following packages will be updated:\n\t" - for package in ${update[*]}; do + for package in ${update}; do printf "${GREEN} $package" done printf "${RESET}\n" fi - if [ "${#install[@]}" != "0" ]; then + if [ "${#install}" != "0" ]; then printf "${LIGHT_BLUE}The following packages will be installed:\n\t" - for package in ${install[*]}; do + for package in ${install}; do printf "${BLUE} $package" done printf "${RESET}\n" fi - if [ "${#already[@]}" != "0" ]; then + if [ "${#already}" != "0" ]; then printf "${LIGHT_WHITE}The following packages are already up to date:\n\t" - for package in ${already[*]}; do + for package in ${already}; do printf "${WHITE} $package" done printf "${RESET}\n" fi fi - [ "${#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" ${QUIET} || printf "${WHITE}Total download size:${LIGHT_WHITE} $(format_bytes $total_download)\n" if prompt_question "${WHITE}Continue?"; then - download_packages $total_download ${install[*]} ${update[*]} + download_packages $total_download ${install} ${update} else ${QUIET} || printf "${RED}Action canceled by user\n" fi diff --git a/src/install.sh b/src/install.sh index 3111f34..63120be 100644 --- a/src/install.sh +++ b/src/install.sh @@ -22,14 +22,14 @@ install_package () { } get_package_filecount() { - local info=($(get_package_download_info $1)) - echo ${info[3]} + set -- $(get_package_download_info $1) + echo $4 } total_filecount() { - local packages=($@) + local packages=$@ local count=0 - for package in ${packages[*]}; do + for package in $packages; do local name=$(basename -s .xipkg $package | cut -d. -f2) local c=$(get_package_filecount $name) count=$((count+c)) @@ -38,25 +38,29 @@ total_filecount() { } install () { - local packages=($@) + local packages=$@ - local missing=() - for package in ${packages[*]}; do - [ ! -f $package ] && missing+=($(basename $package)) + local missing="" + for package in $packages; do + [ ! -f $package ] && missing="$missing $(basename $package)" done - if [ "${#missing[@]}" != "0" ]; then + if [ "${#missing}" != "0" ]; then # warning: potential recursion loop here - fetch ${missing[*]} + fetch $missing else - local total=$(total_filecount ${packages[*]}) - local files_files=() - for package in ${packages[*]}; do + local total=$(total_filecount $packages) + local files_files="" + for package in $packages; do local name=$(basename -s .xipkg $package | cut -d. -f2) install_package $package $name & - files_files+=("${INSTALLED_DIR}/$name/files") + + mkdir -p "${INSTALLED_DIR}/$name/" + filelist="${INSTALLED_DIR}/$name/files" + touch $filelist + files_files="$files_files $filelist" done - wait_for_extract $total ${files_files[*]} + wait_for_extract $total ${files_files} fi } diff --git a/src/profile.sh b/src/profile.sh index feec6cf..915f1c9 100755 --- a/src/profile.sh +++ b/src/profile.sh @@ -3,15 +3,15 @@ . /usr/lib/colors.sh && export HBAR_COMPLETE="-c ${GREEN}${BG_DEFAULT}" -. /usr/lib/glyphs.sh +#. /usr/lib/glyphs.sh export CONF_FILE="/etc/xipkg.conf" export CURL_OPTS="-SsL" export DEP_DIR=$(parseconf -v dir.deps) -export REPOS=($(parseconf -v repos)) -export SOURCES=($(parseconf sources.*)) +export REPOS="$(parseconf -v repos)" +export SOURCES="$(parseconf sources.*)" export PACKAGES_DIR=$(parseconf -v dir.packages) export INSTALLED_DIR=${SYSROOT}$(parseconf -v dir.installed) diff --git a/src/sync.sh b/src/sync.sh index af8e9dd..c0dd36c 100755 --- a/src/sync.sh +++ b/src/sync.sh @@ -62,7 +62,7 @@ contest () { local popular=$(wc -l $package_dir/* | sort -n | head -1 | awk '{ print $2 }' ) - local info_file=$(sed "s/.versions//g" <<< "$package_dir") + local info_file=${package_dir%.versions} mv $popular $info_file rm -r $package_dir } @@ -71,19 +71,22 @@ popularity_contest () { local list=$(ls -1 -d $PACKAGES_DIR/*/*) local total=$(echo $list | wc -l) + local completed=0 for package_dir in $list; do contest $package_dir & + completed=$((completed+1)) + hbar -T "${LARGE_CIRCLE} contesting packages..." $completed $total done - - wait_for_jobs "${LARGE_CIRCLE} contesting packages..." "${CHECKMARK} contested packages" + hbar -t ${HBAR_COMPLETE} -T "${CHECKMARK} contested packages" $completed $completed } index_deps () { local l=$1 - local total=${#SOURCES[*]} + set -- ${SOURCES} + local total=$# local completed=0 - for src in ${SOURCES[*]}; do + for src in ${SOURCES}; do dep_graph $src completed=$((completed+1)) ${QUIET} || hbar -l $l -T "${LARGE_CIRCLE} indexing dependencies..." $completed $total @@ -93,10 +96,11 @@ index_deps () { index_repo () { local repo=$1 l=$2 - local total=${#SOURCES[*]} + set -- ${SOURCES} + local total=$# local completed=0 - for src in ${SOURCES[*]}; do + for src in ${SOURCES}; do list_source $repo $src completed=$((completed+1)) ${QUIET} || hbar -l $l -T "${LARGE_CIRCLE} syncing $repo..." $completed $total @@ -114,14 +118,14 @@ sync () { mkdir $DEP_DIR # create padding spaces for each hbar - ${QUIET} || for repo in ${REPOS[*]}; do + ${QUIET} || for repo in ${REPOS}; do hbar done # download package lists and dep graphs at the same time index_deps 0 & local i=1 - for repo in ${REPOS[*]}; do + for repo in ${REPOS}; do mkdir -p ${PACKAGES_DIR}/$repo index_repo $repo $i & i=$((i+1)) diff --git a/src/util.sh b/src/util.sh index d20db86..82d26ca 100644 --- a/src/util.sh +++ b/src/util.sh @@ -4,31 +4,39 @@ download_file() { curl ${CURL_OPTS} -o $1 -w "%{http_code}" $2 2> /dev/null } +# this function is broken wait_for_jobs () { + local text=$1 + local end=$2 + shift 2 + joblist="-e $(echo $@ | sed "s/ / -e /g")" + + echo "$joblist" + if ! $QUIET; then - local total=$(jobs -r | wc -l) + local total=$# local completed=0 while [ "$completed" != "$total" ]; do - completed=$(( $total - $(jobs -r | wc -l))) - hbar -T "$1" $completed $total + running=$(ps aux | grep $joblist | wc -l) + + completed=$(( $total - $running + 1)) + hbar -T "$text" $completed $total done - hbar -t ${HBAR_COMPLETE} -T "$2" $completed $total + hbar -t ${HBAR_COMPLETE} -T "$end" $completed $total fi wait } wait_for_download () { - if ! $QUIET && [ "$(jobs -r | wc -l)" != "0" ]; then + if ! $QUIET; then local total_download=$1 shift - local files=($@) - unset downloaded - while [ "$(jobs -r | wc -l)" != "0" ]; do - local downloaded=0 + local downloaded=0 + while [ "$downloaded" -lt "$total_download" ]; do - for output in ${files[*]}; do + for output in $@; do size=$(stat -c %s $output) downloaded=$((downloaded+size)) done @@ -42,18 +50,19 @@ wait_for_download () { } wait_for_extract () { - if ! $QUIET && [ "$(jobs -r | wc -l)" != "0" ]; then + if ! $QUIET; then local total_filecount=$1 + local extracted=0 shift - local files=($@) - unset extracted - while [ "$(jobs -r | wc -l)" != "0" ]; do + while [ "$extracted" -lt "$total_filecount" ]; do local extracted=0 - for output in ${files[*]}; do - size=$(cat $output | wc -l) - extracted=$((extracted+size)) + for output in $@; do + if [ -f $output ]; then + size=$(cat $output | wc -l) + extracted=$((extracted+size)) + fi done hbar -T " extracting files" $extracted $total_filecount @@ -64,7 +73,6 @@ wait_for_extract () { wait } - format_bytes () { echo $@ | numfmt --to iec @@ -74,5 +82,5 @@ prompt_question () { $NOCONFIRM && return 0 printf "$1 [Y/n] " read response - [ "${response:0}" != "n" ] + [ "${var%${var#?}}"x != 'nx' ] } diff --git a/src/xi.sh b/src/xi.sh index 63828f9..ea4f399 100755 --- a/src/xi.sh +++ b/src/xi.sh @@ -53,8 +53,6 @@ shift $((OPTIND-1)) if [ "$#" = "0" ]; then echo "xilinux running xipkg (palceholder text)" else - - case "$1" in "sync") sync -- cgit v1.2.1