Skip to content

Commit

Permalink
Merge pull request #1016 from thomasjacquin/allsky.sh-improvements
Browse files Browse the repository at this point in the history
Remove legacy, pre-0.8.3 code
  • Loading branch information
linuxkidd authored Feb 12, 2022
2 parents f8a9b23 + ae9fc33 commit aefa2c9
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 160 deletions.
164 changes: 65 additions & 99 deletions allsky.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

# Exit code 100 will cause the service to be stopped so the user can fix the problem.

# Make it easy to find the beginning of this run in the log file.
echo " ***** Starting AllSky *****"

Expand All @@ -13,65 +15,54 @@ cd "${ALLSKY_HOME}"
source "${ALLSKY_HOME}/variables.sh"
if [ -z "${ALLSKY_CONFIG}" ]; then
echo "${RED}*** ERROR: variables not set, can't continue!${NC}"
exit 1
"${ALLSKY_SCRIPTS}/copy_notification_image.sh" "Error" 2>&1
sudo systemctl stop allsky
exit 100
fi

# Reset auto camera selection, so config.sh does not pick up old camera selection.
> "${ALLSKY_CONFIG}/autocam.sh"

# COMPATIBILITY CHECKS
# config.sh moved to a new location in version 0.8.1. Check for it.
# Check for a new variable in config.sh that wasn't in prior versions.
# If not found, force the user to upgrade config.sh
if [ -f "${ALLSKY_CONFIG}/config.sh" ]; then
source "${ALLSKY_CONFIG}/config.sh"
if [ -z "${CAPTURE_SAVE_DIR}" ]; then
echo "${RED}*** ERROR: old version of config.sh detected.${NC}"
echo "See https://github.com/thomasjacquin/allsky/wiki/Upgrade-from-0.8.2-or-prior-versions"
# If not set to something (even "") then it wasn't found and force the user to upgrade config.sh
source "${ALLSKY_CONFIG}/config.sh"
if [ ! -v FAN_DATA_FILE ]; then # FAN_DATA_FILE added after version 0.8.3.
echo "${RED}*** ERROR: old version of ${ALLSKY_CONFIG}/config.sh detected.${NC}"
echo "Please move your current config.sh file to config.sh-OLD, then place the newest one"
echo "from https://github.com/thomasjacquin/allsky in ${ALLSKY_CONFIG} and"
echo "manually copy your data from the old file to the new one.".

"${ALLSKY_SCRIPTS}/copy_notification_image.sh" "Error" 2>&1
sudo systemctl stop allsky
exit 1
fi
else
echo "${RED}*** ERROR: config.sh not in ${ALLSKY_CONFIG}.${NC}"
echo "Please make a backup of your config.sh, ftp-settings.sh, and settings_*.json files,"
echo "then do a full re-install of AllSky."
echo "After the re-install, copy your settings from the backup files to the new files."
echo "Do NOT simply copy the old files over the new ones since several variables have been added or changed names."

"${ALLSKY_SCRIPTS}/copy_notification_image.sh" "Error" 2>&1
sudo systemctl stop allsky
exit 1
exit 100
fi

# Make sure allsky.sh is not already running.
ps -ef | grep allsky.sh | grep -v $$ | xargs "sudo kill -9" 2>/dev/null

# old/regular manual camera selection mode => exit if no requested camera was found
# Buster and Bullseye have different output so only check the part they have in common.
# TODO: this check only needs to be done if CAMERA = RPiHQ
# Bullseye has problems detecting RPiHQ cameras - workaround
which libcamera-still > /dev/null
if [ $? -eq 0 ]; then
LIBCAMERA_LOG_LEVELS="ERROR,FATAL" libcamera-still -t 1 --nopreview
RET=$?
else
vcgencmd get_camera | grep --silent "supported=1"
RET=$?
fi
if [ $RET -eq 0 ]; then
RPiHQIsPresent=1
else
RPiHQIsPresent=0
fi
if [[ $CAMERA == "RPiHQ" && $RPiHQIsPresent -eq 0 ]]; then
echo "RPiHQ Camera not found. Exiting." >&2
if [ -z "${CAMERA}" ]; then
echo "${RED}*** ERROR: CAMERA not set, can't continue!${NC}"
"${ALLSKY_SCRIPTS}/copy_notification_image.sh" "Error" 2>&1
sudo systemctl stop allsky
exit 1
exit 100
fi

