Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow web install over prior version #972

Merged
merged 4 commits into from
Jan 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 111 additions & 39 deletions website/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,90 @@ modify_locations() { # Some files have placeholders for certain locations. Modi
(
cd "${WEBSITE_DIR}"

# NOTE: Only want to replace the FIRST instance of XX_ALLSKY_CONFIG_XX.
sed -i "0,/XX_ALLSKY_CONFIG_XX/{s;XX_ALLSKY_CONFIG_XX;${ALLSKY_CONFIG};}" functions.php
sed -i -e "s;XX_ALLSKY_CONFIG_XX;${ALLSKY_CONFIG};" \
-e "s;XX_ON_PI_XX;true;" \
functions.php
)
}

modify_configuration_variables() { # Update some of the configuration variables
# If the user is updating the website, use the prior config files.
# NOTE: if we add/delete a setting in the files we'll need to change the code below.

if [ "${SAVED_OLD}" = "true" ]; then
echo -e "${GREEN}* Retoring prior 'config.js' and 'virtualsky.json' files.${NC}"
cp "${WEBSITE_DIR_OLD}/config.js" "${WEBSITE_DIR_OLD}/virtualsky.json" "${WEBSITE_DIR}"
else
echo -e "${GREEN}* Updating settings in ${WEBSITE_DIR}/config.js${NC}"
# These have N/S and E/W but the config.js needs decimal numbers.
# "N" is positive, "S" negative for LATITUDE.
# "E" is positive, "W" negative for LONGITUDE.
LATITUDE=$(jq -r '.latitude' "$CAMERA_SETTINGS")
DIRECTION=${LATITUDE:1,-1}
if [ "${DIRECTION}" = "S" ]; then
SIGN="-"
AURORAMAP="south"
else
SIGN=""
AURORAMAP="north"
fi
LATITUDE="${SIGN}${LATITUDE%${DIRECTION}}"

LONGITUDE=$(jq -r '.longitude' "$CAMERA_SETTINGS")
DIRECTION=${LONGITUDE:1,-1}
if [ "${DIRECTION}" = "W" ]; then
SIGN="-"
else
SIGN=""
fi
LONGITUDE="${SIGN}${LONGITUDE%${DIRECTION}}"
COMPUTER=$(tail -1 /proc/cpuinfo | sed 's/.*: //')
# xxxx TODO: anything else we can set?
sed -i \
-e "/latitude:/c\ latitude: ${LATITUDE}," \
-e "/longitude:/c\ longitude: ${LONGITUDE}," \
-e "/auroraMap:/c\ auroraMap: \"${AURORAMAP}\"," \
-e "/computer:/c\ computer: \"${COMPUTER}\"," \
"${WEBSITE_DIR}/config.js"
fi
}


# Check if the user is updating an existing installation.
if [ "${1}" = "--update" -o "${1}" = "-update" ] ; then
shift
if [ ! -d "${WEBSITE_DIR}" ]; then
echo -e "${RED}Update specified but no existing website found in '${WEBSITE_DIR}'${NC}" 1>&2
echo -e "${RED}*** ERROR: Update specified but no existing website found in '${WEBSITE_DIR}'${NC}" 1>&2
echo
exit 2
fi

modify_locations

echo
echo -e "${GREEN}* Update complete${NC}"
echo
exit 0 # currently nothing else to do for updates
fi

echo -e "${GREEN}* Fetching website files into ${WEBSITE_DIR}${NC}"
if [ -d "${WEBSITE_DIR}" ]; then
# git will fail if the directory already exists
WEBSITE_DIR_OLD="${WEBSITE_DIR}-OLD"
echo -e "${GREEN}* Saving old website to '${WEBSITE_DIR_OLD}'${NC}"
mv "${WEBSITE_DIR}" "${WEBSITE_DIR_OLD}"
if [ $? -ne 0 ]; then
echo -e "${RED}*** ERROR: Unable to save old website. Exiting.${NC}" 1>&2
echo
exit 3
fi
SAVED_OLD=true
else
SAVED_OLD=false
fi

echo -e "${GREEN}* Fetching website files into '${WEBSITE_DIR}'${NC}"
git clone https://github.com/thomasjacquin/allsky-website.git "${WEBSITE_DIR}"
[ $? -ne 0 ] && echo -e "\n${RED}*** ERROR: Exiting installation${NC}\n" && exit 4
echo

