Skip to content

Commit 49b2a60

Browse files
authored
Update support.sh: Some optimizations
1 parent fd4fd29 commit 49b2a60

1 file changed

Lines changed: 55 additions & 60 deletions

File tree

support.sh

Lines changed: 55 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# It does NOT assume Allsky has been installed so only uses scripts and functions
99
# that do not require Allsky to be installed. This is to prevent any issues
1010
# with the Allsky installation from interfering with the data collection.
11-
11+
# Several variables used in the script are defined in variables.sh or installUpgradeFunctions.sh.
1212

1313
[[ -z ${ALLSKY_HOME} ]] && export ALLSKY_HOME="$( realpath "$( dirname "${BASH_ARGV0}" )" )"
1414
ME="$( basename "${BASH_ARGV0}" )"
@@ -107,9 +107,9 @@ function print_heading()
107107

108108
function collect_support_info()
109109
{
110+
### OS Information
110111
# shellcheck disable=SC1091
111112
source /etc/os-release || true
112-
### OS Information
113113
OS_ID="${ID,,}"
114114
OS_VERSION_ID="${VERSION_ID}"
115115
OS_VERSION_CODENAME="${VERSION_CODENAME,,}"
@@ -122,12 +122,26 @@ function collect_support_info()
122122
USER_ID="$( id -u )"
123123

124124
### Hardware Information
125-
PI_REVISION="$( grep -m 1 'Revision' /proc/cpuinfo | gawk '{print $3}' )"
125+
PI_REVISION="$( gawk '
126+
{
127+
if ($1 == "Revision") {
128+
print $3;
129+
exit 0;
130+
}
131+
}' /proc/cpuinfo
132+
)"
126133
CPU_ARCH="$( uname -m )"
127134
CPU_BITS="$( getconf LONG_BIT )"
128135
CPU_TOTAL="$( nproc )"
129136
MEMORY_INFO="$( free -h )"
130-
MEM_TOTAL="$( echo "${MEMORY_INFO}" | grep Mem | gawk '{print $2}' )"
137+
MEM_TOTAL="$( echo "${MEMORY_INFO}" | gawk '
138+
{
139+
if ($1 == "Mem:") {
140+
print $2;
141+
exit 0;
142+
}
143+
}'
144+
)"
131145
if [[ -s ${ALLSKY_PI_VERSION_FILE} ]]; then
132146
PI_MODEL="$( < "${ALLSKY_PI_VERSION_FILE}" )"
133147
else
@@ -144,7 +158,6 @@ function collect_support_info()
144158

145159
### File system information
146160
FILE_SYSTEMS="$( df -h )"
147-
# TODO: GET AS image dir sizes
148161

149162
activate_python_venv
150163
PYTHON_VERSION="$( python3 -V )"
@@ -307,20 +320,15 @@ function generate_support_info()
307320
sudo dpkg-query -l
308321
} > "${APT_FILE}"
309322

310-
local LIGHTTPD_ERROR_LOG="/var/log/lighttpd/error.log"
311323
local LIGHTTPD_ERROR_LOG_FILE="${TEMP_DIR}/lighttpd_error.txt"
312-
if [[ -f ${LIGHTTPD_ERROR_LOG} ]]; then
324+
if [[ -f ${LIGHTTPD_LOG_FILE} ]]; then
313325
# Don't include these - they aren't errors.
314326
grep -E -v " server started | server stopped | logfiles cycled " \
315-
"${LIGHTTPD_ERROR_LOG}" > "${LIGHTTPD_ERROR_LOG_FILE}"
327+
"${LIGHTTPD_LOG_FILE}" > "${LIGHTTPD_ERROR_LOG_FILE}"
316328
fi
317329

