Files
openems-build/installation/install-openems.sh

77 lines
2.2 KiB
Bash

#! /bin/bash
RED='\033[0;31m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
host=$(hostname)
read -p "Please enter the host (default: $host): " host_input
host=${host_input:-$host}
read -p "Do you want to set the UI as the default for this server? (yes/no): " ui_default
if [[ "$ui_default" =~ ^[Yy][Ee][Ss]$ ]]; then
echo -e "${YELLOW}WARNING: This will override the default nginx configuration.${NC}"
ui_default=true
else
ui_default=false
fi
echo -e "${GREEN}Summary of Configuration:${NC}"
echo -e "${CYAN}Host: $host${NC}"
echo -e "${CYAN}Set UI as default: ${ui_default}${NC}"
read -p "${CYAN}Do you want to proceed with the installation? (yes/no): ${NC}" proceed
if [[ ! "$proceed" =~ ^[Yy][Ee][Ss]$ ]]; then
echo -e "${RED}Installation aborted.${NC}"
exit 1
fi
echo -e "${GREEN}installing required packages...${NC}"
sudo apt-get update
sudo apt-get install -y openjdk-17-jdk
sudo apt-get install -y nginx
sudo apt-get install -y wget
echo -e "${GREEN}done${NC}"
echo -e "${GREEN}setting up openems system service...${NC}"
# setup openems service
wget -O /etc/systemd/system/openems.service https://git.mumme-it.de/Mumme-IT/openems-build/src/branch/main/installation/openems.service
# setup openems config dir
sudo mkdir -p /etc/openems.d
#fetch openems jar
wget -O /usr/lib/openems/openems.jar https://git.mumme-it.de/Mumme-IT/openems-build/raw/branch/main/latest/openems-edge.jar
# reload systemd and start service
sudo systemctl daemon-reload
sudo systemctl enable openems
sudo systemctl start openems
echo -e "${GREEN}done${NC}"
echo -e "${GREEN}setting up ui as default nginx site...${NC}"
sudo mkdir -p /var/www/openems/html
wget -O ~/openems-ui.zip https://git.mumme-it.de/Mumme-IT/openems-build/raw/branch/main/latest/ui.zip
sudo unzip -o ~/openems-ui.zip -d /var/www/openems/html
sudo rm ~/openems-ui.zip
wget -O /etc/nginx/sites-available/openems https://git.mumme-it.de/Mumme-IT/openems-build/src/branch/main/installation/nginx-config
sudo ln -sf /etc/nginx/sites-available/openems "/etc/nginx/sites-enabled/$host"
if $ui_default; then
sudo ln -sf /etc/nginx/sites-available/openems /etc/nginx/sites-enabled/default
fi
echo -e "${GREEN}done${NC}"