Skip to content

Commit

Permalink
Merge pull request #2984 from thomasjacquin/combined-settings
Browse files Browse the repository at this point in the history
Combine all settings into settings.json
  • Loading branch information
EricClaeys authored Sep 26, 2023
2 parents 8a888c5 + bde4a0d commit 2cbb4da
Show file tree
Hide file tree
Showing 57 changed files with 5,466 additions and 3,405 deletions.
69 changes: 34 additions & 35 deletions allsky.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ STOPPED_MSG="Allsky Stopped!"
ERROR_MSG_PREFIX="*** ERROR ***\n${STOPPED_MSG}\n"

#shellcheck disable=SC2086 source-path=.
source "${ALLSKY_HOME}/variables.sh" || exit ${ALLSKY_ERROR_STOP}
source "${ALLSKY_HOME}/variables.sh" || exit "${ALLSKY_ERROR_STOP}"
if [[ -z ${ALLSKY_CONFIG} ]]; then
MSG="FATAL ERROR: 'source variables.sh' did not work properly."
echo -e "${RED}*** ${MSG}${NC}"
Expand All @@ -25,19 +25,17 @@ if [[ -z ${ALLSKY_CONFIG} ]]; then
"${NOT_STARTED_MSG}<br>${MSG}"
fi

#shellcheck disable=SC2086 source-path=scripts
source "${ALLSKY_SCRIPTS}/functions.sh" || exit ${ALLSKY_ERROR_STOP}
#shellcheck disable=SC2086,SC1091 # file doesn't exist in GitHub
source "${ALLSKY_CONFIG}/config.sh" || exit ${ALLSKY_ERROR_STOP}
#shellcheck disable=SC2086 source-path=scripts
source "${ALLSKY_SCRIPTS}/installUpgradeFunctions.sh" || exit ${ALLSKY_ERROR_STOP}
#shellcheck source-path=scripts
source "${ALLSKY_SCRIPTS}/functions.sh" || exit "${ALLSKY_ERROR_STOP}"
#shellcheck source-path=scripts
source "${ALLSKY_SCRIPTS}/installUpgradeFunctions.sh" || exit "${ALLSKY_ERROR_STOP}"

# Make sure they rebooted if they were supposed to.
NEEDS_REBOOT="false"
reboot_needed && NEEDS_REBOOT="true"

# Make sure the settings have been configured after an installation or upgrade.
LAST_CHANGED="$( settings ".lastChanged" )"
LAST_CHANGED="$( settings ".lastchanged" )"
if [[ ${LAST_CHANGED} == "" ]]; then
echo "*** ===== Allsky needs to be configured before it can be used. See the WebUI."
if [[ ${NEEDS_REBOOT} == "true" ]]; then
Expand All @@ -46,12 +44,12 @@ if [[ ${LAST_CHANGED} == "" ]]; then
"Allsky needs\nconfiguration\nand the Pi needs\na reboot" \
"Allsky needs to be configured then the Pi rebooted."
else
doExit "${EXIT_ERROR_STOP}" "ConfigurationNeeded" "" ""
"${ALLSKY_SCRIPTS}/addMessage.sh" "Error" "Allsky needs to be configured."
doExit "${EXIT_ERROR_STOP}" "ConfigurationNeeded" "" ""
fi
elif [[ ${NEEDS_REBOOT} == "true" ]]; then
doExit "${EXIT_ERROR_STOP}" "RebootNeeded" "" ""
"${ALLSKY_SCRIPTS}/addMessage.sh" "Error" "The Pi needs to be rebooted."
doExit "${EXIT_ERROR_STOP}" "RebootNeeded" "" ""
fi

SEE_LOG_MSG="See ${ALLSKY_LOG}"
Expand Down Expand Up @@ -83,7 +81,10 @@ if [[ -f ${POST_INSTALLATION_ACTIONS} ]]; then
fi
fi

USE_NOTIFICATION_IMAGES=$(settings ".notificationimages")
USE_NOTIFICATION_IMAGES="$( settings ".notificationimages" )" || exit "${ALLSKY_ERROR_STOP}"
UHUBCTL_PATH="$( settings ".uhubctlpath" )" || exit "${ALLSKY_ERROR_STOP}"
UHUBCTL_PORT="$( settings ".uhubctlport" )" || exit "${ALLSKY_ERROR_STOP}"
LOCALE="$( settings ".locale" )" || exit "${ALLSKY_ERROR_STOP}"

if [[ -z ${CAMERA_TYPE} ]]; then
MSG="FATAL ERROR: 'Camera Type' not set in WebUI."
Expand All @@ -98,7 +99,7 @@ pgrep "${ME}" | grep -v $$ | xargs "sudo kill -9" 2>/dev/null

