summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/get.sh20
-rw-r--r--src/query.sh50
-rw-r--r--src/util.sh20
-rwxr-xr-xsrc/xi.sh42
4 files changed, 90 insertions, 42 deletions
diff --git a/src/get.sh b/src/get.sh
index 24e397c..197b232 100755
--- a/src/get.sh
+++ b/src/get.sh
@@ -63,25 +63,6 @@ get_package_download_info() {
sed 1q ${PACKAGES_DIR}/$1
}
-# return if a package is present on the system or not
-#
-is_installed() {
- [ -f "${INSTALLED_DIR}/$1/checksum" ]
-}
-
-# get the installed checksum of a package ($1)
-#
-get_installed_version () {
- local name=$1
- local file="${INSTALLED_DIR}/$name/checksum"
- [ -f $file ] &&
- cat $file
-}
-
-package_exists () {
- [ -f "${PACKAGES_DIR}/$1" ]
-}
-
download_package () {
local package=$1
local output=$2
@@ -119,6 +100,7 @@ download_packages () {
mkdir -p "$out_dir"
for package in $@; do
+ # TODO if pacakge is local, just symlink instead
set -- $(get_package_download_info $package)
checksum=$2
size=$3
diff --git a/src/query.sh b/src/query.sh
index f47ea60..3498c61 100644
--- a/src/query.sh
+++ b/src/query.sh
@@ -1,14 +1,20 @@
#!/bin/sh
+# list all available packages
+#
list () {
find ${PACKAGES_DIR} -type f | sed "s,${PACKAGES_DIR}/,,"
}
+# list installed packages
+#
installed () {
ls -1 ${INSTALLED_DIR}
}
+# list all packages and lable installed ones
+#
list_installed () {
list | while read -r line; do
[ -d ${INSTALLED_DIR}/$line ] \
@@ -17,6 +23,8 @@ list_installed () {
done
}
+# search for a package based on a query
+#
search () {
if [ $# = 0 ]; then
list_installed
@@ -25,6 +33,8 @@ search () {
fi
}
+# list the files that belong to a package
+#
files () {
for package in $@; do
local file="${INSTALLED_DIR}/$package/files"
@@ -32,6 +42,8 @@ files () {
done
}
+# figure out which package a file belongs to
+#
file_info () {
for file in $@; do
[ ! -f ${SYSROOT}$file ] && file=$(realpath $file 2>/dev/null)
@@ -54,3 +66,41 @@ file_info () {
done
}
+# extract a variable from a package info
+#
+# extract_info [file] [FIELD]
+#
+extract_info () {
+ grep -i "^$2=" $1 | cut -d'=' -f2-
+}
+
+# pretty print a xipkg info file
+#
+print_info () {
+ file=$1
+ line="${LIGHT_CYAN}%-15s ${LIGHT_BLUE}%s\n"
+ for field in Name Description Version Origin; do
+ printf "$line" "$field" "$(extract_info $file $field)"
+ done
+
+ printf "$line" "Dependencies" "$(extract_info $file "DEPS")"
+ printf "$line" "Build Date" "$(extract_info $file "DATE")"
+
+ is_installed $(extract_info $file "NAME") && {
+ date=$(date -d @$(stat -t $file | cut -d' ' -f13))
+ printf "$line" "Install Date" "$date"
+ } || true
+}
+
+# print information about one or more packages
+#
+info () {
+ for package in $@; do
+ infofile=${INSTALLED_DIR}/$package/info
+ [ -f $infofile ] && {
+ print_info $infofile
+ } || {
+ printf "Package info for $package could not be found!"
+ }
+ done
+}
diff --git a/src/util.sh b/src/util.sh
index 96d326d..2b7044c 100644
--- a/src/util.sh
+++ b/src/util.sh
@@ -83,3 +83,23 @@ prompt_question () {
[ "${var%${var#?}}"x != 'nx' ]
}
+# return if a package is present on the system or not
+#
+is_installed() {
+ [ -f "${INSTALLED_DIR}/$1/checksum" ]
+}
+
+# get the installed checksum of a package ($1)
+#
+get_installed_version () {
+ local name=$1
+ local file="${INSTALLED_DIR}/$name/checksum"
+ [ -f $file ] &&
+ cat $file
+}
+
+#
+#
+package_exists () {
+ [ -f "${PACKAGES_DIR}/$1" ]
+}
diff --git a/src/xi.sh b/src/xi.sh
index 92222f9..923612c 100755
--- a/src/xi.sh
+++ b/src/xi.sh
@@ -133,6 +133,21 @@ done
. ${LIBDIR}/get.sh
. ${LIBDIR}/remove.sh
+do_install () {
+ [ "$#" = "0" ] && set -- $(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)
+}
+
shift $((OPTIND-1))
if [ "$#" = "0" ]; then
@@ -147,19 +162,7 @@ else
"install" | "update")
shift
checkroot
-
- [ "$#" = "0" ] && set -- $(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)
+ do_install $@
;;
"build")
shift
@@ -187,8 +190,8 @@ else
"reinstall")
shift
checkroot
- $0 remove $@
- $0 install $@
+ remove $@
+ do_install $@
;;
"files")
shift
@@ -221,14 +224,7 @@ else
;;
"info")
shift
- for package in $@; do
- infofile=${INSTALLED_DIR}/$package/info
- [ -f $infofile ] && {
- cat $infofile
- } || {
- printf "Package info for $package could not be found!"
- }
- done
+ info $@
;;
"verify")
shift