summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/get.sh121
-rwxr-xr-xsrc/profile.sh14
-rwxr-xr-xsrc/sync.sh (renamed from src/xisync.sh)24
-rwxr-xr-xsrc/xi.sh44
-rw-r--r--src/xiget.sh12
5 files changed, 182 insertions, 33 deletions
diff --git a/src/get.sh b/src/get.sh
new file mode 100755
index 0000000..3e0be79
--- /dev/null
+++ b/src/get.sh
@@ -0,0 +1,121 @@
+#!/bin/sh
+
+
+# list all direct dependencies of a package
+#
+list_deps() {
+ local name=$1
+ local tree_file="${DEP_DIR}/$name"
+ [ -f $tree_file ] &&
+ for dep in $(cat "$tree_file"); do
+ echo $dep
+ done | sort -u
+}
+
+# list all dependencies and sub dependencies of a package
+#
+resolve_deps () {
+ local deps=()
+ local to_check=($@)
+ if ${RESOLVE_DEPS}; then
+ while [ "${#to_check[@]}" != "0" ]; do
+ local package=${to_check[-1]}
+ unset to_check[-1]
+
+ 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)
+ fi
+ done
+ done
+ echo ${deps[@]}
+ else
+ echo $@
+ fi
+
+}
+
+get_package_download_info() {
+ tail -1 ${PACKAGES_DIR}/*/$1
+}
+
+get_available_version () {
+ echo "${info[1]}"
+}
+
+is_installed() {
+ [ -f "${INSTALLED_DIR}/$1/checksum" ]
+}
+
+get_installed_version () {
+ local name=$1
+ local file="${INSTALLED_DIR}/$name/checksum"
+ [ -f $file ] &&
+ cat $file
+}
+
+# bad implementation
+exists () {
+ [ "$(find ${PACKAGES_DIR} -mindepth 2 -name "$1" | wc -l)" != "0" ]
+}
+
+download () {
+ local requested=($@)
+
+ local missing=()
+ local install=()
+ local update=()
+ local urls=()
+
+ local total_download=0
+
+ for package in $(resolve_deps $@); do
+ if exists $package; then
+ info=($(get_package_download_info $package))
+ url=${info[0]}
+ checksum=${info[1]}
+ size=${info[2]}
+ files=${info[3]}
+
+ if is_installed $package; then
+ if [ "$(get_installed_version $package)" != "$(get_available_version $package)" ]; then
+ update+=($package)
+ total_download=$((total_download+size))
+ fi
+ else
+ install+=($package)
+ total_download=$((total_download+size))
+ fi
+ else
+ missing+=($package)
+ fi
+ done
+
+ if [ "${#missing[@]}" != "0" ]; then
+ printf "${LIGHT_RED}The following packages could not be located:"
+ for package in ${missing[*]}; do
+ printf "${RED} $package"
+ done
+ printf "${RESET}\n"
+ fi
+ if [ "${#update[@]}" != "0" ]; then
+ printf "${LIGHT_GREEN}The following packages will be updated:\n\t"
+ for package in ${update[*]}; do
+ printf "${GREEN} $package"
+ done
+ printf "${RESET}\n"
+ fi
+ if [ "${#install[@]}" != "0" ]; then
+ printf "${LIGHT_BLUE}The following packages will be updated:\n\t"
+ for package in ${install[*]}; do
+ printf "${BLUE} $package"
+ done
+ printf "${RESET}\n"
+ fi
+
+ echo "total download size: ${total_download} bytes"
+}
+
+
diff --git a/src/profile.sh b/src/profile.sh
new file mode 100755
index 0000000..12bd41c
--- /dev/null
+++ b/src/profile.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+. /usr/lib/colors.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 PACKAGES_DIR=$(parseconf -v dir.packages)
+export INSTALLED_DIR=$(parseconf -v dir.installed)
+
+export TMP_DIR="/tmp/xi"
diff --git a/src/xisync.sh b/src/sync.sh
index 5349dd2..9589c43 100755
--- a/src/xisync.sh
+++ b/src/sync.sh
@@ -1,21 +1,5 @@
#!/bin/bash
-export CONF_FILE="/etc/xipkg.conf"
-
-CURL_OPTS="-SsL"
-
-REPOS=($(parseconf -v repos))
-SOURCES=($(parseconf sources.*))
-PACKAGES_DIR=$(parseconf -v dir.packages)
-DEP_GRAPH=$(parseconf -v dir.deps)
-
-TMP_DIR="/tmp/xi"
-
-get_deps() {
- local name=$1
- [ -f $DEP_GRAPH ] && sed -rn "s/^$name: (.*)/\1/p" $DEP_GRAPH || echo
-}
-
download_file() {
curl ${CURL_OPTS} -o $1 -w "%{http_code}" $2 2> /dev/null
}
@@ -81,7 +65,7 @@ dep_graph () {
while IFS= read -r line; do
local package=$(echo $line | cut -d: -f1)
local new=$(echo $line | cut -d: -f2-)
- echo $new >> $DEP_GRAPH/$package
+ echo $new >> $DEP_DIR/$package
done < "$tmp_file"
fi
}
@@ -139,8 +123,8 @@ sync () {
# prepare the file structure for the sync
mkdir -pv $TMP_DIR
rm -r $PACKAGES_DIR/*
- rm -r $DEP_GRAPH
- mkdir $DEP_GRAPH
+ rm -r $DEP_DIR
+ mkdir $DEP_DIR
# create padding spaces for each hbar
for repo in ${REPOS[*]}; do
@@ -162,5 +146,3 @@ sync () {
hbar
popularity_contest
}
-
-sync
diff --git a/src/xi.sh b/src/xi.sh
new file mode 100755
index 0000000..aaad140
--- /dev/null
+++ b/src/xi.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+[ -z "${LIBDIR}" ] && LIBDIR=/usr/lib/xipkg
+. ${LIBDIR}/profile.sh
+. ${LIBDIR}/sync.sh
+. ${LIBDIR}/get.sh
+
+export SYSROOT=/
+export CONF_FILE="/etc/xipkg.conf"
+export VERBOSE=false
+export RESOLVE_DEPS=true
+export DO_SYNC=true
+export UNSAFE=false
+export NOCONFIRM=false
+
+while getopts ":r:c:nluyv" opt; do
+ case "${opt}" in
+ r)
+ SYSROOT="${OPTARG}"
+ ;;
+ c)
+ CONF_FILE="${OPTARG}"
+ ;;
+ n)
+ RESOLVE_DEPS=false
+ ;;
+ l)
+ DO_SYNC=false
+ ;;
+ u)
+ UNSAFE=true
+ ;;
+ y)
+ NOCONFIRM=true
+ ;;
+ v)
+ VERBOSE=true
+ ;;
+ esac
+done
+
+shift $((OPTIND-1))
+
+download $@
diff --git a/src/xiget.sh b/src/xiget.sh
deleted file mode 100644
index 815c47f..0000000
--- a/src/xiget.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-
-export CONF_FILE="/etc/xipkg.conf"
-
-CURL_OPTS="-SsL"
-
-DEP_GRAPH=$(parseconf -v dir.deps)
-
-get_deps() {
- local name=$1
- [ -f $DEP_GRAPH ] && sed -rn "s/^$name: (.*)/\1/p" $DEP_GRAPH || echo
-}