Skip to content

Commit

Permalink
Gui/install fixes and changes (#1192)
Browse files Browse the repository at this point in the history
* gui/install.sh: fix permissions

Files should be 644, not 775.

* sudoers: add ifconfig - bug fix

ifconfig needs to be in the file in order for the start/stop network buttons in the WebUI to work.

* lighttpd.conf 2 fixes

1. Add the "thumbnails" directory to the list where buffering is turned off.  Without this, new thumbnails didn't appear until ALL of them were created, and with video thumbnails that could be half a minute, and the user would think the page hung.
2. Remove the "compress" lines since we aren't doing compression.  With the lines there, it produces two warnings in the log file.

* install.sh: misc changes

* Put { } around variables to be consistent.
* Add quotes around some variables.
* No longer any need to replace only the FIRST instance of XX_ALLSKY_HOME_XX in funciton.php, so removed that comment and code.
* Merged the "sed -i" statements from 3 to 2, and added WEBSITE_DIR.

* install.sh: update list of commands

Since "ifconfig" is being added in the PR to "sudoers", check for it during installation.

* variables.sh: change variable names

To be consistent with all other variables pointing to directories, add ALLSKY_WEBUI and ALLSKY_WEBSITE.  The old names will go away in a future release.

* install.sh: replace placeholders in lighttpd.conf

And add ALLSKY_WEBSITE which is needed by the WebUI.

* lighttpd.conf: Use placeholders

* Add a placeholder for "website" which is needed by the WebUI.
* To be consistent with other installation scripts, use placeholders that will be replaced during installation.
  • Loading branch information
EricClaeys authored May 17, 2022
1 parent c8a8082 commit 02c7d61
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
42 changes: 24 additions & 18 deletions gui/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ echo "*** Welcome to the Allsky Web User Interface (WebUI) installation ***"
echo -e "*********************************************************************"
echo -en '\n'

if [[ $EUID -ne 0 ]]; then
if [[ ${EUID} -ne 0 ]]; then
echo -e "${RED}This script must be run as root${NC}" 1>&2
exit 1
fi
Expand All @@ -29,13 +29,15 @@ modify_locations()
echo -e "${GREEN}* Modifying locations in web files${NC}"
(
cd "${PORTAL_DIR}/includes" || exit 1
# NOTE: Only want to replace the FIRST instance of XX_ALLSKY_HOME_XX in funciton.php
# Otherwise, the edit check in functions.php will always fail.
sed -i "0,/XX_ALLSKY_HOME_XX/{s;XX_ALLSKY_HOME_XX;${ALLSKY_HOME};}" functions.php
sed -i "s;XX_ALLSKY_HOME_XX;${ALLSKY_HOME};" save_file.php
sed -i -e "s;XX_ALLSKY_SCRIPTS_XX;${ALLSKY_SCRIPTS};" \
sed -i -e "s;XX_ALLSKY_HOME_XX;${ALLSKY_HOME};" \
-e "s;XX_ALLSKY_WEBSITE_XX;${WEBSITE_DIR};" \
save_file.php

sed -i -e "s;XX_ALLSKY_HOME_XX;${ALLSKY_HOME};" \
-e "s;XX_ALLSKY_SCRIPTS;${ALLSKY_SCRIPTS};" \
-e "s;XX_ALLSKY_IMAGES_XX;${ALLSKY_IMAGES};" \
-e "s;XX_ALLSKY_CONFIG_XX;${ALLSKY_CONFIG};" \
-e "s;XX_ALLSKY_WEBSITE_XX;${WEBSITE_DIR};" \
-e "s;XX_RASPI_CONFIG_XX;${CONFIG_DIR};" \
functions.php
)
Expand Down Expand Up @@ -85,8 +87,8 @@ if [ "${1}" = "--update" ] || [ "${1}" = "-update" ] ; then
# Add entries to sudoers file if not already there.
# This is only needed for people who updated allsky-portal but didn't update allsky.
# Don't simply copy the "allsky" file to /etc/sudoers.d in case "allsky" isn't up to date.
grep --silent "/usr/bin/vcgencmd" /etc/sudoers.d/allsky &&
grep --silent "postData.sh" /etc/sudoers.d/allsky
grep --silent "postData.sh" /etc/sudoers.d/allsky &&
grep --silent "ifconfig" /etc/sudoers.d/allsky
# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo -e "${GREEN}* Updating sudoers list${NC}"
Expand Down Expand Up @@ -118,15 +120,18 @@ service lighttpd restart
echo

echo -e "${GREEN}* Configuring lighttpd${NC}"
# "/home/pi/allsky" is hard coded into file we distribute
sed -i "s|/home/pi/allsky|$(dirname "$SCRIPTPATH")|g" $SCRIPTPATH/lighttpd.conf
install -m 0644 $SCRIPTPATH/lighttpd.conf /etc/lighttpd/lighttpd.conf
sed -i \
-e "s|XX_ALLSKY_HOME_XX|${ALLSKY_HOME}|g" \
-e "s|XX_ALLSKY_IMAGES_XX|${ALLSKY_IMAGES}|g" \
-e "s|XX_ALLSKY_WEBSITE_XX|${ALLSKY_WEBSITE}|g" \
"${SCRIPTPATH}/lighttpd.conf"
install -m 0644 "${SCRIPTPATH}/lighttpd.conf" /etc/lighttpd/lighttpd.conf
echo

if [ "${NEED_TO_UPDATE_HOST_NAME}" = "true" ]; then
echo -e "${GREEN}* Changing hostname to '${HOST_NAME}'${NC}"
echo "$HOST_NAME" > /etc/hostname
sed -i "s/127.0.1.1.*$CURRENT_HOSTNAME/127.0.1.1\t$HOST_NAME/g" /etc/hosts
echo "${HOST_NAME}" > /etc/hostname
sed -i "s/127.0.1.1.*${CURRENT_HOSTNAME}/127.0.1.1\t${HOST_NAME}/g" /etc/hosts
echo
else
echo -e "${GREEN}* Leaving hostname at '${HOST_NAME}'${NC}"
Expand All @@ -137,8 +142,8 @@ FILE="/etc/avahi/avahi-daemon.conf"
if [ $? -ne 0 ]; then
# New HOST_NAME not found, or file doesn't exist, so need to configure file.
echo -e "${GREEN}* Configuring avahi-daemon${NC}"
install -m 0644 $SCRIPTPATH/avahi-daemon.conf "${FILE}"
sed -i "s/allsky/$HOST_NAME/g" "${FILE}" # "allsky" is hard coded in file we distribute
install -m 0644 "${SCRIPTPATH}/avahi-daemon.conf" "${FILE}"
sed -i "s/allsky/${HOST_NAME}/g" "${FILE}" # "allsky" is hard coded in file we distribute
echo
fi

Expand Down Expand Up @@ -167,7 +172,8 @@ fi
echo -e "${GREEN}* Retrieving github files to build admin portal${NC}"
git clone https://github.com/thomasjacquin/allsky-portal.git "${PORTAL_DIR}"
chown -R ${SUDO_USER}:www-data "${PORTAL_DIR}"
chmod -R 775 "${PORTAL_DIR}"
find "${PORTAL_DIR}/" -type f -exec chmod 644 {} \;
find "${PORTAL_DIR}/" -type d -exec chmod 775 {} \;

# Restore WEBSITE_DIR if it existed before
if [ "${TMP_WEBSITE_DIR}" != "" ]; then
Expand All @@ -194,7 +200,7 @@ else
install -m 0644 -o www-data -g www-data ${ALLSKY_CONFIG}/settings_RPiHQ.json "${CONFIG_DIR}"
fi
chown -R www-data:www-data "${CONFIG_DIR}"
usermod -a -G www-data $SUDO_USER
usermod -a -G www-data ${SUDO_USER}
echo
# don't leave unused files around
rm -f ${ALLSKY_CONFIG}/settings_ZWO.json ${ALLSKY_CONFIG}/settings_RPiHQ.json
Expand All @@ -203,7 +209,7 @@ echo -e "${GREEN}* Modify config.sh${NC}"
sed -i "/CAMERA_SETTINGS_DIR=/c\CAMERA_SETTINGS_DIR=\"${CONFIG_DIR}\"" ${ALLSKY_CONFIG}/config.sh
echo -en '\n'

if (whiptail --title "Allsky Software Installer" --yesno "The Allsky WebUI is now installed. You can now reboot the Raspberry Pi and connect to it at this address: http://$HOST_NAME.local or http://$(hostname -I | sed -e 's/ .*$//') Would you like to Reboot now?" 10 60 \
if (whiptail --title "Allsky Software Installer" --yesno "The Allsky WebUI is now installed. You can now reboot the Raspberry Pi and connect to it at this address: http://${HOST_NAME}.local or http://$(hostname -I | sed -e 's/ .*$//') Would you like to Reboot now?" 10 60 \
3>&1 1>&2 2>&3); then
reboot now
else
Expand Down
11 changes: 5 additions & 6 deletions gui/lighttpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ server.port = 80

dir-listing.activate = "enable"

$HTTP["url"] =~ "allsky/videos|allsky/startrails|allsky/keograms" {
$HTTP["url"] =~ "thumbnails|allsky/videos|allsky/startrails|allsky/keograms" {
server.stream-response-body = 1
} else $HTTP["url"] =~ "^/current" {
expire.url = ( "" => "access plus 0 seconds")
Expand All @@ -26,8 +26,10 @@ $HTTP["url"] =~ "allsky/videos|allsky/startrails|allsky/keograms" {
)
}

alias.url = ("/current/" => "/home/pi/allsky/")
alias.url += ("/images/" => "/home/pi/allsky/images/")
alias.url = ("/current/" => "XX_ALLSKY_HOME_XX")
alias.url += ("/images/" => "XX_ALLSKY_IMAGES_XX")
alias.url += ("/website/" => "XX_ALLSKY_WEBSITE_XX")

# strict parsing and normalization of URL for consistency and security
# https://redmine.lighttpd.net/projects/lighttpd/wiki/Server_http-parseoptsDetails
# (might need to explicitly set "url-path-2f-decode" = "disable"
Expand All @@ -50,9 +52,6 @@ index-file.names = ( "index.php", "index.html" )
url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" )

#mimetype.assign = (".css" => "text/css", )

# default listening port for IPv6 falls back to the IPv4 port
Expand Down
1 change: 1 addition & 0 deletions gui/sudoers
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ www-data ALL=(ALL) NOPASSWD:/bin/cp
www-data ALL=(ALL) NOPASSWD:/bin/mv
www-data ALL=(ALL) NOPASSWD:/usr/bin/vcgencmd
www-data ALL=(ALL) NOPASSWD:XX_ALLSKY_SCRIPTS_XX/postData.sh
www-data ALL=(ALL) NOPASSWD:/usr/sbin/ifconfig
6 changes: 4 additions & 2 deletions variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ if [ "${ALLSKY_VARIABLE_SET}" = "" ]; then
ALLSKY_DARKS="${ALLSKY_DARKS:-${ALLSKY_HOME}/darks}"

# Location of optional allsky-portal package.
PORTAL_DIR=${PORTAL_DIR:-/var/www/html}
ALLSKY_WEBUI=${ALLSKY_WEBUI:-/var/www/html}
PORTAL_DIR=${ALLSKY_WEBUI} # old name - will eventually remove this

# Location of optional allsky-website package.
WEBSITE_DIR=${WEBSITE_DIR:-${PORTAL_DIR}/allsky}
ALLSKY_WEBSITE=${ALLSKY_WEBSITE:-${ALLSKY_WEBUI}/allsky}
WEBSITE_DIR=${ALLSKY_WEBSITE} # old name - will eventually remove this
fi

0 comments on commit 02c7d61

Please sign in to comment.