if [[ ${CAMERA_TYPE} == "RPi" ]]; then
# "true" means use doExit() on error
RPi_COMMAND_TO_USE="$(determineCommandToUse "true" "${ERROR_MSG_PREFIX}" )"
RPi_COMMAND_TO_USE="$( determineCommandToUse "true" "${ERROR_MSG_PREFIX}" )"

elif [[ ${CAMERA_TYPE} == "ZWO" ]]; then
RPi_COMMAND_TO_USE=""
Expand All @@ -122,7 +123,7 @@ elif [[ ${CAMERA_TYPE} == "ZWO" ]]; then
fi

MSG="${YELLOW}WARNING: Resetting USB ports ${REASON/\\n/ }"
if [[ ${ON_TTY} -eq 1 ]]; then
if [[ ${ON_TTY} == "true" ]]; then
echo "${MSG}; restart ${ME} when done.${NC}" >&2
else
echo "${MSG}, then restarting.${NC}" >&2
Expand All @@ -136,7 +137,7 @@ elif [[ ${CAMERA_TYPE} == "ZWO" ]]; then
"${ALLSKY_SCRIPTS}/generate_notification_images.sh" --directory "${ALLSKY_TMP}" "${FILENAME}" \
"yellow" "" "85" "" "" \
"" "5" "yellow" "${EXTENSION}" "" "WARNING:\n\nResetting USB bus\n${REASON}.\nAttempt ${NUM_USB_RESETS}."
sudo "$UHUBCTL_PATH" -a cycle -l "$UHUBCTL_PORT"
sudo "${UHUBCTL_PATH}" -a cycle -l "${UHUBCTL_PORT}"
sleep 3 # give it a few seconds, plus, allow the notification images to be seen
}

Expand Down Expand Up @@ -190,7 +191,7 @@ fi
# Make sure the settings file is linked to the camera-specific file.
if ! MSG="$( check_settings_link "${SETTINGS_FILE}" )" ; then
"${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${MSG}"
echo "ERROR: Settings file (${SETTINGS_FILE}) not linked correctly." >&2
echo "ERROR: ${MSG}" >&2
fi

# Make directories that need to exist.
Expand All @@ -216,39 +217,39 @@ mkdir "${ALLSKY_ABORTS_DIR}"
sudo chgrp "${WEBSERVER_GROUP}" "${ALLSKY_ABORTS_DIR}"
sudo chmod 775 "${ALLSKY_ABORTS_DIR}"

rm -f "${ALLSKY_NOTIFICATION_LOG}" # clear out any notificatons from prior runs.

# Optionally display a notification image.
if [[ $USE_NOTIFICATION_IMAGES -eq 1 ]]; then
if [[ ${USE_NOTIFICATION_IMAGES} == "true" ]]; then
# Can do this in the background to speed up startup.
"${ALLSKY_SCRIPTS}/copy_notification_image.sh" "StartingUp" 2>&1 &
fi

: > "${ARGS_FILE}"

# If the locale isn't in the settings file, try to determine it.
LOCALE="$(settings .locale)"
if [[ -z ${LOCALE} ]]; then
if [[ -n ${LC_ALL} ]]; then
echo "-Locale=${LC_ALL}" >> "${ARGS_FILE}"
echo "Locale=${LC_ALL}" >> "${ARGS_FILE}"
elif [[ -n ${LANG} ]]; then
echo "-lOcale=${LANG}" >> "${ARGS_FILE}"
echo "lOcale=${LANG}" >> "${ARGS_FILE}"
elif [[ -n ${LANGUAGE} ]]; then
echo "-loCale=${LANGUAGE}" >> "${ARGS_FILE}"
echo "loCale=${LANGUAGE}" >> "${ARGS_FILE}"
fi
fi

# We must pass "-config ${ARGS_FILE}" on the command line,
# and debuglevel we did above, so don't do them again.
TAB="$( echo -e "\t" )"
convert_json_to_tabs "${SETTINGS_FILE}" |
grep -E -i -v "^config${TAB}|^debuglevel${TAB}" |
sed -e 's/^/-/' -e "s/${TAB}/=/" >> "${ARGS_FILE}"
# Only pass settings that are used by the capture program.
"${ALLSKY_WEBUI}/includes/outputJSONwithEqual.php" --capture-only "${OPTIONS_FILE}" |
grep -E -i -v "^config=|^debuglevel=" >> "${ARGS_FILE}"

