summaryrefslogtreecommitdiffstats
path: root/init.sh
diff options
context:
space:
mode:
Diffstat (limited to 'init.sh')
-rwxr-xr-xinit.sh71
1 files changed, 45 insertions, 26 deletions
diff --git a/init.sh b/init.sh
index 33a2d82..c5cc4a1 100755
--- a/init.sh
+++ b/init.sh
@@ -1,21 +1,12 @@
#!/bin/sh
+# vim:set noet ts=4 sts=4:
# jpokorny@redhat.com
#
-# base functions
+# internals
#
-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
-}
+CHOICES=""
check_nargs () {
[ $1 -ge $2 ]
@@ -34,12 +25,39 @@ do_del () {
[ -d "$1" ] && rm -rfI -- "$1" || echo "$1 not present"
}
+#
+# "API" for sourced choices
+#
+
+register () {
+ # usage: $1=choice to register
+ CHOICES="$CHOICES|$1"
+}
+
+announce () {
+ # usage: $1=message to output
+ # 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_git_submodule () {
- # usage: $1 = action, $2..n submodules
+ # usage: $1=action ($1 passed from main), $2..$N=submodule(s)
ret=0
+ # TODO: pushd $GIT_ROOT
for submodule in "${@:2}"; do
announce "$1 $submodule (git submodule)"
if [ "$1" == "get" ]; then
+ # TODO: avoid this workaround
+ if [ ! -f .gitmodules ]; then
+ submodule="$SUBMODULES_DIR/$submodule"
+ fi
git submodule update --init "$submodule" 2>&1
else
do_del "$submodule"
@@ -47,21 +65,21 @@ do_git_submodule () {
ret=$?
[ $ret -ne 0 ] && break
done
+ popd
check_ret $ret
}
do_wget () {
- # usage: $1 = action, $2 = target dir, $3..n = actual arguments to wget
+ # usage: $1=action ($1 passed from main), $2=DIR, $3..$N=arguments (to wget)
check_nargs $# 3 || return $?
- if [ "$(dirname $2)" == "." ]; then
- toplevel="$2"
- else
+ toplevel="$2"
+ if [ "$(dirname $2)" != "." ]; then
toplevel="$(dirname $2)"
fi
announce "$1 $toplevel (wget)"
-
if [ "$1" == "get" ]; then
- wget --no-verbose --directory-prefix "$2" "${@:3}" 2>&1
+ wget --no-verbose --no-clobber --execute robots=off \
+ --directory-prefix "$2" "${@:3}" 2>&1
else
do_del "$toplevel"
fi
@@ -69,18 +87,19 @@ do_wget () {
}
do_svn () {
- # usage: $1 = action, $2 = target dir, $3 = svn repo (+ possibly args)
- # TODO: support for revisions?
+ # usage: $1=action ($1 passed from main), $2=DIR, $3=SVN [, $4=REV]
check_nargs $# 3 || return $?
- if [ "$(dirname $2)" == "." ]; then
- toplevel="$2"
- else
+ toplevel="$2"
+ if [ "$(dirname $2)" != "." ]; then
toplevel="$(dirname $2)"
fi
announce "$1 $toplevel (svn)"
-
if [ "$1" == "get" ]; then
- svn checkout --force "${@:3}" "$2" 2>&1
+ rev=""
+ if [ $# -ge 4 ]; then
+ rev="--revision $4"
+ fi
+ svn checkout --force $rev "$3" "$2" | grep "revision"
else
do_del "$toplevel"
fi