diff --git a/openwb-install.sh b/openwb-install.sh index 8653946130..02674bd361 100755 --- a/openwb-install.sh +++ b/openwb-install.sh @@ -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..." @@ -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 @@ -22,7 +27,7 @@ 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" @@ -30,7 +35,7 @@ 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" @@ -38,71 +43,60 @@ 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 diff --git a/web/version b/web/version index 22ab76e321..c07a87d259 100644 --- a/web/version +++ b/web/version @@ -1 +1 @@ -1.99.001 +1.99.002