318-
PRIOR_WEBSITE_DIR="${ALLSKY_PRIOR_DIR}${ALLSKY_WEBSITE/${ALLSKY_HOME}/}"
319-
if [[ -d ${PRIOR_WEBSITE_DIR} ]]; then
320-
PRIOR_WEBSITE_CONFIG_FILE="${PRIOR_WEBSITE_DIR}/${ALLSKY_WEBSITE_CONFIGURATION_NAME}"
321-
if [[ -s ${PRIOR_WEBSITE_CONFIG_FILE} ]]; then
322-
cp "${PRIOR_WEBSITE_CONFIG_FILE}" "${TEMP_DIR}/${ALLSKY_WEBSITE_CONFIGURATION_NAME}-OLD.json"
323-
fi
330+
if [[ -d ${PRIOR_WEBSITE_DIR} && -s ${PRIOR_WEBSITE_CONFIG_FILE} ]]; then
331+
cp "${PRIOR_WEBSITE_CONFIG_FILE}" "${TEMP_DIR}/${ALLSKY_WEBSITE_CONFIGURATION_NAME}-OLD.json"
324332
fi
325333

326334
if [[ -f ${ALLSKY_WEBSITE_CONFIGURATION_FILE} ]]; then
@@ -339,12 +347,12 @@ function generate_support_info()
339347
print "${RPI_CAMERAS}"
340348
} > "${LIBCAMERA_FILE}"
341349

342-
local CONF_FILE="/etc/lighttpd/lighttpd.conf"
343-
if [[ -f ${CONF_FILE} ]]; then
344-
cp "${CONF_FILE}" "${TEMP_DIR}/etc-$( basename "${CONF_FILE}" ).txt"
350+
351+
if [[ -f ${LIGHTTPD_CONFIG_FILE} ]]; then
352+
cp "${LIGHTTPD_CONFIG_FILE}" "${TEMP_DIR}/etc-$( basename "${LIGHTTPD_CONFIG_FILE}" ).txt"
345353
fi
346354

347-
cp "${ALLSKY_HOME}/variables.json" "${TEMP_DIR}"
355+
[[ -f ${ALLSKY_VARIABLES_JSON_FILE} ]] && cp "${ALLSKY_VARIABLES_JSON_FILE}" "${TEMP_DIR}"
348356

349357
# Copy most of ${ALLSKY_TMP} directory.
350358
if [[ -d ${ALLSKY_TMP} ]]; then
@@ -360,29 +368,17 @@ function generate_support_info()
360368
# The directory should exists unless installation failed.
361369
[[ -d ${ALLSKY_CONFIG} ]] && cp -ar "${ALLSKY_CONFIG}" "${TEMP_DIR}"
362370

363-
local TEMP_DIR_MODULES="${TEMP_DIR}/${ALLSKY_MODULES/${ALLSKY_HOME}}"
364371
local TEMP_DIR_OVERLAY="${TEMP_DIR}/${ALLSKY_OVERLAY/${ALLSKY_HOME}}"
372+
local TEMP_MY_MODULES="${TEMP_DIR}/${ALLSKY_MY_MODULES/${ALLSKY_HOME}}"
373+
local TEMP_DIR_MODULES="${TEMP_DIR}/${ALLSKY_MODULES/${ALLSKY_HOME}}"
365374

366-
# Truncate large files not needed for support.
367-
local X="${TEMP_DIR_OVERLAY}/config/tmp/overlay/de421.bsp"
375+
# Truncate or delete large files not needed for support.
376+
local X="${TEMP_DIR_OVERLAY}/config/overlay/tmp/de421.bsp"
368377
[[ -s ${X} ]] && truncate -s 0 "${X}"
369-
X="${TEMP_DIR_OVERLAY}/system_fonts"
370-
rm -fr "${X}"
371-
372-
# We don't need these files so delete them.
373-
X="${TEMP_DIR}/config/myFiles/modules/moduledata/data/allsky_adsb/adsb_data"
374-
rm -fr "${X}"
375-
X="${TEMP_DIR}/config/myFiles/modules/__pycache__"
376-
rm -fr "${X}"
377-
378-
# If we have any sensitive data in the flows then truncate them.
379-
# If the variables.json file exists then there will be no sensitive data in the flows since
380-
# this data was moved to the env.json file in the same release that created variables.json.
381-
# This could do a version comparison but this is a much simpler check.
382-
if [[ ! -f "${ALLSKY_HOME}/variables.json" ]]; then
383-
X="${TEMP_DIR_MODULES}"
384-
[[ -d ${X} ]] && find "${X}" -type f -exec truncate -s 0 {} +
385-
fi
378+
rm -fr \
379+
"${TEMP_DIR_OVERLAY}/system_fonts" \
380+
"${TEMP_MY_MODULES}/moduledata/data/allsky_adsb/adsb_data" \
381+
"${TEMP_MY_MODULES}/__pycache__"
386382

