2015-09-05 13:11:10 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-10-05 12:08:35 -04:00
|
|
|
set -eu
|
2015-09-06 10:30:05 -04:00
|
|
|
|
2018-10-05 12:08:35 -04:00
|
|
|
PULL_BASE="https://adamgoldsmith.name/cgit"
|
|
|
|
PUSH_BASE="ag:/srv/git"
|
|
|
|
|
|
|
|
function do_get() {
|
|
|
|
target="$1"
|
|
|
|
if [ -d "$target" ]
|
2015-09-05 13:11:10 -04:00
|
|
|
then
|
2018-10-05 12:08:35 -04:00
|
|
|
echo "$target already exists, not getting"
|
2015-09-05 13:11:10 -04:00
|
|
|
else
|
2018-10-05 12:08:35 -04:00
|
|
|
echo "Getting $target"
|
|
|
|
git clone "$PULL_BASE/dotfiles/$target.git" --recurse-submodules
|
|
|
|
cd $target
|
|
|
|
git remote set-url origin "$PULL_BASE/dotfiles/$target.git"
|
|
|
|
git remote set-url --push origin "$PUSH_BASE/dotfiles/$target.git"
|
2015-09-05 13:11:10 -04:00
|
|
|
cd ..
|
|
|
|
fi
|
2018-10-05 12:08:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function run_script() {
|
|
|
|
script="$1"; shift
|
|
|
|
targets="$@"
|
|
|
|
for target in $targets
|
|
|
|
do
|
|
|
|
if [ -e "$target/$script" ]
|
|
|
|
then
|
|
|
|
echo "Running $target/$script"
|
|
|
|
"$target/$script"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function maybe_stow() {
|
|
|
|
targets="$@"
|
|
|
|
if [ "$stow" = true ]
|
|
|
|
then
|
|
|
|
run_script PRESTOW "$targets"
|
|
|
|
stow -t"$HOME" --ignore="^PRESTOW$" --ignore="^POSTSTOW$" $targets
|
|
|
|
run_script POSTSTOW "$targets"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
stow=true
|
|
|
|
bootstrap=false
|
|
|
|
while [ "$#" -gt 0 ]
|
|
|
|
do
|
|
|
|
case $1 in
|
|
|
|
-ns | --no-stow)
|
|
|
|
stow=false
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-bs | --bootstrap)
|
|
|
|
bootstrap=true
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
-?*)
|
|
|
|
echo "Usage: $0 [-ns|--no-stow] [-bs|bootstrap] [<targets>]"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
esac
|
2015-09-05 13:11:10 -04:00
|
|
|
done
|
2015-09-06 10:30:05 -04:00
|
|
|
|
2018-10-05 12:08:35 -04:00
|
|
|
if [ "$bootstrap" = true ]
|
|
|
|
then
|
|
|
|
git clone "$PULL_BASE/bootstrap.git" .dotfiles
|
|
|
|
cd .dotfiles
|
|
|
|
git remote set-url origin "$PULL_BASE/bootstrap.git"
|
|
|
|
git remote set-url --push origin "PUSH_BASE/bootstrap.git"
|
2018-10-05 13:41:51 -04:00
|
|
|
else
|
|
|
|
cd "$(dirname ${BASH_SOURCE[0]})"
|
2018-10-05 12:08:35 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$#" -gt 0 ]
|
2015-09-06 10:30:05 -04:00
|
|
|
then
|
2018-10-05 12:08:35 -04:00
|
|
|
targets="$@"
|
|
|
|
for target in $targets
|
|
|
|
do
|
|
|
|
do_get "$target"
|
|
|
|
done
|
|
|
|
maybe_stow "$targets"
|
|
|
|
elif [ "$bootstrap" != true ]
|
|
|
|
then
|
|
|
|
echo "Updating .dotfiles"
|
|
|
|
git pull
|
|
|
|
|
|
|
|
for dir in */
|
|
|
|
do
|
|
|
|
echo "Updating $dir"
|
|
|
|
cd "$dir"
|
|
|
|
git pull
|
|
|
|
cd ..
|
|
|
|
done
|
|
|
|
|
|
|
|
maybe_stow "*/"
|
2015-09-06 10:30:05 -04:00
|
|
|
fi
|