# When using a desktop environment a preview of the capture can be displayed in a separate window.
# The preview mode does not work if we are started as a service or if the debian distribution has no desktop environment.
[[ $1 == "preview" ]] && echo "-preview=1" >> "${ARGS_FILE}"
[[ $1 == "preview" ]] && echo "preview=true" >> "${ARGS_FILE}"

echo "-version=$( get_version )" >> "${ARGS_FILE}"
echo "-save_dir=${CAPTURE_SAVE_DIR}" >> "${ARGS_FILE}"
echo "version=$( get_version )" >> "${ARGS_FILE}"
echo "save_dir=${CAPTURE_SAVE_DIR}" >> "${ARGS_FILE}"

FREQUENCY_FILE="${ALLSKY_TMP}/IMG_UPLOAD_FREQUENCY.txt"
# If the user wants images uploaded only every n times, save that number to a file.
Expand All @@ -262,8 +263,6 @@ fi

CAPTURE="capture_${CAMERA_TYPE}"

rm -f "${ALLSKY_NOTIFICATION_LOG}" # clear out any notificatons from prior runs.

# Clear up any flow timings
"${ALLSKY_SCRIPTS}/flow-runner.py" --cleartimings

Expand All @@ -277,7 +276,7 @@ RETCODE=$?
[[ ${RETCODE} -eq ${EXIT_OK} ]] && doExit "${EXIT_OK}" ""

if [[ ${RETCODE} -eq ${EXIT_RESTARTING} ]]; then
if [[ ${ON_TTY} -eq 1 ]]; then
if [[ ${ON_TTY} == "true" ]]; then
echo "*** Can restart allsky now. ***"
NOTIFICATION_TYPE="NotRunning"
else
Expand All @@ -290,20 +289,20 @@ if [[ ${RETCODE} -eq ${EXIT_RESET_USB} ]]; then
# Reset the USB bus if possible
if [[ ${UHUBCTL_PATH} != "" ]]; then
reset_usb " (ASI_ERROR_TIMEOUTs)"
if [[ ${ON_TTY} -eq 1 ]]; then
if [[ ${ON_TTY} == "true" ]]; then
echo "*** USB bus was reset; You can restart allsky now. ***"
NOTIFICATION_TYPE="NotRunning"
else
NOTIFICATION_TYPE="Restarting"
fi
if [[ ${USE_NOTIFICATION_IMAGES} -eq 1 ]]; then
if [[ ${USE_NOTIFICATION_IMAGES} == "true" ]]; then
"${ALLSKY_SCRIPTS}/copy_notification_image.sh" "${NOTIFICATION_TYPE}"
fi
doExit 0 "" # use 0 so the service is restarted
else
# TODO: use ASI_ERROR_TIMEOUT message
MSG="Non-recoverable ERROR found"
[[ ${ON_TTY} -eq 1 ]] && echo "*** ${MSG} - ${SEE_LOG_MSG}. ***"
[[ ${ON_TTY} == "true" ]] && echo "*** ${MSG} - ${SEE_LOG_MSG}. ***"
doExit "${EXIT_ERROR_STOP}" "Error" \
"${ERROR_MSG_PREFIX}Too many\nASI_ERROR_TIMEOUT\nerrors received!\n${SEE_LOG_MSG}" \
"${STOPPED_MSG}<br>${MSG}<br>${SEE_LOG_MSG}."
Expand All @@ -313,7 +312,7 @@ fi
# RETCODE -ge ${EXIT_ERROR_STOP} means we should not restart until the user fixes the error.
if [[ ${RETCODE} -ge ${EXIT_ERROR_STOP} ]]; then
echo "***"
if [[ ${ON_TTY} -eq 1 ]]; then
if [[ ${ON_TTY} == "true" ]]; then
echo "*** After fixing, restart ${ME}.sh. ***"
else
echo "*** After fixing, restart the allsky service. ***"
Expand All @@ -323,7 +322,7 @@ if [[ ${RETCODE} -ge ${EXIT_ERROR_STOP} ]]; then
fi

# Some other error
if [[ ${USE_NOTIFICATION_IMAGES} -eq 1 ]]; then
if [[ ${USE_NOTIFICATION_IMAGES} == "true" ]]; then
# If started by the service, it will restart us once we exit.
doExit "${RETCODE}" "NotRunning"
else
Expand Down
29 changes: 21 additions & 8 deletions config_repo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ ifeq ($(PKGBUILD),)
endif


CONFIGFILES := config.sh ftp-settings.sh
CONFIGFILES := config.sh
ENVFILE := env.json
UNINSTALLFILES := $(DESTDIR)$(sysconfdir)/logrotate.d/allsky $(DESTDIR)$(sysconfdir)/rsyslog.d/allsky.conf $(DESTDIR)$(sysconfdir)/systemd/system/allsky.service $(DESTDIR)$(sysconfdir)/systemd/system/allskyperiodic.service

