diff options
-rwxr-xr-x | src/get.sh | 67 | ||||
-rw-r--r-- | src/install.sh | 2 | ||||
-rwxr-xr-x | src/profile.sh | 3 | ||||
-rw-r--r-- | src/query.sh | 14 | ||||
-rw-r--r-- | src/remove.sh | 42 | ||||
-rwxr-xr-x | src/xi.sh | 86 |
6 files changed, 185 insertions, 29 deletions
@@ -19,6 +19,7 @@ resolve_deps () { local deps="" local i=0 if ${RESOLVE_DEPS}; then + hbar while [ "$#" != "0" ]; do # pop a value from the args @@ -67,6 +68,30 @@ package_exists () { [ "$(find ${PACKAGES_DIR} -mindepth 2 -name "$1" | wc -l)" != "0" ] } +download_package () { + local package=$1 + local output=$2 + + local info=$(get_package_download_info $package) + set -- $info + + local url=$1 + local checksum=$2 + + local output_info="${output}.info" + + if validate_checksum $output $checksum; then + ${VERBOSE} && printf "${LIGHT_BLACK}skipping download for %s already exists with checksum %s${RESET}\n" $package $checksum + else + ${VERBOSE} && printf "${LIGHT_BLACK}downloading $package from $url\n" $package $checksum + touch $output + + (curl ${CURL_OPTS} -o "$output_info" "$url.info" || printf "${RED}Failed to download info for %s\n" $package) & + (curl ${CURL_OPTS} -o "$output" "$url" || printf "${RED}Failed to download %s\n" $package) & + fi + +} + download_packages () { local total_download=$1; shift local packages=$@ @@ -76,25 +101,8 @@ download_packages () { mkdir -p "$out_dir" 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" - - if validate_checksum $output $checksum; then - ${VERBOSE} && printf "${LIGHT_BLACK}skipping download for %s already exists with checksum %s${RESET}\n" $package $checksum - else - ${VERBOSE} && printf "${LIGHT_BLACK}downloading $package from $url\n" $package $checksum - touch $output - - (curl ${CURL_OPTS} -o "$output_info" "$url.info" || printf "${RED}Failed to download info for %s\n" $package) & - (curl ${CURL_OPTS} -o "$output" "$url" || printf "${RED}Failed to download %s\n" $package) & - fi - + download_package $package $output outputs="$outputs $output" done @@ -122,7 +130,7 @@ download_packages () { } -fetch () { +get () { local requested=$@ local missing="" @@ -161,6 +169,7 @@ fetch () { fi done + # TODO tidy this if ! ${QUIET}; then if [ "${#missing}" != "0" ]; then printf "${LIGHT_RED}The following packages could not be located:" @@ -183,7 +192,7 @@ fetch () { done printf "${RESET}\n" fi - if [ "${#already}" != "0" ]; then + if [ "${#install}" = "0" ] && [ "${#update}" = 0 ] && [ "${#already}" != "0" ]; then printf "${LIGHT_WHITE}The following packages are already up to date:\n\t" for package in ${already}; do printf "${WHITE} $package" @@ -205,4 +214,22 @@ fetch () { fi } +fetch () { + local packages=$@ + local outputs="" + + local total_download=0 + for package in $packages; do + if package_exists $package; then + set -- $(get_package_download_info $package) + size=$3 + total_download=$((total_download+size)) + + local output="${package}.xipkg" + download_package $package $output + outputs="$outputs $output" + fi + done + wait_for_download $total_download ${outputs} +} diff --git a/src/install.sh b/src/install.sh index da8b7a2..48e037c 100644 --- a/src/install.sh +++ b/src/install.sh @@ -78,7 +78,7 @@ install () { if [ "${#missing}" != "0" ]; then # warning: potential recursion loop here - fetch $missing + get $missing else local total=$(total_filecount $packages) diff --git a/src/profile.sh b/src/profile.sh index f05271b..43e4900 100755 --- a/src/profile.sh +++ b/src/profile.sh @@ -1,7 +1,8 @@ #!/bin/sh . /usr/lib/colors.sh && - export HBAR_COMPLETE="-c ${GREEN}${BG_DEFAULT}" + export HBAR_COMPLETE="-c ${GREEN}${BG_DEFAULT}" && + export HBAR_RED="-c ${BLACK}${BG_RED}" #. /usr/lib/glyphs.sh diff --git a/src/query.sh b/src/query.sh index d5571b0..7292434 100644 --- a/src/query.sh +++ b/src/query.sh @@ -1,7 +1,16 @@ #!/bin/sh + +list () { + find ${PACKAGES_DIR} -type f | sed "s,${PACKAGES_DIR}/,," +} + +list_installed () { + ls -1 ${INSTALLED_DIR} +} + search () { - find ${PACKAGES_DIR} -type f | sed "s,${PACKAGES_DIR}/,," | grep $(echo $@ | sed "s/ /\\|/g") + list | grep $(echo $@ | sed "s/ /\\|/g") } files () { @@ -11,7 +20,7 @@ files () { done } -file () { +file_info () { for file in $@; do [ ! -f ${SYSROOT}$file ] && file=$(realpath $file) for list in ${INSTALLED_DIR}/*/files; do @@ -21,3 +30,4 @@ file () { done done } + diff --git a/src/remove.sh b/src/remove.sh index 727bcec..3e722fb 100644 --- a/src/remove.sh +++ b/src/remove.sh @@ -1,8 +1,44 @@ #!/bin/sh remove () { + local packages=$@ + + local to_remove="${CACHE_DIR}/toremove" + [ -f $to_remove ] && rm $to_remove + local real="" + + for package in $@; do + local package_dir="${INSTALLED_DIR}/$package" + local filesfile="${package_dir}/files" + if [ -d $package_dir ]; then + [ -f $filesfile ] && + cat $filesfile >> $to_remove + echo $package_dir >> $to_remove + real="$real $package" + else + >&2 printf "${RED}Package ${LIGHT_RED}$package${RED} is not installed" + fi + done + + local total=$(cat $to_remove | wc -l) + + ${QUIET} || printf "${LIGHT_RED}The following packages will be removed from the system:\n\t${RED}%s\n" $real + ${QUIET} || printf "${LIGHT_RED}Files to remove: ${RED}%s\n" $total + + if prompt_question "Continue?"; then + + local removed=0 + ${QUIET} || hbar + for file in $(cat $to_remove); do + rm -rf $file + + removed=$((removed+1)) + ${QUIET} || hbar ${HBAR_RED} -T "removing files" $removed $total + done + ${QUIET} || hbar -t ${HBAR_COMPLETE} -T "removing files" $removed $total + else + ${QUIET} || printf "${LIGHT_BLACK}Action cancled by user\n" + fi - # TODO ask to remove package - # TODO calculate broken dependencies - # TODO } + @@ -1,5 +1,63 @@ #!/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 + fetch [package] + download a .xipkg file + keyimport [name] [url] + import a key from a url + + search [query] + search the database for a package + files [package] + list files belonging to a package + list + list available packagesa + 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 +EOF +} + [ -z "${LIBDIR}" ] && LIBDIR=/usr/lib/xipkg export SYSROOT=/ @@ -11,7 +69,7 @@ export DO_SYNC=true export UNSAFE=false export NOCONFIRM=false -while getopts ":r:c:qnluyv" opt; do +while getopts ":r:c:qnluyvh" opt; do case "${opt}" in r) SYSROOT=$(realpath ${OPTARG}) @@ -37,6 +95,10 @@ while getopts ":r:c:qnluyv" opt; do q) QUIET=true ;; + h) + usage + exit 0 + ;; esac done @@ -48,6 +110,7 @@ done . ${LIBDIR}/sync.sh . ${LIBDIR}/install.sh . ${LIBDIR}/bootstrap.sh +. ${LIBDIR}/remove.sh . ${LIBDIR}/get.sh shift $((OPTIND-1)) @@ -61,12 +124,22 @@ else ;; "install" | "update") shift + $DO_SYNC && sync install $@ ;; "search") shift search $@ ;; + "fetch") + shift + $DO_SYNC && sync + fetch $@ + ;; + "remove") + shift + remove $@ + ;; "files") shift files $@ @@ -76,14 +149,23 @@ else set -o noglob keyimport $@ ;; + "list") + list + ;; + "list-installed") + list_installed + ;; "file") shift - file $@ + file_info $@ ;; "bootstrap") shift bootstrap $@ ;; + "help") + usage + ;; *) $DO_SYNC && sync fetch $@ |