Skip to content

Commit

Permalink
Merge pull request #339 from benderl/web
Browse files Browse the repository at this point in the history
alpha 2
  • Loading branch information
benderl authored Mar 15, 2022
2 parents e48fab5 + 2dec4e2 commit 197d70d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 49 deletions.
90 changes: 42 additions & 48 deletions openwb-install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/bash
OPENWBBASEDIR=/var/www/html/openWB

if (( $(id -u) != 0 )); then
echo "this script has to be run as user root or with sudo"
exit 1
fi

echo "installing openWB 2 into \"${OPENWBBASEDIR}\""

echo "install required packages..."
Expand All @@ -9,9 +14,9 @@ apt-get -q -y install vim bc apache2 php php-gd php-curl php-xml php-json libapa
echo "done"

echo "check for initial git clone..."
if [ ! -d ${OPENWBBASEDIR}/web ]; then
cd /var/www/html/
git clone https://github.com/openWB/core.git --branch master ${OPENWBBASEDIR}
if [ ! -d "${OPENWBBASEDIR}/web" ]; then
cd /var/www/html/ || exit
git clone https://github.com/openWB/core.git --branch master "${OPENWBBASEDIR}"
chown -R pi:pi openWB
echo "git cloned"
else
Expand All @@ -22,87 +27,76 @@ echo -n "check for ramdisk... "
if grep -Fxq "tmpfs ${OPENWBBASEDIR}/ramdisk tmpfs nodev,nosuid,size=32M 0 0" /etc/fstab; then
echo "ok"
else
mkdir -p ${OPENWBBASEDIR}/ramdisk
mkdir -p "${OPENWBBASEDIR}/ramdisk"
echo "tmpfs ${OPENWBBASEDIR}/ramdisk tmpfs nodev,nosuid,size=32M 0 0" >> /etc/fstab
mount -a
echo "created"
fi

echo -n "check for crontab... "
if [ ! -f /etc/cron.d/openwb ]; then
sudo cp ${OPENWBBASEDIR}/data/config/openwb.cron /etc/cron.d/openwb
cp "${OPENWBBASEDIR}/data/config/openwb.cron" /etc/cron.d/openwb
echo "installed"
else
echo "ok"
fi

# check for mosquitto configuration
echo "check mosquitto installation..."
if [ ! -f /etc/mosquitto/conf.d/openwb.conf ] || ! sudo grep -Fq "persistent_client_expiration" /etc/mosquitto/mosquitto.conf; then
if [ ! -f /etc/mosquitto/conf.d/openwb.conf ] || ! grep -Fq "persistent_client_expiration" /etc/mosquitto/mosquitto.conf; then
echo "updating mosquitto config file"
sudo cp ${OPENWBBASEDIR}/data/config/openwb.conf /etc/mosquitto/conf.d/openwb.conf
sudo service mosquitto restart
service mosquitto stop
sleep 2
cp "${OPENWBBASEDIR}/data/config/openwb.conf" /etc/mosquitto/conf.d/openwb.conf
service mosquitto start
fi

#check for mosquitto_local instance
if [ ! -f /etc/mosquitto/mosquitto_local.conf ]; then
echo "setting up mosquitto local instance"
sudo install -d -m 0755 -o root -g root /etc/mosquitto/conf_local.d/
sudo install -d -m 0755 -o mosquitto -g root /var/lib/mosquitto_local
sudo cp -a ${OPENWBBASEDIR}/data/config/mosquitto_local.conf /etc/mosquitto/mosquitto_local.conf
sudo cp -a ${OPENWBBASEDIR}/data/config/openwb_local.conf /etc/mosquitto/conf_local.d/

