git-build.sh/git-build.sh

48 lines
1.5 KiB
Bash
Raw Normal View History

2020-04-18 01:59:19 +00:00
#/bin/bash
2020-04-18 03:40:30 +00:00
# This script was indeed self-updated!
# Catch signals so we don't leave zombie tasks behind if we Ctrl^C
2020-04-18 03:44:01 +00:00
# No idea why but it seems to prevent the script from working? Disable!
#trap "exit" INT TERM ERR
#trap "kill 0" EXIT
2020-04-18 01:59:19 +00:00
BASEDIR="$HOME/.git-build"
# So scripts can know we're still running (for autoupdater)
touch $BASEDIR/.LOCK
2020-04-18 01:59:19 +00:00
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"
2020-04-18 01:59:19 +00:00
p_dir="$BASEDIR/.$p_name"
if [ ! -d $p_dir ]; then
source="$(cat $BASEDIR/$p_name.source)"
echo "[$p_name] CLONE $source"
2020-04-18 14:20:54 +00:00
# Don't forget the git submodules!
git clone --recursive "$source" "$p_dir"
[[ $? != 0 ]] && echo "[$p_name] CLONE FAILED" && exit 1
if [[ "$p_branch" != "master" ]]; then
2020-04-18 01:59:19 +00:00
cd $p_dir
echo "[$p_name] CHECKOUT BRANCH $p_branch"
git checkout "$p_branch"
[[ $? != 0 ]] && echo "[$p_name] CHECKOUT FAILED" && exit 1
2020-04-18 01:59:19 +00:00
fi
fi
cd "$p_dir"
2020-04-18 02:47:18 +00:00
# Refresh remote before comparing with local
2020-04-18 03:00:12 +00:00
git fetch --quiet origin
git diff --quiet remotes/origin/$p_branch
if [[ $? != 0 ]]; then
echo "[$p_name] PULL"
2020-04-18 14:20:54 +00:00
# Update all submodules, for now only when the main repo changed (TODO)
git pull --quiet --recurse-submodules
[[ $? != 0 ]] && echo "[$p_name] PULL FAILED" && exit 1
echo "[$p_name] RUN"
2020-04-18 02:14:58 +00:00
fi
2020-04-18 03:37:19 +00:00
# Run in background and redirect output to $p_name.log
(GITBUILDDIR="$BASEDIR" nohup $BASEDIR/$p_name $p_name > $BASEDIR/$p_name.log 2> $BASEDIR/$p_name.err) &
2020-04-18 01:59:19 +00:00
done
rm $BASEDIR/.LOCK