summaryrefslogtreecommitdiffstats
path: root/init-functions
diff options
context:
space:
mode:
Diffstat (limited to 'init-functions')
-rw-r--r--init-functions59
1 files changed, 59 insertions, 0 deletions
diff --git a/init-functions b/init-functions
new file mode 100644
index 0000000..d3ce738
--- /dev/null
+++ b/init-functions
@@ -0,0 +1,59 @@
+# functions used by init.sh
+
+announce () {
+ # use colours if available
+ echo
+ if test -t 1; then
+ echo -en "\\033[32m"
+ echo -n "$1"
+ echo -e "\\033[0m"
+ else
+ echo "[[ $1 ]]"
+
+ fi
+}
+
+do_del () {
+ #echo "delete $1?"
+ [ -d "$1" ] && rm -rfI -- "$1" || echo "$1 not present"
+}
+
+do_wget () {
+ # usage: $1 = action, $2 = target dir, $2..n = actual arguments to wget
+ if [ $# -le 2 ]; then
+ echo "do_wget: not enough arguments"
+ exit 2
+ fi
+ if [ "$(dirname $2)" == "." ]; then
+ toplevel="$2"
+ else
+ toplevel="$(dirname $2)"
+ fi
+ announce "$1 $toplevel (wget)"
+
+ if [ "$1" == "get" ]; then
+ wget -nv -P "$2" "${@:3}" 2>&1
+ else
+ do_del "$toplevel"
+ fi
+ ret=$?
+ [ $ret -ne 0 ] && announce "action failed with exit status $?"
+ return $ret
+}
+
+do_git_submodule () {
+ # usage: $1 = action, $2..n submodules
+ ret=0
+ for submodule in "${@:2}"; do
+ announce "$1 $submodule (git submodule)"
+ if [ "$1" == "get" ]; then
+ git submodule update --init "$submodule" 2>&1
+ else
+ do_del "$submodule"
+ fi
+ ret=$?
+ [ $ret -ne 0 ] && break
+ done
+ [ $ret -ne 0 ] && announce "action failed with exit status $?"
+ return $ret
+}