Skip to content

Commit

Permalink
Update install.sh: restore PR4 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
EricClaeys authored Oct 26, 2023
1 parent 8579480 commit eebb55d
Showing 1 changed file with 150 additions and 87 deletions.
237 changes: 150 additions & 87 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,24 @@ STATUS_ERROR="Error encountered"
STATUS_INT="Got interrupt"
STATUS_VARIABLES=() # Holds all the variables and values to save

OS="$(grep CODENAME /etc/os-release | cut -d= -f2)" # usually buster or bullseye

##### XXXXXXXXXXXXXXXX TODO: TEMPORARY CHECK FOR Bookworm
if [[ ${OS} == "bookworm" ]]; then
echo -e "\n=========="
echo "Allsky does not yet work on Bookworm, the newest Pi operating system"
echo "released in October, 2023."
echo "We are working on a release that supports Bookworm and"
echo "should have it available shortly."
echo -e "\n=========="
exit 0
OS="$( grep CODENAME /etc/os-release | cut -d= -f2 )" # buster, bullseye, or bookworm
# TODO: check for unknown OS ?
LONG_BITS=$( getconf LONG_BIT ) # Size of a long, 32 or 64

# Check if any extra modules are installed
if [[ -n "$( find /opt/allsky/modules -type f -name "*.py" -print -quit 2> /dev/null )" ]]; then
EXTRA_MODULES_INSTALLED="true"
else
EXTRA_MODULES_INSTALLED="false"
fi

# Check if we have a venv already. If not then the install/update will create it
# but we need to warn the user to reinstall the extra modules if they have them.
if [[ -d "${ALLSKY_HOME}/venv" ]]; then
INSTALLED_VENV="false"
else
INSTALLED_VENV="true"
fi

############################################## functions

Expand Down Expand Up @@ -383,8 +388,8 @@ check_for_raspistill()
STATUS_VARIABLES+=("check_for_raspistill='true'\n")

if W="$( which raspistill )" && [[ ${OS} != "buster" ]]; then
echo display_msg --longonly info "Renaming 'raspistill' on ${OS}."
echo sudo mv "${W}" "${W}-OLD"
display_msg --longonly info "Renaming 'raspistill' on ${OS}."
sudo mv "${W}" "${W}-OLD"
fi
}

Expand Down Expand Up @@ -784,7 +789,7 @@ check_success()
MSG="The full log file is in ${LOG}"
MSG="${MSG}\nThe end of the file is:"
display_msg --log info "${MSG}"
tail -5 "${LOG}"
tail "${LOG}"

return 1
fi
Expand All @@ -796,7 +801,7 @@ check_success()

####
# Install the web server.
install_webserver()
install_webserver_et_al()
{
sudo systemctl stop hostapd 2> /dev/null
sudo systemctl stop lighttpd 2> /dev/null
Expand All @@ -813,21 +818,22 @@ install_webserver()
if ! check_success $? "lighttpd installation failed" "${TMP}" "${DEBUG}" ; then
exit_with_image 1 "${STATUS_ERROR}" "lighttpd installation failed"
fi

FINAL_LIGHTTPD_FILE="/etc/lighttpd/lighttpd.conf"
sed \
-e "s;XX_ALLSKY_WEBUI_XX;${ALLSKY_WEBUI};g" \
-e "s;XX_ALLSKY_HOME_XX;${ALLSKY_HOME};g" \
-e "s;XX_ALLSKY_IMAGES_XX;${ALLSKY_IMAGES};g" \
-e "s;XX_ALLSKY_CONFIG_XX;${ALLSKY_CONFIG};g" \
-e "s;XX_ALLSKY_WEBSITE_XX;${ALLSKY_WEBSITE};g" \
-e "s;XX_ALLSKY_OVERLAY_XX;${ALLSKY_OVERLAY};g" \
-e "s;XX_ALLSKY_DOCUMENTATION_XX;${ALLSKY_DOCUMENTATION};g" \
"${REPO_LIGHTTPD_FILE}" > /tmp/x
sudo install -m 0644 /tmp/x "${FINAL_LIGHTTPD_FILE}" && rm -f /tmp/x

STATUS_VARIABLES+=("install_webserver_et_al='true'\n")
fi

FINAL_LIGHTTPD_FILE="/etc/lighttpd/lighttpd.conf"
sed \
-e "s;XX_ALLSKY_WEBUI_XX;${ALLSKY_WEBUI};g" \
-e "s;XX_ALLSKY_HOME_XX;${ALLSKY_HOME};g" \
-e "s;XX_ALLSKY_IMAGES_XX;${ALLSKY_IMAGES};g" \
-e "s;XX_ALLSKY_CONFIG_XX;${ALLSKY_CONFIG};g" \
-e "s;XX_ALLSKY_WEBSITE_XX;${ALLSKY_WEBSITE};g" \
-e "s;XX_ALLSKY_OVERLAY_XX;${ALLSKY_OVERLAY};g" \
-e "s;XX_ALLSKY_DOCUMENTATION_XX;${ALLSKY_DOCUMENTATION};g" \
"${REPO_LIGHTTPD_FILE}" > /tmp/x
sudo install -m 0644 /tmp/x "${FINAL_LIGHTTPD_FILE}" && rm -f /tmp/x

# Ignore output since it may already be enabled.
sudo lighty-enable-mod fastcgi-php > /dev/null 2>&1

Expand All @@ -845,7 +851,7 @@ install_webserver()
# Starting it added an entry so truncate the file so it's 0-length
sleep 1; truncate -s 0 "${LIGHTTPD_LOG}"

STATUS_VARIABLES+=("install_webserver='true'\n")
STATUS_VARIABLES+=("install_webserver_et_al='true'\n")
}