cd "${WEBSITE_DIR}"
Expand All @@ -67,50 +132,57 @@ if [ ! -d startrails/thumbnails -o ! -d keograms/thumbnails -o ! -d videos/thumb
fi

modify_locations
modify_configuration_variables

echo -e "${GREEN}* Updating settings in ${WEBSITE_DIR}/config.js${NC}"
# These have N/S and E/W but the config.js needs decimal numbers.
# "N" is positive, "S" negative for LATITUDE.
# "E" is positive, "W" negative for LONGITUDE.
LATITUDE=$(jq -r '.latitude' "$CAMERA_SETTINGS")
DIRECTION=${LATITUDE:1,-1}
if [ "${DIRECTION}" = "S" ]; then
SIGN="-"
AURORAMAP="south"
else
SIGN=""
AURORAMAP="north"
fi
LATITUDE="${SIGN}${LATITUDE%${DIRECTION}}"
if [ "${SAVED_OLD}" = "true" ]; then
# Each directory has one .php file plus zero or more images.
# Move the thumbnails first so it doesn't appear in the count.

LONGITUDE=$(jq -r '.longitude' "$CAMERA_SETTINGS")
DIRECTION=${LONGITUDE:1,-1}
if [ "${DIRECTION}" = "W" ]; then
SIGN="-"
else
SIGN=""
fi
LONGITUDE="${SIGN}${LONGITUDE%${DIRECTION}}"
COMPUTER=$(tail -1 /proc/cpuinfo | sed 's/.*: //')
# xxxx TODO: anything else we can set?
sed -i \
-e "/latitude:/c\ latitude: ${LATITUDE}," \
-e "/longitude:/c\ longitude: ${LONGITUDE}," \
-e "/auroraMap:/c\ auroraMap: \"${AURORAMAP}\"," \
-e "/computer:/c\ computer: \"${COMPUTER}\"," \
"${WEBSITE_DIR}/config.js"
if [ -d "${WEBSITE_DIR_OLD}/videos/thumbnails" ]; then
mv "${WEBSITE_DIR_OLD}/videos/thumbnails" videos
fi
count=$(ls -1 "${WEBSITE_DIR_OLD}/videos" | wc -l)
if [ "${count}" -gt 1 ]; then
echo -e "${GREEN}* Restoring prior videos${NC}"
mv "${WEBSITE_DIR_OLD}"/videos/allsky-* videos
fi

if [ -d "${WEBSITE_DIR_OLD}/keograms/thumbnails" ]; then
mv "${WEBSITE_DIR_OLD}/keograms/thumbnails" keograms
fi
count=$(ls -1 "${WEBSITE_DIR_OLD}/keograms" | wc -l)
if [ "${count}" -gt 1 ]; then
echo -e "${GREEN}* Restoring prior keograms${NC}"
mv "${WEBSITE_DIR_OLD}"/keograms/keogram-* keograms
fi

if [ -d "${WEBSITE_DIR_OLD}/startrails/thumbnails" ]; then
mv "${WEBSITE_DIR_OLD}/startrails/thumbnails" startrails
fi
count=$(ls -1 "${WEBSITE_DIR_OLD}/startrails" | wc -l)
if [ "${count}" -gt 1 ]; then
echo -e "${GREEN}* Restoring prior startrails${NC}"
mv "${WEBSITE_DIR_OLD}"/startrails/startrails-* startrails
fi
fi

echo
echo -e "${GREEN}* Installation complete${NC}"
echo

# In the meantime, let the user know to do it.
echo "+++++++++++++++++++++++++++++++++++++"
echo "Before using the website you should:"
echo -e " * Edit ${YELLOW}${WEBSITE_DIR}/config.js${NC}"
echo -e " * Look at, and possibly edit ${YELLOW}${WEBSITE_DIR}/virtualsky.json${NC}"
if [ "${SAVED_OLD}" = "true" ]; then
echo -e "Your prior website is in '${WEBSITE_DIR_OLD}'."
echo "All your prior videos, keograms, and startrails, as well as prior configuration files"
echo "were MOVED to the updated website".
echo -e "\nAfter you are convinced everything is working remove your prior version.\n"
else
echo "Before using the website you should:"
echo -e " * Edit ${YELLOW}${WEBSITE_DIR}/config.js${NC}"
echo -e " * Look at, and possibly edit ${YELLOW}${WEBSITE_DIR}/virtualsky.json${NC}"
echo " See https://github.com/thomasjacquin/allsky/wiki/allsky-website-Settings for more information".
fi
if [ "${POST_END_OF_NIGHT_DATA}" != "true" ]; then
echo " * Set 'POST_END_OF_NIGHT_DATA=true' in ${ALLSKY_CONFIG}/config.sh"
echo " * Set 'POST_END_OF_NIGHT_DATA=true' in ${ALLSKY_CONFIG}/config.sh"
fi
echo