captaincore/app/quicksave/list
2024-05-05 05:11:16 -04:00

55 lines
No EOL
1.2 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# Fetches list of quicksaves for a site
#
# `captaincore quicksave 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
quicksave_list="$path/${site}_${site_id}/${environment}/quicksaves/list.json"
if [ ! -f "$quicksave_list" ] || [[ $( wc -c < $quicksave_list | awk '{print $1}' ) == "0" ]]; then
captaincore quicksave list-generate $site-$environment --captain-id=$CAPTAIN_ID
fi
if [[ "$FIELD" != "" ]]; then
cd ${root_path}data
wp eval-file ../lib/local-scripts/quicksave-list-field.php file=$quicksave_list field=$FIELD
return
fi
cat "$quicksave_list"
}
run_command