WIP grocy - Installation, upgrad and backup
This commit is contained in:
138
seqs/grocy.sh
Executable file
138
seqs/grocy.sh
Executable file
@@ -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 <<NOTES_END
|
||||
# Behind reverse proxy as subfolder
|
||||
|
||||
* Install in the root of a nginx server (e.g. localhost:8080)
|
||||
* Proxy pass from a subdirectory (e.g. domain.me/grocy)
|
||||
* [data/config.php]
|
||||
Setting('BASE_PATH', '');
|
||||
Setting('BASE_URL', 'https://domain.me/grocy');
|
||||
|
||||
# Nginx config
|
||||
server {
|
||||
listen 8080;
|
||||
|
||||
root /var/www/grocy/public;
|
||||
|
||||
index index.php;
|
||||
|
||||
#access_log /var/log/nginx/grocy.access.log;
|
||||
error_log /var/log/nginx/grocy.error.log;
|
||||
|
||||
location ~ ^.+?\.php(/.*)?\$ {
|
||||
|
||||
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.*)\$;
|
||||
|
||||
set \$path_info \$fastcgi_path_info;
|
||||
fastcgi_param PATH_INFO \$path_info;
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files \$uri /index.php\$is_args\$query_string;
|
||||
}
|
||||
}
|
||||
|
||||
NOTES_END
|
||||
}
|
||||
|
||||
VERSION_SEQREV=15
|
||||
. /usr/local/bin/sequencer.sh
|
Reference in New Issue
Block a user