if [[ $CAMERA != "RPiHQ" ]]; then
# Make sure allsky.sh is not already running.
pgrep allsky.sh | grep -v $$ | xargs "sudo kill -9" 2>/dev/null

if [ "${CAMERA}" = "RPiHQ" ]; then
# See if we should use libcamera-still or raspistill.
which libcamera-still > /dev/null
if [ $? -eq 0 ]; then
LIBCAMERA_LOG_LEVELS="ERROR,FATAL" libcamera-still --timeout 1 --nopreview > /dev/null 2>&1
RET=$?
else
# Buster and Bullseye have different output so only check the part they have in common.
vcgencmd get_camera | grep --silent "supported=1"
RET=$?
fi
if [ $RET -ne 0 ]; then
echo "${RED}*** ERROR: RPiHQ Camera not found. Exiting.${NC}" >&2
sudo systemctl stop allsky
exit 100
fi

else # ZWO CAMERA
reset_usb() # resets the USB bus
{
if [ "${ON_TTY}" = "1" ]; then
Expand All @@ -84,76 +75,42 @@ if [[ $CAMERA != "RPiHQ" ]]; then
}

# Use two commands to better aid debugging when camera isn't found.
# xxxxx This doesn't catch cases where CAMERA is "auto" and we should use ZWO.
ZWOdev=$(lsusb | awk '/ 03c3:/ { bus=$2; dev=$4; gsub(/[^0-9]/,"",dev); print "/dev/bus/usb/"bus"/"dev;}')
ZWOIsPresent=$(lsusb -D ${ZWOdev} 2>/dev/null | grep -c 'iProduct .*ASI[0-9]')
if [[ $CAMERA == "ZWO" && $ZWOIsPresent -eq 0 ]]; then
echo "ZWO Camera not found..." >&2
if [ $ZWOIsPresent -eq 0 ]; then
echo "${RED}*** ERROR: ZWO Camera not found...${NC}" >&2
if [[ $ZWOdev == "" ]]; then
echo " and no USB entry found for it." >&2
else
echo " but USB entry '$ZWOdev' found for it." >&2
fi
if [ "$UHUBCTL_PATH" != "" ] ; then
reset_usb
exit 1
exit 0 # exit with 0 so the service is restarted
else
echo " Exiting." >&2
echo " If you have the 'uhubctl' command installed, add it to config.sh." >&2
echo " In the meantime, try running it to reset the USB bus." >&2
sudo systemctl stop allsky
exit 1
exit 100
fi
fi
fi

# CAMERA AUTOSELECT
# Exit if no camera found.
WAS_AUTO=0

if [[ $CAMERA == "auto" ]]; then
WAS_AUTO=1
echo "Trying to automatically determine camera type"
if [[ $ZWOIsPresent -eq 0 && $RPiHQIsPresent -eq 0 ]]; then
echo "None of RPI or ZWO Cameras were found. Exiting." >&2
sudo systemctl stop allsky
exit 1
fi
# Prioritize ZWO camera if exists, otherwise use RPI camera.
if [[ $ZWOIsPresent -eq 0 ]]; then
CAMERA="RPiHQ"
else
CAMERA="ZWO"
fi

# redefine the settings variable
CAMERA_SETTINGS="${CAMERA_SETTINGS_DIR}/settings_${CAMERA}.json"
fi

if [ $WAS_AUTO -eq 1 ]; then # Get the proper debug level since earlier config.sh run couldn't.
ALLSKY_DEBUG_LEVEL=$(jq -r '.debuglevel' "${CAMERA_SETTINGS}")
fi

