captaincore/app/logs/list

47 lines
No EOL
988 B
Bash
Executable file

#!/usr/bin/env bash
#
# Fetches list of server logs for a site
#
# `captaincore logs list <site>`
#
if [ ${#@} -eq 0 ]; then
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Requires a <site>"
exit
fi
while read config; do
if [[ "$config" == "Error:"* ]]; then
continue
fi
declare "$config"
done <<< "$(php ${CAPTAINCORE_PATH}/lib/local-scripts/configs.php fetch)"
site=$1
run_command() {
# Extract environment
if [[ "$site" == *"-staging"* ]]; then
environment=staging
fi
if [[ "$site" == *"-production"* ]]; then
environment=production
fi
if [[ "$site" != *"-"* ]]; then
environment=production
fi
# Load site configs
IFS=$'\n'$'\r'; for line in $(captaincore site get $site --bash --captain-id=$CAPTAIN_ID); do declare "$line"; done
if [ ! -f "$logs_list" ] || [[ $( wc -c < $logs_list | awk '{print $1}' ) == "0" ]]; then
captaincore ssh $site-$environment --script=fetch-log-files --captain-id=$CAPTAIN_ID
fi
}
run_command