Skip to content

Commit

Permalink
Merge pull request #2711 from thomasjacquin/Determine-if-settings.jso…
Browse files Browse the repository at this point in the history
…n-is-linked-properly

Determine if settings.json is linked properly
  • Loading branch information
EricClaeys authored May 29, 2023
2 parents a8ff9a0 + 4654445 commit 412f493
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 5 deletions.
29 changes: 29 additions & 0 deletions allsky.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,35 @@ else
"${NOT_STARTED_MSG}<br>${MSG}"
fi

# Make sure the settings file is linked to the camera-specific file.
if ! SETTINGS_LINK="$( get_links "${SETTINGS_FILE}" )" ; then
MSG="The settings file (${SETTINGS_FILE}) is not linked to"
MSG="${MSG} a camera-specific file; any setting changes you make will not"
MSG="${MSG} be saved if you switch cameras."
MSG="${MSG}\nERROR: ${SETTINGS_LINK}."
# TODO: Tell them how to fix it.
"${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${MSG}"
echo "ERROR: Settings file (${SETTINGS_FILE}) not linked to camera-specific file." >&2
else
# Make sure it's linked to the correct file.
SETTINGS_LINK="$( basename "${SETTINGS_LINK}" )"
FILE="${SETTINGS_FILE%.*}"
EXT="${SETTINGS_FILE##*.}"
CORRECT_NAME="$( basename "${FILE}_${CAMERA_TYPE}_${CAMERA_MODEL}.${EXT}" )"
if [[ ${SETTINGS_LINK} != "${CORRECT_NAME}" ]]; then
MSG="The settings file (${SETTINGS_FILE}) is not properly linked to"
MSG="${MSG} its camera-specific file; any setting changes you make will not"
MSG="${MSG} be saved if you switch cameras."
MSG="${MSG}\nIt is linked to:"
MSG="${MSG}\n ${SETTINGS_LINK}"
MSG="${MSG}\nbut should be linked to"
MSG="${MSG}\n ${CORRECT_NAME}"
# TODO: Tell them how to fix it.
"${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${MSG}"
echo "ERROR: Settings file (${SETTINGS_FILE}) incorrectly linked to ${SETTINGS_LINK}." >&2
fi
fi

# Make directories that need to exist.
if [[ -d ${ALLSKY_TMP} ]]; then
# remove any lingering old image files.
Expand Down
18 changes: 13 additions & 5 deletions html/documentation/changeLog.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,19 @@ <h4>Enhancements</h4>
<span class="WebUISetting">Camera Type</span>.
For example, replacing a ZWO ASI120 with an ASI290.
</li>
<li>Speed up the installation process by using prebuilt binaries where possible.</li>
<li>The installation only prompts for a new hostname if the current one is the default,
"raspberrypi". The suggested new name is still "allsky".
If the current hostname is anything other than "raspberrypi" it implies the
user has already changed the Pi's name, so don't prompt to change again.
<li>Greatly sped up the installation process when packages are not
already installed by using prebuilt binaries where possible.
</li>
<li>The installation only prompts for a new hostname if the current one
is still the default "raspberrypi".
The suggested new name is still "allsky".
If the current hostname is anything other than the default the user
already changed the Pi's name, so don't prompt to change again.
</li>
<li>Check at startup if the settings file is properly linked to a
camera-specific file.
When it isn't, changes to the settings won't be propogated during
updates to Allsky or when switching cameras.
</li>
</ul>

Expand Down
98 changes: 98 additions & 0 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,101 @@ function settings()
echo "${ME2}: running as $(id --user --name), unable to get json value for '${1}';" >&2
ls -l "${SETTINGS_FILE}" >&2
}


#####
# Return hard any link(s) to the specified file.
# The links must be in the same directory.
# On success return code 0 and the link(s).
# On failure, return code 1 and an error message.
NO_LINK_=3
function get_links()
{
local FILE="$1"
if [[ -z ${FILE} ]]; then
echo "get_links(): File not specified."
return 1
fi
local DIRNAME="$( dirname "${FILE}" )"

# shellcheck disable=SC2012
local INODE="$( ls -l --inode "${FILE}" 2>/dev/null | cut -f1 -d' ' )"
if [[ -z ${INODE} ]]; then
echo "File '${FILE}' not found."
return 2
fi

# Don't include the specified FILE.
LINKS="$(
if [[ ${DIRNAME} == "." ]]; then
x="./"
else
x=""
fi
find "${DIRNAME}" -inum "${INODE}" "!" -path "${x}${FILE}" |
if [[ -n ${x} ]]; then
sed -e "s;^${x};;"
else
cat
fi
)"
if [[ -z ${LINKS} ]]; then
echo "No links for '${FILE}'."
return "${NO_LINK_}"
fi

echo "${LINKS}"
return 0
}


#####
# Make sure the settings file is linked to the camera-specific file.
# Return 0 code and no message if successful, else 1 and return a message.
function check_settings_link()
{
local FILE DIRNAME SETTINGS_LINK RET MSG F E CORRECT_NAME
FILE="$1"
if [[ -z ${FILE} ]]; then
echo "check_settings_link(): Settings file not specified."
return 1
fi

DIRNAME="$( dirname "${FILE}" )"
SETTINGS_LINK="$( get_links "${FILE}" )"
RET=$?
if [[ ${RET} -ne 0 ]]; then
MSG="The settings file (${SETTINGS_FILE}) is not linked to"
MSG="${MSG} a camera-specific file; any setting changes you make will not"
MSG="${MSG} be saved if you switch cameras or upgrade Allsky."
[[ ${RET} -ne "${NO_LINK_}" ]] && MSG="${MSG}\nERROR: ${SETTINGS_LINK}."
echo "${MSG}$( fix_settings_link )"
return 1
else
# Make sure it's linked to the correct file.
SETTINGS_LINK="$( basename "${SETTINGS_LINK}" )"
F="${FILE%.*}"
E="${FILE##*.}"
CORRECT_NAME="$( basename "${F}_${CAMERA_TYPE}_${CAMERA_MODEL}.${E}" )"
if [[ ${SETTINGS_LINK} != "${CORRECT_NAME}" ]]; then
MSG="The settings file (${SETTINGS_FILE}) is not properly linked to"
MSG="${MSG} its camera-specific file; any setting changes you make will not"
MSG="${MSG} be saved if you switch cameras or upgrade Allsky."
MSG="${MSG}\nIt is linked to:"
MSG="${MSG}\n ${DIRNAME}/${SETTINGS_LINK}"
MSG="${MSG}\nbut should be linked to:"
MSG="${MSG}\n ${DIRNAME}/${CORRECT_NAME}"
echo "${MSG}$( fix_settings_link )"
return 1
fi
fi

return 0
}

function fix_settings_link()
{
# TODO: describe how to fix the settings link.
#### echo "\nTo fix: "
return 0
}

0 comments on commit 412f493

Please sign in to comment.