sudo cp ${OPENWBBASEDIR}/data/config/mosquitto_local_init /etc/init.d/mosquitto_local
sudo chown root.root /etc/init.d/mosquitto_local
sudo chmod 755 /etc/init.d/mosquitto_local
install -d -m 0755 -o root -g root /etc/mosquitto/conf_local.d/
install -d -m 0755 -o mosquitto -g root /var/lib/mosquitto_local
cp -a "${OPENWBBASEDIR}/data/config/mosquitto_local.conf" /etc/mosquitto/mosquitto_local.conf
cp -a "${OPENWBBASEDIR}/data/config/openwb_local.conf" /etc/mosquitto/conf_local.d/
cp "${OPENWBBASEDIR}/data/config/mosquitto_local_init" /etc/init.d/mosquitto_local
chown root:root /etc/init.d/mosquitto_local
chmod 755 /etc/init.d/mosquitto_local
systemctl daemon-reload
systemctl enable mosquitto_local
service mosquitto_local start
else
sudo cp -a ${OPENWBBASEDIR}/data/config/openwb_local.conf /etc/mosquitto/conf_local.d/
service mosquitto_local stop
sleep 2
cp -a "${OPENWBBASEDIR}/data/config/openwb_local.conf" /etc/mosquitto/conf_local.d/
service mosquitto_local start
fi
sudo systemctl daemon-reload
sudo systemctl enable mosquitto_local
sudo service mosquitto_local restart
echo "mosquitto done"

# echo "disable cronjob logging"
# if grep -Fxq "EXTRA_OPTS=\"-L 0\"" /etc/default/cron
# then
# echo "...ok"
# else
# echo "EXTRA_OPTS=\"-L 0\"" >> /etc/default/cron
# fi

# apache
echo -n "replacing apache default page..."
sudo cp ${OPENWBBASEDIR}/index.html /var/www/html/index.html
cp "${OPENWBBASEDIR}/index.html" /var/www/html/index.html
echo "done"
echo -n "fix upload limit..."
if [ -d "/etc/php/7.3/" ]; then
sudo /bin/su -c "echo 'upload_max_filesize = 300M' > /etc/php/7.3/apache2/conf.d/20-uploadlimit.ini"
sudo /bin/su -c "echo 'post_max_size = 300M' >> /etc/php/7.3/apache2/conf.d/20-uploadlimit.ini"
echo "upload_max_filesize = 300M" > /etc/php/7.3/apache2/conf.d/20-uploadlimit.ini
echo "post_max_size = 300M" >> /etc/php/7.3/apache2/conf.d/20-uploadlimit.ini
echo "done (OS Buster)"
elif [ -d "/etc/php/7.4/" ]; then
sudo /bin/su -c "echo 'upload_max_filesize = 300M' > /etc/php/7.4/apache2/conf.d/20-uploadlimit.ini"
sudo /bin/su -c "echo 'post_max_size = 300M' >> /etc/php/7.4/apache2/conf.d/20-uploadlimit.ini"
echo "upload_max_filesize = 300M" > /etc/php/7.4/apache2/conf.d/20-uploadlimit.ini
echo "post_max_size = 300M" >> /etc/php/7.4/apache2/conf.d/20-uploadlimit.ini
echo "done (OS Bullseye)"
fi

echo "installing python requirements..."
sudo pip install -r ${OPENWBBASEDIR}/requirements.txt

# echo "www-data ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/010_pi-nopasswd

# chmod 777 ${OPENWBBASEDIR}/openwb.conf
# chmod +x ${OPENWBBASEDIR}/modules/*
chmod +x ${OPENWBBASEDIR}/runs/*
chmod +x ${OPENWBBASEDIR}/*.sh
touch /var/log/openWB.log
chmod 777 /var/log/openWB.log
pip install -r "${OPENWBBASEDIR}/requirements.txt"

echo "installing openwb2 system service..."
sudo ln -s ${OPENWBBASEDIR}/data/config/openwb2.service /etc/systemd/system/openwb2.service
sudo systemctl daemon-reload
sudo systemctl enable openwb2.service
sudo systemctl start openwb2.service
ln -s "${OPENWBBASEDIR}/data/config/openwb2.service" /etc/systemd/system/openwb2.service
systemctl daemon-reload
systemctl enable openwb2.service
systemctl start openwb2.service

touch "${OPENWBBASEDIR}/ramdisk/main.log"
chmod 666 "${OPENWBBASEDIR}/ramdisk/main.log"
echo "installation finished, now running atreboot.sh..."
${OPENWBBASEDIR}/runs/atreboot.sh
"${OPENWBBASEDIR}/runs/atreboot.sh" >> "${OPENWBBASEDIR}/ramdisk/main.log" 2>&1
2 changes: 1 addition & 1 deletion web/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.99.001
1.99.002

0 comments on commit 197d70d

Please sign in to comment.