387383
cd "${TEMP_DIR}" || exit 1
388384

@@ -405,12 +401,11 @@ function generate_support_info()
405401
{ TOTAL += $5; }
406402
END { printf("%d", 0.5 + ((TOTAL / 1024 / 1024) * C)); }'
407403
}
408-
function get_size()
404+
function get_actual_size()
409405
{
410406
local ZIP_FILE="${1}"
411407
local SOURCE="${2}"
412-
# shellcheck disable=SC2086
413-
zip -r "${ZIP_FILE}" ${SOURCE} > /dev/null 2>&1
408+
zip -r "${ZIP_FILE}" "${SOURCE}" > /dev/null 2>&1
414409
get_mb "${ZIP_FILE}"
415410
rm -f "${ZIP_FILE}"
416411
}
@@ -427,22 +422,19 @@ function generate_support_info()
427422
local COMPRESSION_RATIO=0.3 # Normally the logs compress to around 10%, but be very conservative
428423
declare -a ALL_LOGS=()
429424
local INDEX=-1
430-
local ALLSKY_LOG_SIZE_MB=0
431-
local ALLSKY_LOG1_SIZE_MB=0
432-
local ALLSKY_PERIODIC_LOG_SIZE_MB=0
433425
local ALLSKY_LOG1_INDEX="" # If the ".1" log file exist this will be it's index in the array.
434426
local ALLSKY_LOG1="${ALLSKY_LOG}.1" # this should probably go in variables.sh...
435427

