mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-24 13:36:29 +01:00
71 lines
3.0 KiB
Plaintext
71 lines
3.0 KiB
Plaintext
#!/usr/bin/env bashio
|
|
|
|
bashio::log.info "Checking status of referenced repositoriess..."
|
|
|
|
#Defining github values
|
|
bashio::log.info "... github authentification"
|
|
GITUSER=$(bashio::config 'gituser')
|
|
GITPASS=$(bashio::config 'gitpass')
|
|
GITMAIL=$(bashio::config 'gitemail')
|
|
git config --system http.sslVerify false
|
|
git config --global credential.helper 'cache --timeout 7200'
|
|
git config --global user.name ${GITUSER}
|
|
git config --global user.password ${GITPASS}
|
|
git config --global user.email ${GITMAIL}
|
|
|
|
bashio::log.info "... parse addons"
|
|
for addons in $(bashio::config "addon|keys"); do
|
|
SLUG=$(bashio::config "addon[${addons}].slug")
|
|
REPOSITORY=$(bashio::config "addon[${addons}].repository")
|
|
UPSTREAM=$(bashio::config "addon[${addons}].upstream")
|
|
CURRENT=$(bashio::config "addon[${addons}].current")
|
|
BETA=$(bashio::config "addon[${addons}].beta")
|
|
BASENAME=$(basename $REPOSITORY)
|
|
bashio::log.info "... $SLUG : check started"
|
|
|
|
git remote set-url origin https://${GITUSER}:${GITPASS}@github.com/${REPOSITORY}
|
|
|
|
#If beta flag, select beta version
|
|
if [ ${BETA} = true ]; then
|
|
bashio::log.info "... $SLUG : beta is on"
|
|
LASTVERSION=$(lastversion --pre $UPSTREAM)
|
|
else
|
|
bashio::log.info "... $SLUG : beta is off"
|
|
LASTVERSION=$(lastversion $UPSTREAM)
|
|
fi
|
|
|
|
if [ ${CURRENT} != ${LASTVERSION} ]; then
|
|
bashio::log.info "... $SLUG : update from $CURRENT to $LASTVERSION"
|
|
|
|
#Update local version
|
|
bashio::log.info "... $SLUG : cloning base repo"
|
|
cd /
|
|
git clone https://github.com/${REPOSITORY} || cd /${BASENAME} && git fetch --all && git reset --hard origin/master
|
|
|
|
#Define the folder addon
|
|
bashio::log.info "... $SLUG : checking exists in repo"
|
|
cd /${BASENAME}/${SLUG} || bashio::log.error "$SLUG addon not found in this repository. Exiting." exit
|
|
|
|
#Change all instances of version
|
|
bashio::log.info "... $SLUG : updating files"
|
|
|
|
files=$(grep -rl '"'${CURRENT}'"' /${BASENAME}/${SLUG}) && echo $files | xargs sed -i 's/"'${CURRENT}'"/"'${LASTVERSION}'"/g'
|
|
git commit -m "Bot update to $CURRENT" $files
|
|
|
|
#Git commit and push
|
|
bashio::log.info "... $SLUG : push to master"
|
|
git remote set-url origin https://${GITUSER}:${GITPASS}@github.com/${REPOSITORY}
|
|
git push
|
|
|
|
#Update the current flag
|
|
bashio::log.info "... $SLUG : updating current flag"
|
|
sed -i "s/${CURRENT}/${LASTVERSION}/g" /data/options.json
|
|
|
|
#Log
|
|
bashio::log.info "... $SLUG : updated and published"
|
|
|
|
else
|
|
bashio::log.info "Addon $SLUG is already up-to-date."
|
|
fi
|
|
done
|