Last active
January 21, 2023 18:31
-
-
Save mattrude/1492d86d2a97355a274b22d15e055619 to your computer and use it in GitHub Desktop.
A simple build scrip for LibreELEC.tv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
buildDIR='/mnt/public/LibreELEC.tv' | |
httpDIR='/var/www/html' | |
builds="master libreelec-11.0" | |
GITURL="https://github.com/LibreELEC/LibreELEC.tv.git" | |
###################################################################################### | |
scriptName=$(basename -- "$0") | |
for pid in $(pidof -x ${scriptName}); do | |
if [ $pid != $$ ]; then | |
echo "[$(date)] : $scriptName : Process is already running with PID $pid" | |
exit 1 | |
fi | |
done | |
###################################################################################### | |
if [ "${LOGNAME}" != "matt" ]; then | |
echo "[$(date)] : $scriptName : Process must be ran by the 'matt' user." | |
exit 1 | |
fi | |
###################################################################################### | |
cd ${buildDIR}/ | |
for BUILD in ${builds} | |
do | |
if [ -d ${buildDIR}/${BUILD}/.git ]; then | |
OLDGITID=`git --git-dir=${buildDIR}/${BUILD}/.git show-ref |grep "refs/remotes/origin/${BUILD}" |awk '{print $1}' |cut -c -7` | |
else | |
OLDGITID='new-install' | |
fi | |
NEWGITID=`git ls-remote --heads ${GITURL} |grep "refs/heads/${BUILD}" |awk '{ print $1 }' |cut -c -7` | |
if [ -z ${NEWGITID} ]; then | |
break | |
fi | |
#NEWGITID='' | |
echo "" | |
echo "Building LibreELEC" | |
echo "--------------------------------------------------------------------------" | |
echo "" | |
echo "Branch: ${BUILD}" | |
echo "Remote Ref ID: ${NEWGITID}" | |
echo "Local Ref ID: ${OLDGITID}" | |
if [ "${OLDGITID}" != "${NEWGITID}" ]; then | |
if [ -d ${buildDIR}/${BUILD}/ ]; then | |
cd ${buildDIR}/${BUILD}/ | |
git pull | |
else | |
git clone ${GITURL} ${buildDIR}/${BUILD}/ | |
fi | |
cd ${buildDIR}/${BUILD}/ | |
pwd | |
PROJECT=RPi ARCH=arm DEVICE=RPi4 make image | |
echo "" | |
if [ "${BUILD}" = "master" ]; then | |
echo "--------------------------------------------------------------------------" | |
echo "" | |
ssh [email protected] rm -f /storage/.update/*.img.gz | |
rsync -a ${buildDIR}/${BUILD}/target/*img.gz [email protected]:/storage/.update/ | |
echo "" | |
fi | |
buildID=`git log --pretty="%h" |head -1 |cut -c -7` | |
if [ -f ${buildDIR}/${BUILD}/target/*img.gz ]; then | |
rm -f ${buildDIR}/${BUILD}/target/*kernel ${buildDIR}/${BUILD}/target/*system \ | |
${buildDIR}/${BUILD}/target/*tar ${buildDIR}/${BUILD}/target/*tar.sha256 | |
sudo mkdir -p ${httpDIR}/${BUILD}/ | |
cd ${httpDIR}/${BUILD}/; ls -tp . | grep -v '/$' | tail -n +7 | xargs -I {} rm -- {} | |
sudo rsync -a ${buildDIR}/${BUILD}/target/*img.gz ${httpDIR}/${BUILD}/ | |
rm ${buildDIR}/${BUILD}/target/* | |
fi | |
else | |
echo "" | |
echo "No Update for branch ${BUILD} found, skipping..." | |
echo "" | |
fi | |
done | |
echo "--------------------------------------------------------------------------" | |
echo "Done!" | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment