mirror of
https://gh.wpcy.net/https://github.com/CaptainCore/captaincore.git
synced 2026-04-18 13:16:01 +08:00
44 lines
No EOL
1.1 KiB
Bash
Executable file
44 lines
No EOL
1.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
#
|
|
# Generates usage stats for one or more sites.
|
|
#
|
|
# `captaincore usage-update <site>`
|
|
#
|
|
|
|
if [ ${#@} -ne 1 ]; then
|
|
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a <site>."
|
|
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
|
|
else
|
|
environment=production
|
|
fi
|
|
|
|
# Load site configs
|
|
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain-id=$CAPTAIN_ID)"
|
|
|
|
folder_size=$( captaincore ssh $site-$environment --captain-id=$CAPTAIN_ID --script=fetch-folder-size )
|
|
|
|
# Views for yearly stats
|
|
visits=$( captaincore stats $site-$environment --captain-id=$CAPTAIN_ID )
|
|
|
|
cd ${CAPTAINCORE_PATH}/data
|
|
wp eval-file ../lib/local-scripts/site-update-usage.php site=$site environment=$environment storage=$folder_size visits=$visits
|
|
|
|
}
|
|
|
|
run_command |