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

intro evccuser #1800

Merged
merged 2 commits into from
Jul 15, 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
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
}