echo "CAMERA: ${CAMERA}"
if [ "${ALLSKY_DEBUG_LEVEL}" -gt 0 ]; then
echo "CAMERA_SETTINGS: ${CAMERA_SETTINGS}"
fi

# Save auto camera selection for the current session, will be read in config.sh file.
echo "export CAMERA=${CAMERA}" > "${ALLSKY_CONFIG}/autocam.sh"

# This must be called after CAMERA AUTOSELECT above to refresh the file name.
source "${ALLSKY_SCRIPTS}/filename.sh"

if [ -d "${ALLSKY_TMP}" ]; then
# remove any lingering old image files.
rm -f "${ALLSKY_TMP}/${FILENAME}"-202*.${EXTENSION} # "202" for 2021 and later
rm -f "${ALLSKY_TMP}/${FILENAME}"-202*.${EXTENSION} # "202" for 2020 and later
else
# Re-create in case it's on a memory filesystem that gets wiped out at reboot
mkdir -p "${ALLSKY_TMP}"
fi

# Optionally display a notification image. This must come after the creation of "autocam.sh" above.
# Optionally display a notification image.
USE_NOTIFICATION_IMAGES=$(jq -r '.notificationimages' "$CAMERA_SETTINGS")
if [ "$USE_NOTIFICATION_IMAGES" = "1" ] ; then
# Can do this in the background to speed up startup
Expand Down Expand Up @@ -210,19 +167,21 @@ else
rm -f "${FREQUENCY_FILE}"
fi

# "capture" expects 0 or 1; newer versions of config.sh use "true" and "false".
# DAYTIME is the old name for DAYTIME_CAPTURE.
# TODO: These checks will go away in the future.
if [ "${DAYTIME_CAPTURE}" = "true" -o "${DAYTIME}" = "1" ] ; then
if [ "${DAYTIME_CAPTURE}" = "true" ] ; then
DAYTIME_CAPTURE=1
elif [ "${DAYTIME_CAPTURE}" = "false" -o "${DAYTIME}" = "0" ] ; then
else
DAYTIME_CAPTURE=0
fi
ARGUMENTS+=(-daytime $DAYTIME_CAPTURE)

[ "$CAPTURE_EXTRA_PARAMETERS" != "" ] && ARGUMENTS+=(${CAPTURE_EXTRA_PARAMETERS}) # Any additional parameters

echo "${ARGUMENTS[@]}" > ${ALLSKY_TMP}/capture_args.txt
echo "${ARGUMENTS[@]}" > ${ALLSKY_TMP}/capture_args.txt # for debugging

GOT_SIGTERM="false"
GOT_SIGUSR1="false"
# trap "GOT_SIGTERM=true" SIGTERM
# trap "GOT_SIGUSR1=true" SIGUSR1

if [[ $CAMERA == "ZWO" ]]; then
CAPTURE="capture"
Expand All @@ -231,15 +190,22 @@ elif [[ $CAMERA == "RPiHQ" ]]; then
fi
"${ALLSKY_HOME}/${CAPTURE}" "${ARGUMENTS[@]}"
RETCODE=$?
[ $RETCODE -ne 0 ] && echo "'${CAPTURE}' exited with RETCODE=${RETCODE}"
if [ $RETCODE -ne 0 ]; then
echo -e "${RED}'${CAPTURE}' exited with RETCODE=${RETCODE}, GOT_SIGTERM=$GOT_SIGTERM, GOT_SIGUSR1=$GOT_SIGUSR1${NC}"
fi

if [ "${USE_NOTIFICATION_IMAGES}" = "1" -a "${RETCODE}" -ne 0 ] ; then
# 98 return code means we are restarting. The capture program dealt with notification images.
if [ "${RETCODE}" -eq 98 ] ; then
exit 0 # use 0 so the service is restarted
fi

# 99 is a special return code which means to reset usb bus if possible.
if [ "${RETCODE}" -eq 99 -a "$UHUBCTL_PATH" != "" ] ; then
reset_usb
fi
# 99 is a special return code which means to reset usb bus if possible.
if [ "${RETCODE}" -eq 99 -a "$UHUBCTL_PATH" != "" ] ; then
reset_usb
exit 0 # use 0 so the service is restarted
fi