%:
Expand All @@ -42,7 +43,6 @@ uninstall:
@echo `date +%F\ %R:%S` Complete.
@echo `date +%F\ %R:%S` NOTE: Config files were \-NOT\- removed.
@echo `date +%F\ %R:%S` To remove config files, please run \'sudo make remove_configs\'

.PHONY : uninstall

ifeq ($(PKGBUILD),1)
Expand All @@ -57,7 +57,6 @@ createDirs:
@if [ ! -e $(DESTDIR)$(sysconfdir)/profile.d ]; then mkdir -p $(DESTDIR)$(sysconfdir)/profile.d; fi
@if [ ! -e $(DESTDIR)$(sysconfdir)/systemd/system ]; then mkdir -p $(DESTDIR)$(sysconfdir)/systemd/system; fi
@if [ ! -e $(DESTDIR)$(sysconfdir)/udev/rules.d ]; then mkdir -p $(DESTDIR)$(sysconfdir)/udev/rules.d; fi

.PHONY : createDirs

$(CONFIGFILES):
Expand All @@ -67,7 +66,14 @@ $(CONFIGFILES):
fi
.PHONY : $(CONFIGFILES)

install: createDirs $(CONFIGFILES)
$(ENVFILE):
@if [ ! -e $(DESTDIR)$(sysconfdir)/allsky/$@ ]; then \
echo `date +%F\ %R:%S` Copying default $@; \
install -m 0644 $@.repo $(DESTDIR)$(sysconfdir)/allsky/$@; \
fi
.PHONY : $(ENVFILE)

install: createDirs $(CONFIGFILES) $(ENVFILE)
@echo `date +%F\ %R:%S` Setting up udev rules...
@install -D -m 0644 asi.rules $(DESTDIR)$(sysconfdir)/udev/rules.d/
@echo `date +%F\ %R:%S` Setting up logging...
Expand All @@ -80,26 +86,33 @@ install: createDirs $(CONFIGFILES)
@echo `date +%F\ %R:%S` Setting up home environment variable...
@echo -e "export ALLSKY_TMP=/tmp\nexport ALLSKY_CONFIG=$(DESTDIR)$(sysconfdir)/allsky\nexport ALLSKY_SCRIPTS=$(DESTDIR)$(libexecdir)\nexport ALLSKY_NOTIFICATION_IMAGES=$(DESTDIR)$(sharedir)\nexport ALLSKY_IMAGES=/home/allsky/images/" > $(DESTDIR)$(sysconfdir)/profile.d/allsky.sh

else # Not in package build mode

else ############################# Not in package build mode
remove_configs:
@echo `date +%F\ %R:%S` Removing config path and files ../config
@rm -rf ../config

.PHONY : remove_configs

createDirs:
@echo `date +%F\ %R:%S` Creating directory structures...
@if [ ! -e ../config ]; then mkdir -p ../config; chown $(SUDO_USER):$(SUDO_USER) ../config; fi

.PHONY : createDirs

$(CONFIGFILES):
@if [ ! -e ../config/$@ ]; then \
echo `date +%F\ %R:%S` Copying default $@; \
install -m 0644 -o $(SUDO_USER) -g $(SUDO_USER) $@.repo ../config/$@; \
fi
.PHONY : $(CONFIGFILES)

install: createDirs $(CONFIGFILES)
$(ENVFILE):
@if [ ! -e ../$@ ]; then \
echo `date +%F\ %R:%S` Copying default .$@; \
install -m 0644 -o $(SUDO_USER) -g $(SUDO_USER) $@.repo ../$@; \
fi
.PHONY : $(ENVFILE)

install: createDirs $(CONFIGFILES) $(ENVFILE)
@echo `date +%F\ %R:%S` Setting up udev rules...
@install -D -m 0644 asi.rules $(DESTDIR)$(sysconfdir)/udev/rules.d/
@echo `date +%F\ %R:%S` Setting up logging...
Expand Down
1 change: 1 addition & 0 deletions config_repo/allskyDefines.inc.repo
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

// These values are updated during installation.
define('HOME', 'XX_HOME_XX');
define('ALLSKY_HOME', 'XX_ALLSKY_HOME_XX');
define('ALLSKY_CONFIG', 'XX_ALLSKY_CONFIG_XX');
define('ALLSKY_SCRIPTS', 'XX_ALLSKY_SCRIPTS_XX');
Expand Down
Loading

0 comments on commit 2cbb4da

Please sign in to comment.