Expand Down Expand Up @@ -1526,6 +1532,8 @@ update_config_sh()
create_allsky_logs()
{
display_msg --log progress "Setting permissions on ${ALLSKY_LOG} and ${ALLSKY_PERIODIC_LOG}."
TMP="${ALLSKY_INSTALLATION_LOGS}/rsyslog.log"
sudo apt-get --assume-yes install rsyslog > "${TMP}" 2>&1
sudo truncate -s 0 "${ALLSKY_LOG}" "${ALLSKY_PERIODIC_LOG}"
sudo chmod 664 "${ALLSKY_LOG}" "${ALLSKY_PERIODIC_LOG}"
sudo chgrp "${ALLSKY_GROUP}" "${ALLSKY_LOG}" "${ALLSKY_PERIODIC_LOG}"
Expand Down Expand Up @@ -2242,83 +2250,124 @@ do_update()
install_overlay()
{
if [[ ${installed_PHP_modules} != "true" ]]; then
display_msg --log progress "Installing PHP modules."
display_msg --log progress "Installing PHP modules and dependencies."
TMP="${ALLSKY_INSTALLATION_LOGS}/PHP_modules.log"
sudo apt-get --assume-yes install php-zip php-sqlite3 python3-pip > "${TMP}" 2>&1
check_success $? "PHP module installation failed" "${TMP}" "${DEBUG}"
[[ $? -ne 0 ]] && exit_with_image 1 "${STATUS_ERROR}" "PHP module install failed."

display_msg --log progress "Installing other PHP dependencies."
TMP="${ALLSKY_INSTALLATION_LOGS}/libatlas.log"
sudo apt-get --assume-yes install libatlas-base-dev > "${TMP}" 2>&1
check_success $? "PHP dependencies failed" "${TMP}" "${DEBUG}"
[[ $? -ne 0 ]] && exit_with_image 1 "${STATUS_ERROR}" "PHP dependencies failed."

STATUS_VARIABLES+=( "installed_PHP_modules='true'\n" )
fi

# Doing all the python dependencies at once can run /tmp out of space, so do one at a time.
# This also allows us to display progress messages.
if [[ ${OS} == "buster" ]]; then
M=" for Buster"
R="-buster"

# Force pip upgrade, without this installations on Buster fail
pip3 install --upgrade pip > /dev/null 2>&1
else
M=""
R=""
fi
local NAME="Python_dependencies"
local REQUIREMENTS_FILE="${ALLSKY_REPO}/requirements${R}.txt"
local NUM_TO_INSTALL=$( wc -l < "${REQUIREMENTS_FILE}" )

# See how many have already been installed - if all, then skip this step.
local NUM_INSTALLED="$( set | grep -c "^${NAME}" )"
if [[ ${NUM_INSTALLED} -eq "${NUM_TO_INSTALL}" ||
${installed_Python_dependencies} == "true" ]]; then
display_msg --logonly info "Skipping: ${NAME} - all packages already installed"
if [[ ${installed_python} == "true" ]]; then
display_msg --log info "Python and related packages already installed."
else
local TMP="${ALLSKY_INSTALLATION_LOGS}/${NAME}"
display_msg --log progress "Installing ${NAME}${M}:"
local COUNT=0
rm -f "${STATUS_FILE_TEMP}"
while read -r package
# Doing all the python dependencies at once can run /tmp out of space, so do one at a time.
# This also allows us to display progress messages.
M=" for ${OS^}"
R="-${OS}"
if [[ ${OS} == "buster" ]]; then
# Force pip upgrade, without this installations on Buster fail
pip3 install --upgrade pip > /dev/null 2>&1
elif [[ ${OS} != "bullseye" && ${OS} != "bookworm" ]]; then
# TODO: is this an error? Unknown OS?
M=""
R=""
fi

local NAME="Python_dependencies"
display_msg --logonly info "Attempting to locate Python dependency file"

local PREFIX="${ALLSKY_REPO}/requirements"
for REQUIREMENTS_FILE in "${PREFIX}${R}-${LONG_BITS}.txt" \
"${PREFIX}${R}.txt" \
"${PREFIX}-${LONG_BITS}.txt" \
"${PREFIX}.txt" \
"END"
do
((COUNT++))
echo "${package}" > /tmp/package
if [[ ${COUNT} -lt 10 ]]; then
C=" ${COUNT}"
else
C="${COUNT}"
if [[ ${REQUIREMENTS_FILE} == "END" ]]; then
display_msg --log error "Unable to find a requirements file!"
exit_with_image 1 "No requirements file"
fi

local PACKAGE=" === Package # ${C} of ${NUM_TO_INSTALL}: [${package}]"
# Need indirection since the ${STATUS_NAME} is the variable name and we want its value.
local STATUS_NAME="${NAME}_${COUNT}"
eval "STATUS_VALUE=\${${STATUS_NAME}}"
if [[ ${STATUS_VALUE} == "true" ]]; then
display_msg --log progress "${PACKAGE} - already installed."
continue
if [[ -f ${REQUIREMENTS_FILE} ]]; then
display_msg --logonly info "${REQUIREMENTS_FILE} - File found!"
else
display_msg --logonly info "${REQUIREMENTS_FILE} - File not found!"
fi
display_msg --log progress "${PACKAGE}"
done

local NUM_TO_INSTALL=$( wc -l < "${REQUIREMENTS_FILE}" )

# See how many have already been installed - if all, then skip this step.
local NUM_INSTALLED="$( set | grep -c "^${NAME}" )"
if [[ ${NUM_INSTALLED} -eq "${NUM_TO_INSTALL}" ||
${installed_Python_dependencies} == "true" ]]; then
display_msg --logonly info "Skipping: ${NAME} - all packages already installed"
else
# AG - Bookworm mod 12/10/23
display_msg --log progress "Installing Python3-full and related packages."
local TMP="${ALLSKY_INSTALLATION_LOGS}/python_full.log"
(
sudo apt-get --assume-yes install python3-full &&
sudo apt-get --assume-yes install libgfortran5 libopenblas0-pthread
) > "${TMP}" 2>&1
check_success $? "python3-full install failed" "${TMP}" "${DEBUG}"
[[ $? -ne 0 ]] && exit_with_image 1 "${STATUS_ERROR}" "python3-full install failed."

python3 -m venv "${ALLSKY_HOME}/venv"
#shellcheck disable=SC1090,SC1091
source "${ALLSKY_HOME}/venv/bin/activate"

local TMP="${ALLSKY_INSTALLATION_LOGS}/${NAME}"
display_msg --log progress "Installing ${NAME}${M}:"
local COUNT=0
rm -f "${STATUS_FILE_TEMP}"
while read -r package
do
((COUNT++))
echo "${package}" > /tmp/package
if [[ ${COUNT} -lt 10 ]]; then
C=" ${COUNT}"
else
C="${COUNT}"
fi

L="${TMP}.${COUNT}.log"
local M="${NAME} [${package}] failed"
pip3 install --no-warn-script-location -r /tmp/package > "${L}" 2>&1
# These files are too big to display so pass in "0" instead of ${DEBUG}.
if ! check_success $? "${M}" "${L}" 0 ; then
rm -fr "${PIP3_BUILD}"
local PACKAGE=" === Package # ${C} of ${NUM_TO_INSTALL}: [${package}]"
# Need indirection since the ${STATUS_NAME} is the variable name and we want its value.
local STATUS_NAME="${NAME}_${COUNT}"
eval "STATUS_VALUE=\${${STATUS_NAME}}"
if [[ ${STATUS_VALUE} == "true" ]]; then
display_msg --log progress "${PACKAGE} - already installed."
continue
fi
display_msg --log progress "${PACKAGE}"

# Add current status
update_status_from_temp_file
L="${TMP}.${COUNT}.log"
local M="${NAME} [${package}] failed"
pip3 install --no-warn-script-location -r /tmp/package > "${L}" 2>&1
# These files are too big to display so pass in "0" instead of ${DEBUG}.
if ! check_success $? "${M}" "${L}" 0 ; then
rm -fr "${PIP3_BUILD}"

exit_with_image 1 "${STATUS_ERROR}" "${M}."
fi
echo "${STATUS_NAME}='true'" >> "${STATUS_FILE_TEMP}"
done < "${REQUIREMENTS_FILE}"
# Add current status
update_status_from_temp_file

# Add the status back in.
update_status_from_temp_file
exit_with_image 1 "${STATUS_ERROR}" "${M}."
fi
echo "${STATUS_NAME}='true'" >> "${STATUS_FILE_TEMP}"
done < "${REQUIREMENTS_FILE}"

# Add the status back in.
update_status_from_temp_file
fi

STATUS_VARIABLES+=( "installed_python='true'\n" )
fi

if [[ ${installing_Trutype_fonts} != "true" ]]; then
Expand Down Expand Up @@ -2498,7 +2547,7 @@ check_new_exposure_algorithm()
local FIELD="experimentalExposure"
local NEW="$( settings ".${FIELD}" )"
[[ ${NEW} -eq 1 ]] && return

MSG="There is a new auto-exposure algorithm for nighttime images that initial testing indicates"
MSG="${MSG} it creates better images at night and during the day-to-night transition."
MSG="${MSG}\n\nDo you want to use it?"
Expand Down Expand Up @@ -2542,6 +2591,17 @@ remind_old_version()
fi
}

update_modules()
{
if [[ ${EXTRA_MODULES_INSTALLED} == "true" && ${INSTALLED_VENV} == "true" ]]; then
MSG="You appear to have the Allsky Extra modules installed."
MSG="${MSG}\nPlease reinstall these using the normal instructions"
MSG="${MSG} at https://github.com/Alex-developer/allsky-modules"
MSG="${MSG}\nThe extra modules will not function until you have reinstalled them."
whiptail --title "${TITLE}" --msgbox "${MSG}" 12 "${WT_WIDTH}" 3>&1 1>&2 2>&3
display_msg --logonly info "Reminded user to re install the extra modules."
fi
}

clear_status()
{
Expand Down Expand Up @@ -2760,7 +2820,7 @@ if [[ -z ${FUNCTION} && -s ${STATUS_FILE} ]]; then
unset get_desired_locale # forces a re-prompt
unset CURRENT_LOCALE # It will get re-calculated
fi

else
MSG="Do you want to restart the installation from the beginning?"
MSG="${MSG}\n\nSelecting <No> will exit the installation without making any changes."
Expand Down Expand Up @@ -2848,7 +2908,7 @@ display_msg notice "${MSG}"

##### Install web server
# This must come BEFORE save_camera_capabilities, since it installs php.
[[ ${install_webserver} != "true" ]] && install_webserver
[[ ${install_webserver_et_al} != "true" ]] && install_webserver_et_al

##### Install dependencies, then compile and install Allsky software
# This will create the "config" directory and put default files in it.
Expand Down Expand Up @@ -2907,6 +2967,9 @@ fi
##### Let the user know to run check_allsky.sh.
[[ ${remind_run_check_allsky} != "true" ]] && remind_run_check_allsky

##### Check if extra modules need to be reinstalled.
update_modules

##### If needed, remind the user to remove any old Allsky version
# Re-run every time to remind the user again.
remind_old_version
Expand Down

0 comments on commit eebb55d

Please sign in to comment.