if [ "${USE_NOTIFICATION_IMAGES}" = "1" -a "${RETCODE}" -ne 0 ] ; then
# RETCODE -ge 100 means the we should not restart until the user fixes the error.
if [ "$RETCODE" -ge 100 ]; then
echo "***"
Expand Down
62 changes: 28 additions & 34 deletions config_repo/config.sh.repo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# - Values can optionally be quoted with double quotes, NOT single quotes.
# - If a variable occurs multiple times, only the last value is used.

# Choose between "ZWO" or "RPiHQ". Note that "auto" is no longer allowed.
# Choose between "ZWO" or "RPiHQ".
CAMERA=""


Expand Down Expand Up @@ -69,6 +69,15 @@ REMOVE_BAD_IMAGES_THRESHOLD_HIGH=90
# e.g. activate autoexposure algorithm "mean" for RPiHQ: "-mean-value 0.3 -autoexposure 1"
CAPTURE_EXTRA_PARAMETERS=""

# Set to "false" to disable daytime capture.
DAYTIME_CAPTURE="true"

# Night images are always taken and saved to disk.
# Setting DAYTIME_SAVE to "true" also saves daytime images to disk.
# Will only save daytime images if DAYTIME_CAPTURE="true".
DAYTIME_SAVE="false"


########## Timelapse
# Set to "true" to generate a timelapse video at the end of each night.
TIMELAPSE="true"
Expand Down Expand Up @@ -106,10 +115,7 @@ UPLOAD_VIDEO="false"
KEOGRAM="true"

# Additional Keogram parameters. Run "keogram --help" to see the options.
# Keograms work best if North is at the top of the image. If this is not the case you can
# rotate the image; for example, if North is straight down in your image, rotate it 180 degrees.
# Rotation is anticlockwise. 0 disables rotation.
KEOGRAM_EXTRA_PARAMETERS="--rotate 0 --font-size 1.0 --font-line 1 --font-color '255 255 255'"
KEOGRAM_EXTRA_PARAMETERS="--font-size 1.0 --font-line 1 --font-color '255 255 255'"

# Set to "true" to upload the keogram to your website at the end of each night.
UPLOAD_KEOGRAM="false"
Expand Down Expand Up @@ -149,13 +155,10 @@ POST_END_OF_NIGHT_DATA="false"
# You must first create dark frames - see the README.md file for instructions.
DARK_FRAME_SUBTRACTION="false"

# Set to "false" to disable daytime capture.
DAYTIME_CAPTURE="true"

# Night images are always taken and saved to disk.
# Setting DAYTIME_SAVE to "true" also saves daytime images to disk.
# Will only save daytime images if DAYTIME_CAPTURE="true".
DAYTIME_SAVE="false"
# If you have a fan in your Allsky camera enclosure that reports its speed,
# set this to the full pathname of that file.
# The file should include two numbers: the fan speed in RPM and the percent of maximum speed.
FAN_DATA_FILE=""

# The uhubctl command can reset the USB bus if the camera isn't found and you know it's there.
# Allsky.sh uses this to try and fix "missing" cameras.
Expand All @@ -168,12 +171,14 @@ UHUBCTL_PORT=2
# Do not change unless you know what you are doing.
CAMERA_SETTINGS_DIR="${ALLSKY_CONFIG}"


# ================ Do not change anything below this line.
END_OF_USER_SETTINGS="true" # During upgrades, stop looking for variables here.

if [ "${CAMERA}" = "" ]; then
echo "${RED}ERROR: Please set CAMERA in config/config.sh${NC}"
exit 1
elif [ "${CAMERA}" = "auto" ]; then
echo "${RED}ERROR: 'auto' is no longer a valid CAMERA type. Please reset CAMERA in config/config.sh${NC}"
exit 1
sudo systemctl stop allsky
exit 100
fi

