diff --git a/seqs/grocy.sh b/seqs/grocy.sh new file mode 100755 index 0000000..e0a0704 --- /dev/null +++ b/seqs/grocy.sh @@ -0,0 +1,138 @@ +#!/usr/bin/env bash + +shopt -s extglob + +readonly toolName=grocy +readonly downUrl="https://releases.grocy.info/latest" +readonly versionUrl="https://api.github.com/repos/grocy/grocy/releases/latest" + +versionNew= +versionNow= + +sc_grocyDir="/var/www/grocy" +sc_grocyConf="${sc_grocyDir}/data/config.php" +sc_grocyBackup="data/backup" +sc_grocyViewcache="data/viewcache" + +grocyDownLoc="/tmp/grocy_latest.zip" + +# Get script working directory +# (when called from a different directory and even when called via symlink) +readonly sq_dir="$(cd "$(dirname -- "$(realpath ${BASH_SOURCE[0]})")" >>/dev/null 2>&1 && pwd)" +readonly sq_scriptFile=$(basename -- $0) +readonly sq_scriptName=${sq_scriptFile%%.*} +readonly sq_configFileName="${sq_scriptName}.cfg" +readonly sq_configFileTemplate="$sq_dir/${sq_configFileName}.example" +sq_aptOpt= +sq_config=0 + +step_config() { + ## or to use sequencer api with global config file: + #initSeqConfig "$sq_configFileName" "$sq_configFileTemplate" + #if [ $? -eq 0 ] ; then + # sq_config=1 + #else + # # End if no configuration file exists + # [ $DRY -eq 0 ] && return -1 + #fi + + ## Apt cmdline option to suppress user interaction + [ $QUIET -ne 0 ] && sq_aptOpt="-y" + + ## Return of non zero value will abort the sequence + return 0 +} + +getVersions() { + versionNew=${versionNew:-$(curl --silent "$versionUrl" | grep -Po '"tag_name": "v\K.*?(?=")')} + versionNow=${versionNow:-$(grep -Po '"Version": "\K.*?(?=")' < "${sc_grocyDir}/version.json")} +} + +step_20_info() { echo "Backup ${toolName}"; } +step_20_alias() { ALIAS="backup"; } +step_20() { + local lBu="${sc_grocyDir}/${sc_grocyBackup}/${toolName}_$(date +%Y%m%d-%H%M%S).tgz" + exe cd ${sc_grocyDir}/.. + exe tar \ + --exclude="${sc_grocyBackup}/*" \ + --exclude="${sc_grocyViewcache}/*" \ + -czf "${lBu}" \ + "$(basename "${sc_grocyDir}")" +} + +step_22_info() { echo "Install/upgrade ${toolName}"; } +step_22_alias() { ALIAS="install"; } +step_22() { + getVersions + if [[ ${versionNow} == ${versionNew} ]] ; then + endReturn -o 1 "Latest version ${versionNow} already installed" + else + if [ -n "${versionNow}" ] ; then + echoseq " [I] Upgrading $toolName from ${versionNow} to ${versionNew}" + else + echoseq " [I] Installing $toolName version ${versionNew}" + fi + fi + exe wget ${downUrl} -q -O "${grocyDownLoc}" + endReturn -o $? "Download failed" + if [ -e "${sc_grocyDir}" ] ; then + step backup + exe rm -rf "${sc_grocyDir}/${sc_grocyViewcache}" + fi + exe rm -rf "${sc_grocyDir}/"!(data) + exe unzip -o -qq "${grocyDownLoc}" -d "${sc_grocyDir}" + exe chown -R www-data: "${sc_grocyDir}/public" "${sc_grocyDir}/data" + # Populate first config + if [ ! -e "${sc_grocyConf}" ] ; then + exe cp "${sc_grocyDir}/config-dist.php" "${sc_grocyConf}" + echoseq " [I] Please adjust the config: ${sc_grocyConf}" + else + echoseq " [I] Please check ${sc_grocyDir}/config-dist.php" + echoseq " for new configuration options" + fi +} + +step_30_alias() { ALIAS="notes"; } +step_30() { + outColor green + cat <