captaincore/app/size
Austin Ginder 825b54016d 📦 NEW: Go CLI
2021-06-24 23:05:07 -04:00

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>."