mirror of
https://gh.wpcy.net/https://github.com/CaptainCore/captaincore.git
synced 2026-04-22 17:28:15 +08:00
52 lines
No EOL
1.2 KiB
Bash
Executable file
52 lines
No EOL
1.2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
#
|
|
# Calculates size of one or more sites.
|
|
#
|
|
# `captaincore size <site>`
|
|
#
|
|
|
|
run_command() {
|
|
|
|
INDEX=1
|
|
site=$@
|
|
|
|
# Load site configs
|
|
while read site_configs; do if [[ $site_configs == "" ]]; then continue; fi; declare "$site_configs"; done <<< "$(captaincore site get $site --bash --captain_id=$CAPTAIN_ID)"
|
|
|
|
if [ -z "$domain" ]; then
|
|
echo "Domain not found"
|
|
return
|
|
fi
|
|
|
|
# Define Rclone site name
|
|
rclone_site_name=${captain_id}-${site}
|
|
|
|
if [ "$home_directory" != "" ]; then
|
|
home_directory="${home_directory}/"
|
|
fi
|
|
|
|
json="["
|
|
size_production=$(rclone size sftp-${rclone_site_name}-production:$home_directory --json)
|
|
size_staging=$(rclone size sftp-${rclone_site_name}-staging:$home_directory --json)
|
|
json+="{\"name\":\"$site\","${size_production:1:${#size_production}}
|
|
if [[ "$size_staging" != "" ]]; then
|
|
json+=","
|
|
fi
|
|
json+="{\"name\":\"$site-staging\","${size_staging:1:${#size_staging}}
|
|
json+="]"
|
|
|
|
echo $json
|
|
|
|
let INDEX=${INDEX}+1
|
|
|
|
}
|
|
|
|
# See if any sites are specifed
|
|
if [ ${#arguments[*]} -eq 1 ]; then
|
|
# Runs on specifed sites
|
|
run_command ${arguments[*]}
|
|
exit
|
|
fi
|
|
|
|
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a <site>." |