lixonet-ee/run.sh

66 lines
1.6 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
2021-05-18 17:38:32 -06:00
delay=900
version_file=/etc/lixonet/version
log=/app/log/lixonet.log
mkdir /app/log
2022-12-17 00:46:23 -07:00
echo "Lixonet EE started."
2021-05-18 17:38:32 -06:00
while true
do
2021-09-21 15:10:44 -06:00
set +e
current_version=`cat $version_file || echo 0`
gpg --import <trusted_signers >> $log 2>&1
2022-12-17 01:13:19 -07:00
for id in `gpg --list-packets <trusted_signers | awk '$1=="keyid:"{print$2}'`; do
(echo 5; echo y; echo save) | gpg --command-fd 0 --no-tty --no-greeting -q --edit-key $id trust >> $log 2>&1
if [ $? -ne 0 ]; then
echo "Import GPG key with id $id from trusted_signers failed. For more details, see $log"
sleep $delay
continue
fi
done
2021-09-21 15:10:44 -06:00
2022-12-17 22:02:47 -07:00
git fetch --all >> /dev/null
2021-09-21 15:10:44 -06:00
if [ $? -ne 0 ]; then
2022-12-17 19:33:11 -07:00
echo "Git fetch from $GIT_URL failed."
2021-09-21 15:10:44 -06:00
sleep $delay
continue
fi
2022-12-17 19:33:11 -07:00
current_commit=`git rev-parse HEAD`
2022-12-17 01:21:28 -07:00
latest_commit=`git log "--format=%G? %H" origin/master | grep ^G | head -n 1 | cut -d' ' -f2`
2021-09-21 15:10:44 -06:00
if test -z $latest_commit; then
2022-12-17 19:33:11 -07:00
echo "Latest commit couldn't be found."
2021-09-21 15:10:44 -06:00
sleep $delay
continue
fi
2022-12-17 19:40:12 -07:00
if [ $current_commit != $latest_commit ]; then
echo "Checking out $latest_commit..."
git reset --hard >> /dev/null
git checkout $latest_commit -f
if [ $? -ne 0 ]; then
echo "Git checkout failed."
sleep $delay
continue
fi
2021-09-21 15:10:44 -06:00
fi
checkout_version=`cat version`
if [ "$checkout_version" -gt "$current_version" ]; then
echo "Updating to version $checkout_version..."
2022-12-17 01:24:52 -07:00
chmod +x build.sh && ./build.sh
2021-09-21 15:10:44 -06:00
if [ $? -eq 0 ]; then
echo "Update completed successfully."
echo $checkout_version > $version_file
else
2022-12-17 01:24:52 -07:00
echo "Update failed; version was not updated. Trying again in $delay seconds."
2021-09-21 15:37:57 -06:00
sleep $delay
continue
2021-09-21 15:10:44 -06:00
fi
fi
2021-05-18 17:38:32 -06:00
sleep $delay
2021-09-21 12:52:40 -06:00
done