436-
# First determine the zipped size of what's currently going into the support log.
428+
# First determine the actual zipped size of what's currently going into the support log.
437429
local TMP_ZIP="${TEMP_DIR}/OTHER_THAN.zip"
438-
local REST_OF_LOG_MB="$( get_size "${TMP_ZIP}" "./*" )"
430+
local REST_OF_LOG_MB="$( get_actual_size "${TMP_ZIP}" "./*" )"
439431
display_msg --logonly info "Zipped size of everything EXCEPT log files: ${REST_OF_LOG_MB} MB."
440432
local TOTAL_SIZE_MB="${REST_OF_LOG_MB}"
441433

442434
local LOG_LINES_TEMP="${LOG_LINES}"
443435
local ESTIMATED_SIZE_MB="$( get_mb --compression-ratio "${COMPRESSION_RATIO}" \
444436
"${ALLSKY_LOG}" "${ALLSKY_LOG1}" "${ALLSKY_PERIODIC_LOG}" )"
445-
ESTIMATED_SIZE_MB=$(( ESTIMATED_SIZE_MB + REST_OF_LOG_MB ))
437+
ESTIMATED_SIZE_LOG=$(( ESTIMATED_SIZE_MB + REST_OF_LOG_MB ))
446438
if [[ ${ESTIMATED_SIZE_MB} -le "${GIT_HUB_LIMIT_MB}" ]]; then
447439
ALL_LOGS=( "${ALLSKY_LOG}" "${ALLSKY_LOG1}" "${ALLSKY_PERIODIC_LOG}" )
448440
MSG="WORST CASE support log size: ${ESTIMATED_SIZE_MB} MB is UNDER limit of ${GIT_HUB_LIMIT_MB} MB."
@@ -451,33 +443,33 @@ function generate_support_info()
451443
else
452444
MSG="ESTIMATED support log size: ${ESTIMATED_SIZE_MB} MB is OVER limit of ${GIT_HUB_LIMIT_MB} MB."
453445
display_msg --logonly info "${MSG}"
454-
display_msg --logonly info "Will check each file."
446+
display_msg --logonly info "Will check each log file:"
455447

456448
# Create a list of logs that exist as well as their size.
457449
if [[ -f ${ALLSKY_LOG} ]]; then
458-
INDEX=$(( INDEX + 1 ))
450+
$(( INDEX++ ))
459451
ALL_LOGS[${INDEX}]="${ALLSKY_LOG}"
460452
TMP_ZIP="${TEMP_DIR}/ALLSKY_LOG.zip"
461-
ALLSKY_LOG_SIZE_MB="$( get_size "${TMP_ZIP}" "${ALLSKY_LOG}" )"
462-
TOTAL_SIZE_MB=$(( TOTAL_SIZE_MB + ALLSKY_LOG_SIZE_MB ))
463-
display_msg --logonly info "Zipped size of ${ALLSKY_LOG}: ${ALLSKY_LOG_SIZE_MB} MB."
453+
X_MB="$( get_actual_size "${TMP_ZIP}" "${ALLSKY_LOG}" )"
454+
TOTAL_SIZE_MB=$(( TOTAL_SIZE_MB + X_MB ))
455+
display_msg --logonly info "Zipped size of ${ALLSKY_LOG}: ${X_MB} MB."
464456
fi
465457
if [[ -f ${ALLSKY_LOG1} ]]; then
466-
INDEX=$(( INDEX + 1 ))
458+
$(( INDEX++ ))
467459
ALL_LOGS[${INDEX}]="${ALLSKY_LOG1}"
468460
TMP_ZIP="${TEMP_DIR}/ALLSKY_LOG1.zip"
469-
ALLSKY_LOG1_SIZE_MB="$( get_size "${TMP_ZIP}" "${ALLSKY_LOG1}" )"
470-
TOTAL_SIZE_MB=$(( TOTAL_SIZE_MB + ALLSKY_LOG1_SIZE_MB ))
471-
display_msg --logonly info "Zipped size of ${ALLSKY_LOG1}: ${ALLSKY_LOG1_SIZE_MB} MB."
461+
X_MB="$( get_actual_size "${TMP_ZIP}" "${ALLSKY_LOG1}" )"
462+
TOTAL_SIZE_MB=$(( TOTAL_SIZE_MB + X_MB ))
463+
display_msg --logonly info "Zipped size of ${ALLSKY_LOG1}: ${X_MB} MB."
472464
fi
473465
if [[ -f ${ALLSKY_PERIODIC_LOG} ]]; then
474-
INDEX=$(( INDEX + 1 ))
466+
$(( INDEX++ ))
475467
ALLSKY_LOG1_INDEX="${INDEX}"
476468
ALL_LOGS[${INDEX}]="${ALLSKY_PERIODIC_LOG}"
477469
TMP_ZIP="${TEMP_DIR}/ALLSKY_PERIODIC_LOG.zip"
478-
ALLSKY_PERIODIC_LOG_SIZE_MB="$( get_size "${TMP_ZIP}" "${ALLSKY_PERIODIC_LOG}" )"
479-
TOTAL_SIZE_MB=$(( TOTAL_SIZE_MB + ALLSKY_PERIODIC_LOG_SIZE_MB ))
480-
display_msg --logonly info "Zipped size of ${ALLSKY_PERIODIC_LOG}: ${ALLSKY_PERIODIC_LOG_SIZE_MB} MB."
470+
X_MB="$( get_actual_size "${TMP_ZIP}" "${ALLSKY_PERIODIC_LOG}" )"
471+
TOTAL_SIZE_MB=$(( TOTAL_SIZE_MB + X_MB ))
472+
display_msg --logonly info "Zipped size of ${ALLSKY_PERIODIC_LOG}: ${X_MB} MB."
481473
fi
482474

483475
local MSG="EXPECTED size of zipped support log: ${TOTAL_SIZE_MB} MB, GitHub limit: ${GIT_HUB_LIMIT_MB} MB."
@@ -522,6 +514,9 @@ function generate_support_info()
522514
# We're in a subshell so we need to "echo" this to pass it back to our invoker.
523515
echo "${DIALOG_COMPLETE_MESSAGE//XX_ZIPNAME_XX/${ZIP_NAME}}"
524516

517+
# Copy this last thing so we get the updated copy.
518+
cp "${DISPLAY_MSG_LOG}" "${TEMP_DIR}/config/logs/"
519+
525520
zip -r "${TEMP_DIR}/${ZIP_NAME}" ./* > /dev/null 2>&1
526521
sudo mv "${ZIP_NAME}" "${ALLSKY_SUPPORT_DIR}"
527522
sudo chown "${USER_NAME}:${WEBSERVER_OWNER}" "${ALLSKY_SUPPORT_DIR}/${ZIP_NAME}"

0 commit comments

Comments
 (0)