Skip to content

Commit

Permalink
intro evccuser (#1800)
Browse files Browse the repository at this point in the history
* intro evccuser

Signed-off-by: Markus Storm <[email protected]>
  • Loading branch information
mstormi authored Jul 15, 2023
1 parent f0ca27d commit 12531be
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions functions/packages.bash
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ install_evcc() {
echo -n "$(timestamp) [openHABian] Removing EVCC... "
if ! cond_redirect systemctl disable --now evcc.service; then echo "FAILED (disable evcc.service)"; return 1; fi
if cond_redirect apt-get purge --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" evcc; then echo "OK"; else echo "FAILED"; return 1; fi
rm -f "$svcdir/override.conf"
return;
fi

Expand All @@ -729,37 +730,44 @@ install_evcc() {
if ! cond_redirect apt install -y evcc; then echo "FAILED (EVCC package installation)"; return 1; fi

mkdir "$svcdir"
sed -e "s|%USER|${username}|g" "${BASEDIR:-/opt/openhabian}"/includes/evcc-override.conf > "$svcdir/override.conf"
if [[ $(systemctl show -pUser evcc | cut -d= -f2) == "${username:-openhabian}" ]]; then
sed -e "s|%USER|${username}|g" "${BASEDIR:-/opt/openhabian}"/includes/evcc-override.conf > "$svcdir/override.conf"
fi

if ! cond_redirect systemctl enable --now evcc.service; then echo "FAILED (enable evcc.service)"; return 1; fi
cp "${BASEDIR:-/opt/openhabian}/includes/${sudoersFile}" "${sudoersPath}/"
}


## Function for setting up EVCC, the Electric Vehicle Charge Controller
## The function can be invoked INTERACTIVE only and is German only for now.
## The function can be invoked INTERACTIVE only and setup is in German only for now.
##
## setup_evcc
##
setup_evcc() {
local evccuser
local evccConfig="evcc.yaml"
local dir
local port="${1:-7070}"
local introText="This will create a configuration for EVCC, the Electric Vehicle Charge Controller\\nUse the web interface on port $port to access EVCC's own web interface."
local successText="You have successfully created a configuration file for EVCC, the Electric Vehicle Charge Controller\\nIt replaces /etc/evcc.yaml."

if [[ -n $INTERACTIVE ]]; then
whiptail --title "EVCC configuration" --msgbox "$introText" 8 80
evcc configure --advanced
evcc configure --advanced # creates evcc.yaml in current dir
fi

evccuser="$(systemctl show -pUser evcc | cut -d= -f2)"
dir=${evccuser:-${username:-openhabian}}
if [[ -f ${evccConfig} ]]; then
cond_redirect cp /home/"${username:-openhabian}"/${evccConfig} /home/"${username:-openhabian}"/${evccConfig}.SAVE
cond_redirect mv "${evccConfig}" /home/"${username:-openhabian}"
cond_redirect cp /home/"${dir}"/${evccConfig} /home/"${dir}"/${evccConfig}.SAVE
cond_redirect mv "${evccConfig}" /home/"${dir}"
fi
cond_redirect touch /home/"${username:-openhabian}"/${evccConfig}
cond_redirect chown "${username:-openhabian}:openhab" /home/"${username:-openhabian}"/${evccConfig}*
cond_redirect chmod g+w /home/"${username:-openhabian}"/${evccConfig}*
cond_redirect touch /home/"${dir}"/${evccConfig}
cond_redirect chown "${dir}:openhab" /home/"${dir}"/${evccConfig}*
cond_redirect chmod g+w /home/"${dir}"/${evccConfig}*

echo -n "$(timestamp) [openHABian] Created EVCC config, restarting ... "
if cond_redirect systemctl restart evcc.service; then echo "OK"; else echo "FAILED"; fi
}

0 comments on commit 12531be

Please sign in to comment.