# This is needed in case the user changed the default location the current image is saved to.
Expand All @@ -183,23 +188,12 @@ else
CAPTURE_SAVE_DIR="${IMG_DIR}"
fi

# !!! The next few lines are for backwards compatibility and will be removed in the future - do not change !!!
UPLOAD_IMG="${IMG_UPLOAD}" # UPLOAD_IMG is th eold name for IMG_UPLOAD
if [ "${DAYTIME_CAPTURE}" = "true" ]; then
DAYTIME=1 # DAYTIME is the old name for DAYTIME_CAPTURE
else
DAYTIME=0
fi
CAPTURE_24HR=${DAYTIME_SAVE} # CAPTURE_24HR is the old name for DAYTIME_SAVE
CAMERA_SETTINGS="${CAMERA_SETTINGS_DIR}/settings_${CAMERA}.json"

if [[ ${CAMERA} == "auto" ]]; then
# Restore currently saved autodiscovered camera type, if any.
source "${ALLSKY_CONFIG}/autocam.sh" # May reset ${CAMERA}
fi
if [[ ${CAMERA} != "auto" ]]; then
CAMERA_SETTINGS="${CAMERA_SETTINGS_DIR}/settings_${CAMERA}.json"
# Get the name of the file the websites will look for, and split into name and extension.
FULL_FILENAME=$(jq -r '.filename' "$CAMERA_SETTINGS")
EXTENSION="${FULL_FILENAME##*.}"
FILENAME="${FULL_FILENAME%.*}"

# So scripts can conditionally ouput messages; DO NOT CHANGE NEXT LINES.
ALLSKY_DEBUG_LEVEL=$(jq -r '.debuglevel' "${CAMERA_SETTINGS}")
fi
ALLSKY_DEBUG_LEVEL=${ALLSKY_DEBUG_LEVEL:-0}
# So scripts can conditionally ouput messages; DO NOT CHANGE NEXT LINES.
ALLSKY_DEBUG_LEVEL=$(jq -r '.debuglevel' "${CAMERA_SETTINGS}")
4 changes: 0 additions & 4 deletions config_repo/ftp-settings.sh.repo
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ STARTRAILS_DIR=""
STARTRAILS_DESTINATION_NAME=""
WEB_STARTRAILS_DIR=""

# These are for for backwards compatibility and will be removed in the future. DO NOT CHANGE!
IMGDIR="${IMAGE_DIR}"
MP4DIR="${VIDEOS_DIR}"


############### ftp, ftps, sftp, and scp PROTOCOLS only:
# Enter the name of the remote server. If you don't know it, ask your service provider.
Expand Down
1 change: 0 additions & 1 deletion scripts/copy_notification_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ ME="$(basename "${BASH_ARGV0}")"

source "${ALLSKY_HOME}/variables.sh"
source "${ALLSKY_CONFIG}/config.sh"
source "${ALLSKY_SCRIPTS}/filename.sh"
source "${ALLSKY_CONFIG}/ftp-settings.sh"

NOTIFICATIONFILE="$1" # filename, minus the extension, since the extension may vary
Expand Down
1 change: 0 additions & 1 deletion scripts/endOfNight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ fi

source "${ALLSKY_HOME}/variables.sh"
source "${ALLSKY_CONFIG}/config.sh"
source "${ALLSKY_SCRIPTS}/filename.sh"
source "${ALLSKY_CONFIG}/ftp-settings.sh"

if [ $# -eq 1 ] ; then
Expand Down
7 changes: 0 additions & 7 deletions scripts/filename.sh

This file was deleted.

1 change: 0 additions & 1 deletion scripts/generateForDay.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ fi

source "${ALLSKY_HOME}/variables.sh"
source "${ALLSKY_CONFIG}/config.sh"
source "${ALLSKY_SCRIPTS}/filename.sh"
[ "${TYPE}" = "UPLOAD" ] && source "${ALLSKY_CONFIG}/ftp-settings.sh"

# If we're on a tty we are being invoked manually so no need to display ${ME} in error messages.
Expand Down
Loading

0 comments on commit aefa2c9

Please sign in to comment.