build.sh/git-build.sh

42 lines
1.2 KiB
Bash
Executable File

#/bin/bash
# This script can now self-update! \o/
# This message appeared on the other side because self-update took place.
BASEDIR="$HOME/.git-build"
# So scripts can know we're still running (for autoupdater)
touch $BASEDIR/.LOCK
for project in $BASEDIR/*.source; do
p_name="$(basename $project .source)"
echo "[$p_name] START"
[ -f $BASEDIR/$p_name.branch ] && p_branch="$(cat $BASEDIR/$p_name.branch)" || p_branch="master"
echo "$branch"
p_dir="$BASEDIR/.$p_name"
if [ ! -d $p_dir ]; then
source="$(cat $BASEDIR/$p_name.source)"
echo "[$p_name] CLONE $source"
git clone "$source" "$p_dir"
[[ $? != 0 ]] && echo "[$p_name] CLONE FAILED" && exit 1
if [[ "$p_branch" != "master" ]]; then
cd $p_dir
echo "[$p_name] CHECKOUT BRANCH $p_branch"
git checkout "$p_branch"
[[ $? != 0 ]] && echo "[$p_name] CHECKOUT FAILED" && exit 1
fi
fi
cd "$p_dir"
# Refresh remote before comparing with local
git fetch --quiet origin
git diff --quiet remotes/origin/$p_branch
if [[ $? != 0 ]]; then
echo "[$p_name] PULL"
git pull --quiet
[[ $? != 0 ]] && echo "[$p_name] PULL FAILED" && exit 1
echo "[$p_name] RUN"
fi
(GITBUILDDIR="$BASEDIR" $BASEDIR/$p_name $p_name) &
done
rm $BASEDIR/.LOCK