Commit 0f65b81d authored by Philipp's avatar Philipp

Updated and enhanced install and update script

parent 47e18dcb
Pipeline #288 passed with stage
in 36 seconds
......@@ -4,10 +4,14 @@
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/W:/template_rabenwetter/src/skin.conf</file>
<file>file:/W:/template_rabenwetter/src/tools/sqlite2json.php</file>
<file>file:/W:/template_rabenwetter/Gruntfile.js</file>
<file>file:/W:/template_rabenwetter/src/sqlite2json.php</file>
<file>file:/W:/template_rabenwetter/src/archive.html</file>
<file>file:/W:/template_rabenwetter/src/index.html</file>
<file>file:/W:/template_rabenwetter/src/info.html</file>
<file>file:/W:/template_rabenwetter/src/contact.html</file>
<file>file:/W:/template_rabenwetter/src/tools/install.sh</file>
<file>file:/W:/template_rabenwetter/src/tools/update.sh</file>
</group>
</open-files>
</project-private>
#!/bin/sh
#
# RabenwetterInstaller v0.1
# RabenwetterInstaller v0.1b
# (C) 2019 by Philipp Giebel <info@rabenwetter.de>
#
# This script can help new users to automatically install the Rabenwetter
# template.
# It's pretty new and only tested working on Raspbian Stretch using the .deb
# package of weewx available at http://weewx.com/
# It's pretty new and only tested working on debian based systems using the
# .deb package of weewx available at http://weewx.com/
#
# However: It should work with most linux based systems. Have a try, but do a
# complete backup of your weewx configuration first.
# However: It should work with most linux based systems. Have a try, but do
# a complete backup of your weewx configuration first.
#
# Prequisites:
# - weewx (obviously..)
......@@ -25,54 +25,90 @@
# https://gitlab.ambhost.net/stimpy/template_rabenwetter
#
if [ "$( whoami )" != "root" ]
lang="en"
weepath="/etc/weewx"
cheetahpath="/usr/share/weewx/weewx/cheetahgenerator.py"
echo "*** Rabenwetter installer v0.1b ***"
echo ""
if [ "$1" = "help" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]
then
echo "You need to run this script as root."
echo "use: ./install.sh [</your/weewx/configuration/folder/>] [<language>] \\"
echo " [</path/to/cheetahgenerator.py>] [--dry]"
echo ""
echo " eg: $0 /etc/weewx/ en"
echo ""
echo "Parameters:"
echo " [</weewx/configuration/folder/>] - The path (but not filename) where"
echo " your weewx.conf and your skins"
echo " default: /etc/weewx/ folder are located."
echo ""
echo " [<language>] - ISO-code of the language to install."
echo " default: en available languages: en, de, fr, no"
echo ""
echo " [</path/to/cheetahgenerator.py>] - Path to your existing cheetahgenerator.py"
echo " This comes with weewx and needs to be"
echo " patched. You only need to provide this"
echo " if it's not at the default location on"
echo " default: your system..."
echo " /usr/share/weewx/weewx/cheetahgenerator.py"
echo ""
echo " [--dry] - Dry-run. Don't actually install anything."
echo ""
echo "All parameters are optional but ORDER MATTERS!"
echo "As of now, if you want to set a language, you'll have to set at least"
echo "the weewx path before..."
echo ""
echo "On debian based systems (debian, raspbian, ubuntu, ...)"
echo "using the .deb file from http://weewx.com/downloads/"
echo "and english language for the website, it is sufficient to simply run"
echo "$0 without any parameters at all."
echo ""
exit 1
fi
GIT=$( which git )
if [ $? -gt 0 ]
if [ "$( whoami )" != "root" ]
then
echo "You need git and patch to run this script."
echo ""
echo "ERROR: You need to run this script as root."
echo ""
exit 2
fi
PATCH=$( which patch )
GIT=$( which git )
if [ $? -gt 0 ]
then
echo "You need git and patch to run this script."
echo ""
echo "ERROR: You need git and patch to run this script."
echo ""
exit 3
fi
if [ -z "$2" ]
PATCH=$( which patch )
if [ $? -gt 0 ]
then
echo "use: $0 <path/to/your/weewx/installation> <language> [--dry]"
echo " eg: $0 /etc/weewx en"
echo ""
echo "ERROR: You need git and patch to run this script."
echo ""
exit 4
fi
if [ ! -d "$1" ]
if [ -z "$1" ]
then
echo "use: $0 <path/to/your/weewx/installation> <language> [--dry]"
echo " eg: $0 /etc/weewx en"
echo ""
echo "Skin directory not found: $1"
echo ""
exit 5
echo " ! No weewx path provided. Assuming: $weepath"
else
weepath="$(echo $1 |sed 's/\/$//')"
fi
echo "*** Rabenwetter Installer ***"
echo " - initializing"
if [ -n "$3" ] && [ "$3" != "--dry" ]
if [ -z "$2" ]
then
CHEETAHPATH="$3"
echo " ! No language provided. Assuming: $lang"
else
CHEETAHPATH="/usr/share/weewx/weewx/cheetahgenerator.py"
lang="$2"
fi
if [ "$3" = "--dry" ] || [ "$4" = "--dry" ]
......@@ -82,28 +118,65 @@ else
DRY=0
fi
if [ -n "$3" ] && [ "$3" != "--dry" ]
then
cheetahpath="$3"
else
echo " ! No cheetah path provided. Assuming: $cheetahpath"
fi
if [ ! -d "$weepath" ]
then
echo ""
echo "ERROR: Weewx configuration path not found: $weepath"
echo ""
echo "Please provide the full physical path to your weewx configuration folder:"
echo " $0 </your/weewx/configuration/folder/> [<language>] [--dry]"
echo " eg: "
echo " $0 /etc/weewx/"
echo ""
echo "If you haven't already, please install weewx first."
echo "You can get it here: http://weewx.com/downloads/"
echo ""
exit 5
fi
echo " - initializing"
olddir=$(pwd)
rm -rf /tmp/rwi
mkdir -p /tmp/rwi
cd /tmp/rwi
echo " - downloading"
git clone https://gitlab.ambhost.net/stimpy/template_rabenwetter.git -q
if [ ! -d "template_rabenwetter/dist/i18n/$2" ]
echo " - downloading"
$GIT clone https://gitlab.ambhost.net/stimpy/template_rabenwetter.git -q
if [ $? -gt 0 ]
then
echo ""
echo "use: $0 <path/to/your/weewx/installation> <language> [--dry]"
echo " eg: $0 /etc/weewx en"
echo "ERROR: An error occured downloading the template."
echo ""
echo "Language not found: $2"
echo "Available languages: $( ls -m template_rabenwetter/dist/i18n/ )"
echo "Please visit the wiki for help:"
echo "https://gitlab.ambhost.net/stimpy/template_rabenwetter/wikis/installation"
echo ""
cd "$olddir"
rm -rf /tmp/rwi
exit 6
fi
if [ ! -d "template_rabenwetter/dist/i18n/$lang" ]
then
echo "ERROR: Language not found: $lang"
echo " Available languages: $( ls -m template_rabenwetter/dist/i18n/ )"
echo ""
echo "run \"$0 help\" for detailed help on all parameters."
echo ""
cd "$olddir"
rm -rf /tmp/rwi
exit 7
fi
echo " - preparing"
cp -r template_rabenwetter/dist/i18n/$2/* template_rabenwetter/dist/
cp -r template_rabenwetter/dist/i18n/$lang/* template_rabenwetter/dist/
rm -rf template_rabenwetter/dist/i18n
chmod -R 755 template_rabenwetter/dist
......@@ -112,66 +185,77 @@ find template_rabenwetter/dist/ -type f -exec chmod 644 "{}" \;
if [ $DRY -eq 0 ]
then
echo " - installing skin"
mkdir -p "$1/skins/Rabenwetter"
cp -r template_rabenwetter/dist/* "$1/skins/Rabenwetter/"
mkdir -p "$weepath/skins/Rabenwetter"
cp -r template_rabenwetter/dist/* "$weepath/skins/Rabenwetter/"
else
echo " - Not actually copying template_rabenwetter/dist/* to $1/skins/Rabenetter/ (--dry)"
echo " - Not actually installing skin from template_rabenwetter/dist/* "
echo " to $weepath/skins/Rabenetter/ (--dry)"
fi
if [ -e $CHEETAHPATH ]
if [ -e $cheetahpath ]
then
if [ $DRY -eq 0 ]
then
echo -n " - patching $CHEETAHPATH "
patch -r - -sNp1 "$CHEETAHPATH" template_rabenwetter/cheetahgenerator.patch >/dev/null
echo " - patching $cheetahpath"
$PATCH -r - -sNp1 "$cheetahpath" template_rabenwetter/cheetahgenerator.patch >/dev/null
if [ $? -gt 0 ]
then
echo "error!"
echo " ! cannot apply patch. Maybe, it is already applied?"
echo " ! Continuing for now..."
echo " WARNING: Cannot apply patch. Maybe it is already applied?"
echo " Continuing for now..."
echo ""
else
echo "done"
fi
else
echo " - Not actually patching cheetahgenerator.py (--dry)"
fi
else
echo " - patching $CHEETAHPATH error!"
echo " ! cannot apply patch. Please rerun the installer and provide a full path"
echo " ! to your existing cheetahgenerator.py:"
echo " ! $0 $1 $2 $CHEETAHPATH [--dry]"
echo ""
exit 7
echo "ERROR: Cannot find $cheetahpath for patching."
echo "This file comes with weewx and needs to be patched."
echo "Please find its location on your system, rerun the installer"
echo "and provide the full path to your cheetahgenerator.py as a"
echo "parameter. e.g:"
echo -n " $0 $weepath $lang $cheetahpath"
if [ $DRY -gt 0 ]
then
echo " --dry"
else
echo ""
fi
echo ""
cd "$olddir"
rm -rf /tmp/rwi
exit 8
fi
if [ $( grep -ci '^\s*skin\s*=\s*standard' "$1/weewx.conf" ) -gt 0 ]
if [ $( grep -ci '^\s*skin\s*=\s*standard' "$weepath/weewx.conf" ) -gt 0 ]
then
if [ $DRY -eq 0 ]
then
echo " - updating weewx.conf to use Rabenwetter skin."
sed -i 's/^\(\s*\)skin\s*=\s*standard.*/\1skin = Rabenwetter/i' "$1/weewx.conf"
sed -i 's/^\(\s*\)skin\s*=\s*standard.*/\1skin = Rabenwetter/i' "$weepath/weewx.conf"
else
echo " - Not actually updating weewx.conf to use Rabenwetter skin. (--dry)"
fi
else
echo " - non-standard-skin detected!"
echo " ! non-standard skin installed. please manually update your weewx.conf to"
echo " ! use the skin \"Rabenwetter\"."
echo " ! Look for the section starting with \"[[StandardReport]]\" and change"
echo " ! the parameter \"skin\" below. E.g:"
echo " ! [[StandardReport]]"
echo " ! skin = Rabenwetter"
echo " WARNING: You are using a non-standard skin with your existing"
echo " weewx installation. Please manually update your"
echo " weewx.conf to use the skin \"Rabenwetter\"."
echo ""
echo " Find the section starting with \"[[StandardReport]]\" and"
echo " change the parameter \"skin\" below."
echo " e.g:"
echo " [[StandardReport]]"
echo " skin = Rabenwetter"
echo ""
fi
echo " - done."
echo ""
cd "$olddir"
rm -rf /tmp/rwi
echo "Please update the configuration at $1/skins/Rabenwetter/skin.conf "
echo "Please edit the skin configuration at"
echo "$weepath/skins/Rabenwetter/skin.conf"
echo "to match your system, then restart weewx."
echo ""
#!/bin/sh
#
# RabenwetterUpdate v0.1
# RabenwetterUpdate v0.1b
# (C) 2019 by Philipp Giebel <info@rabenwetter.de>
#
# This script can help existing users to automatically update their Rabenwetter
......@@ -27,9 +27,47 @@
# https://gitlab.ambhost.net/stimpy/template_rabenwetter
#
lang="en"
skinpath="/etc/weewx/skins/Rabenwetter"
echo "*** Rabenwetter Update script v0.1b ***"
echo ""
if [ "$1" = "help" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]
then
echo "use: ./update.sh [</Rabenwetter/skin/folder/>] [<language>] [--dry]"
echo ""
echo " eg: ./update.sh /etc/weewx/skins/Rabenwetter en"
echo ""
echo "Parameters:"
echo " [</Rabenwetter/skin/folder/>] - The path where your existing Rabenwetter"
echo " skin is located."
echo " default: /etc/weewx/skins/Rabenwetter"
echo ""
echo " [<language>] - ISO-code of the language to install."
echo " available languages: en, de, fr, no"
echo " default: en"
echo ""
echo " [--dry] - Dry-run. Don't actually install anything."
echo ""
echo "All parameters are optional but ORDER MATTERS!"
echo "As of now, if you want to set a language, you'll have to set at least"
echo "the weewx path before..."
echo ""
echo "On debian based systems (debian, raspbian, ubuntu, ...)"
echo "using the .deb file from http://weewx.com/downloads/, the Rabenwetter"
echo "install script and english language for the website, it is sufficient"
echo "to simply run update.sh without any parameters at all."
echo ""
exit 1
fi
if [ "$( whoami )" != "root" ]
then
echo "You need to run this script as root."
echo ""
echo "ERROR: You need to run this script as root."
echo ""
exit 1
fi
......@@ -37,7 +75,9 @@ GIT=$( which git )
if [ $? -gt 0 ]
then
echo "You need git, diff and GNU stat to run this script."
echo ""
echo "ERROR: You need git, diff and GNU stat to run this script."
echo ""
exit 2
fi
......@@ -45,7 +85,9 @@ STAT=$( which stat )
if [ $? -gt 0 ]
then
echo "You need git, diff and GNU stat to run this script."
echo ""
echo "ERROR: You need git, diff and GNU stat to run this script."
echo ""
exit 3
fi
......@@ -53,30 +95,49 @@ DIFF=$( which diff )
if [ $? -gt 0 ]
then
echo "You need git, diff and GNU stat to run this script."
echo ""
echo "ERROR: You need git, diff and GNU stat to run this script."
echo ""
exit 4
fi
if [ -z "$1" ]
then
echo " ! No skin path provided. Assuming: $skinpath"
else
skinpath="$(echo $1 |sed 's/\/$//')"
fi
if [ -z "$2" ]
then
echo "use: $0 <path/to/your/rabenwetter/skin> <language> [--dry]"
echo " eg: $0 /etc/weewx/skins/Rabenwetter en"
echo ""
exit 5
echo " ! No language provided. Assuming: $lang"
else
lang="$2"
fi
if [ ! -d "$1" ]
if [ "$3" = "--dry" ]
then
DRY=1
else
DRY=0
fi
if [ ! -d "$skinpath" ]
then
echo "use: $0 <path/to/your/rabenwetter/skin> <language> [--dry]"
echo " eg: $0 /etc/weewx/skins/Rabenwetter en"
echo ""
echo "Skin directory not found: $1"
echo "ERROR: Rabenwetter skin not found: $skinpath"
echo ""
exit 6
echo "Please provide the full physical path to your existing Rabenwetter skin folder:"
echo " update.sh </your/weewx/configuration/folder/> [<language>] [--dry]"
echo " eg: "
echo " update.sh /etc/weewx/"
echo ""
echo "If this is the first time you're installing the Rabenwetter skin,"
echo "use install.sh rather than update.sh..."
echo ""
exit 5
fi
echo "*** Rabenwetter Update script ***"
echo " - initializing"
olddir=$(pwd)
rm -rf /tmp/rwu
......@@ -84,61 +145,96 @@ mkdir -p /tmp/rwu
cd /tmp/rwu
echo " - downloading"
git clone https://gitlab.ambhost.net/stimpy/template_rabenwetter.git -q
if [ ! -d "template_rabenwetter/dist/i18n/$2" ]
$GIT clone https://gitlab.ambhost.net/stimpy/template_rabenwetter.git -q
if [ $? -gt 0 ]
then
echo ""
echo "use: $0 <path/to/your/rabenwetter/skin> <language> [--dry]"
echo " eg: $0 /etc/weewx/skins/Rabenwetter en"
echo "ERROR: An error occured downloading the template."
echo ""
echo "Please visit the wiki for help:"
echo "https://gitlab.ambhost.net/stimpy/template_rabenwetter/wikis/updating"
echo ""
echo "Language not found: $2"
echo "Available languages: $( ls -m template_rabenwetter/dist/i18n/ )"
cd "$olddir"
rm -rf /tmp/rwu
exit 6
fi
if [ ! -d "template_rabenwetter/dist/i18n/$lang" ]
then
echo "ERROR: Language not found: $lang"
echo " Available languages: $( ls -m template_rabenwetter/dist/i18n/ )"
echo ""
echo "run \"$0 help\" for detailed help on all parameters."
echo ""
cd "$olddir"
rm -rf /tmp/rwu
exit 7
fi
echo " - preparing"
cp -r template_rabenwetter/dist/i18n/$2/* template_rabenwetter/dist/
cp -r template_rabenwetter/dist/i18n/$lang/* template_rabenwetter/dist/
rm -rf template_rabenwetter/dist/i18n
mv template_rabenwetter/dist/skin.conf template_rabenwetter/dist/skin.conf.dist
mv template_rabenwetter/dist/info.html.tmpl template_rabenwetter/dist/info.html.tmpl.dist
mv template_rabenwetter/dist/contact.html.tmpl template_rabenwetter/dist/contact.html.tmpl.dist
chmod -R 755 template_rabenwetter/dist
find template_rabenwetter/dist/ -type f -exec chmod 644 "{}" \;
if [ "$3" != "--dry" ]
if [ $DRY -eq 0 ]
then
echo " - updating skin"
cp -r template_rabenwetter/dist/* "$1/"
cp -r template_rabenwetter/dist/* "$skinpath/"
else
echo " - Not actually copying template_rabenwetter/dist/* to $1/ (--dry)"
echo " - Not actually updating $skinpath/"
echo " from template_rabenwetter/dist/* (--dry)"
fi
WWW=$( grep HTML_ROOT "$1/../../weewx.conf" |grep -v '^\s*#' |cut -d'=' -f2 |sed -e 's/^[[:space:]]*//' )
WWW=$( grep HTML_ROOT "$skinpath/../../weewx.conf" |grep -v '^\s*#' |cut -d'=' -f2 |sed -e 's/^[[:space:]]*//' )
if [ -d "$WWW" ]
then
WWWUSER=$( $STAT -c '%U' "$WWW/assets" )
WWWGROUP=$( $STAT -c '%G' "$WWW/assets" )
if [ "$3" != "--dry" ]
if [ $DRY -eq 0 ]
then
echo " - updating website"
cp -r template_rabenwetter/dist/assets "$www/"
chown -R $WWWUSER:$WWWGROUP "$WWW/assets"
chmod -R 775 "$WWW/assets"
find "$WWW/assets/" -type f -exec chmod 664 "{}" \;
if [ -d "$WWW/assets" ]
then
WWWUSER=$( $STAT -c '%U' "$WWW/assets" )
WWWGROUP=$( $STAT -c '%G' "$WWW/assets" )
cp -r template_rabenwetter/dist/assets "$WWW/"
chown -R $WWWUSER:$WWWGROUP "$WWW/assets"
chmod -R 775 "$WWW/assets"
find "$WWW/assets/" -type f -exec chmod 664 "{}" \;
else
echo " WARNING: Cannot find existing website. Not updating static files."
echo " Maybe, you want to manually copy the assets folder from"
echo " $skinpath/assets"
echo " to your webroot to speed up updating of these static files...."
echo ""
fi
else
echo " - Not actually copying template_rabenwetter/dist/assets to $www/ (--dry)"
echo " - Not actually copying template_rabenwetter/dist/assets"
echo " to $WWW/ (--dry)"
fi
else
echo " ! WARNING: Cannot find HTML_ROOT."
echo " Maybe, you want to manually copy the assets folder from"
echo " $skinpath/assets"
echo " to your webroot to speed up updating of these static files...."
echo ""
fi
echo " - done."
echo ""
echo "=== New and changed configuration variables: ================================"
$DIFF -wn "$1/skin.conf.dist" "$1/skin.conf" |sed -e '1,2d'
echo "============================================================================="
echo ""
cd "$olddir"
rm -rf /tmp/rwu
echo "Please check your existing config at $1/skin.conf for changes against "
echo "the updated config at $1/skin.conf.dist, then restart weewx."
echo "Please check your existing config at"
echo "$skinpath/skin.conf"
echo "for changes against the updated config at"
echo "$skinpath/skin.conf.dist,"
echo "then restart weewx."
echo ""
echo "=== New and changed configuration variables: ================================"
$DIFF -wn "$skinpath/skin.conf.dist" "$skinpath/skin.conf" |sed -e '1,2d'
echo "============================================================================="
echo ""
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment