Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed reboot at installation #78

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 25 additions & 119 deletions victron-venus-os-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ UMGEBUNGSVARIABLEN

DESTDIR - Pfad der den zu installierenden Dateien vorangestellt wird. So könnte beispielsweise in ein chroot Verzeichnis oder ein gemountetes Venus OS image installiert werden.

NO_REBOOT - Wenn gesetzt, so wird noch der Installation nicht neu gestartet.

LOG_FILE - Datei, über die alle Ereignisse mitprotokolliert werden. Kann gegebenenfallse auf /dev/null gesetzt werden.

LIZENZ
Expand Down Expand Up @@ -80,8 +78,6 @@ ENVIRONMENT

DESTDIR - Path that is preprended to the regular path of the installation, e.g. to facilitate the installation into a chroot environment, the DESTDIR variable would specify the file path to that changed root.

NO_REBOOT - If set, not reboot is initiated at the end of the install script.

LOG_FILE - File to which all events are logged, may be set to /dev/null.

LICENSE
Expand Down Expand Up @@ -126,132 +122,42 @@ if [ -n "$missing" ]; then
echo
fi



# DESTDIR is optionally set as an environment variable.
if [ -n "$DESTDIR" ] && [ "/" != "$DESTDIR" ] ; then
if which realpath > /dev/null; then
RESOLVED_DESTDIR=$(realpath "$DESTDIR")
if [ "$RESOLVED_DESTDIR" != "$DESTDIR" ]; then
echo "W: The provided installation path ($DESTDIR) is a symbolic link that points to $RESOLVED_DESTDIR."
echo " The script will use the resolved path for installation."
fi
DESTDIR="$RESOLVED_DESTDIR"
else
if ! echo "$DESTDIR" | grep -q "^/"; then
echo "E: The DESTDIR passed from environment variable must be absolute or realpath must be available."
exit 1
fi
fi
echo
echo "W: The environment variable DESTDIR is set to the value '$DESTDIR' that is different from '/', the root directory."
echo " This is meant to support testing and packaging, not for a true installation."
echo " If you are using Victron Venus OS, the correct installation directory should be '/'."
echo " No harm is expected to be caused, you anyway have 5 seconds to cancel now with CTRL-C."
echo " No harm is expected to be caused, but it's recommended to install directly to '/' for a standard installation."
echo " You can cancel now with CTRL-C if this is not what you intended."
sleep 5
echo "I: Will now continue. Still, you can interrupt at any time."
echo "I: Will now continue. You can still interrupt at any time."
echo
fi

if ! mkdir -p "$DESTDIR"/data/etc/Spotmarket-Switcher/service ; then
echo "E: Could not create service directory '$DESTDIR/data/etc/Spotmarket-Switcher/service'."
exit 1
fi

downloadToDest () {
url="$1"
dest="$2"

echo "I: Downloading '$(basename "$url")'"
if ! wget --no-verbose --continue --no-directories --show-progress -O "$dest" "$url" ; then
echo "E: Download of '$(basename "$url")' failed."
return 1
fi
chmod +x "$dest"
}

if [ -z "$SRCDIR" ]; then
SRCDIR=scripts
fi
if [ -z "$branch" ]; then
BRANCH=main
fi
if [ -x "$SRCDIR/controller.sh" ]; then
cp "$SRCDIR/controller.sh" "$DESTDIR"/data/etc/Spotmarket-Switcher/
else
if [ -n "$DEBUG" ]; then
# Series of extra info in case the scripts directory is not nearby
echo "D: ls \$SRCDIR"
if ! ls "$SRCDIR"; then
echo "D: pwd: $(pwd)"
ls
fi
fi
echo "I: Downloading 'controller.sh' from github repository - '$BRANCH' branch"
downloadToDest https://raw.githubusercontent.com/christian1980nrw/Spotmarket-Switcher/"$BRANCH"/scripts/controller.sh "$DESTDIR"/data/etc/Spotmarket-Switcher/controller.sh
fi
if [ -x "$SRCDIR/run" ]; then
cp "$SRCDIR/run" "$DESTDIR/data/etc/Spotmarket-Switcher/service/"
else
echo "I: Downloading 'run' from github repository - '$BRANCH' branch"
downloadToDest https://raw.githubusercontent.com/christian1980nrw/Spotmarket-Switcher/"$BRANCH"/scripts/run "$DESTDIR"/data/etc/Spotmarket-Switcher/service/run
fi
ln -s /data/etc/Spotmarket-Switcher/service /service/Spotmarket-Switcher
(crontab -l | grep -Fxq "0 * * * * /data/etc/Spotmarket-Switcher/controller.sh") || (crontab -l; echo "0 * * * * /data/etc/Spotmarket-Switcher/controller.sh") | crontab -

# $DESTDIR is always an absolut path
if [ ! -d "$DESTDIR"/service ]; then
if [ -n "$DESTDIR" ] && [ "/" != "$DESTDIR" ] ; then
echo "I: The '$DESTDIR/service' directory is not existing, as expected because of the custom DESTDIR setting."
echo " Skipping creation of symbolic link to the Sportmarket-Switcher to register this service."
else
echo "W: The '$DESTDIR/service' directory is not existing."
echo " Not installing a symbolic link to the Sportmarket-Switcher to register this service."
echo " Check on https://github.com/christian1980nrw/Spotmarket-Switcher/issues if that has already been reported."
fi
else
if [ ! -L "$DESTDIR"/service/Spotmarket-Switcher ]; then
ln -s "$DESTDIR"/data/etc/Spotmarket-Switcher/service "$DESTDIR"/service/Spotmarket-Switcher
echo
echo "Installation completed. Spotmarket-Switcher will be executed every full hour."
echo "The crontab will be changed automatically by the script '$DESTDIR/data/etc/Spotmarket-Switcher/service/run' ."
echo "Please edit the configuration file with a text editor, like"
echo " vi '$DESTDIR/data/etc/Spotmarket-Switcher/controller.sh'"
echo "and change it to your needs."
echo
if [ -n "$missing" ]; then
echo "Note: Remember to install these missing executables: $missing"
echo
fi
fi

if [ -e "$DESTDIR"/data/rc.local ]; then
if grep -q "Spotmarket-Switcher/service /service/Spotmarket-Switcher" "$DESTDIR"/data/rc.local; then
echo "I: Spotmarket-Switcher/service is already known to rc.local boot script - not added again."
if [ -e "$DESTDIR"/data/rc.local ]; then
if grep -q "Spotmarket-Switcher/service /service/Spotmarket-Switcher" "$DESTDIR"/data/rc.local; then
echo "I: Spotmarket-Switcher/service is already known to rc.local boot script - not added again."
else
echo "I: Adding link to Spotmarket-Switcher/service to rc.local boot script."
sed -i '1s|^|ln -s /data/etc/Spotmarket-Switcher/service /service/Spotmarket-Switcher\n|' /data/rc.local
fi
else
echo "I: Adding link to Spotmarket-Switcher/service to rc.local boot script."
sed -i '1s|^|ln -s /data/etc/Spotmarket-Switcher/service /service/Spotmarket-Switcher\n|' /data/rc.local
echo "I: Creating new data/rc.local boot script"
echo "ln -s /data/etc/Spotmarket-Switcher/service /service/Spotmarket-Switcher" > "$DESTDIR"/data/rc.local
chmod +x "$DESTDIR"/data/rc.local
fi
else
echo "I: Creating new data/rc.local boot script"
echo "ln -s /data/etc/Spotmarket-Switcher/service /service/Spotmarket-Switcher" > "$DESTDIR"/data/rc.local
chmod +x "$DESTDIR"/data/rc.local
fi

echo
echo "Installation completed. Spotmarket-Switcher will be executed every full hour."
echo "The crontab will be changed automatically by the script '$DESTDIR/data/etc/Spotmarket-Switcher/service/run' ."
echo "Please edit the configuration file with a text editor, like"
echo " vi '$DESTDIR/data/etc/Spotmarket-Switcher/controller.sh'"
echo "and change it to your needs."
echo
echo "Note: This installation will survive a Venus OS firmware update."
echo " Please do an extra reboot after every firmware update so that the crontab can be recreated automatically."
echo
if [ -n "$missing" ]; then
echo "Note: Remember to install these missing executables: $missing"
echo
fi

if [ -n "$DESTDIR" ] && [ "/" != "$DESTDIR" ] ; then
echo "I: Not auto-rebooting now since DESTDIR set to a value != '/'."
exit 0
elif [ -e /.dockerenv ]; then
echo "I: Not auto-rebooting since /.dockerenv exists, suggesting execution within docker"
exit 0
elif [ -n "$NO_REBOOT" ]; then
echo "I: Not rebooting the system since NO_REBOOT environment variable is set."
exit 0
else
echo "W: The System will reboot in 20 seconds to finalize the setup."
sleep 20
reboot
fi