mirror of
https://gh.wpcy.net/https://github.com/CaptainCore/captaincore.git
synced 2026-04-22 19:11:29 +08:00
60 lines
1.3 KiB
Bash
Executable file
60 lines
1.3 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
#
|
|
# Store theme/plugin update logs
|
|
#
|
|
# `captaincore update-fetch <site>`
|
|
#
|
|
|
|
# Load configuration
|
|
root_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; root_path=${root_path%app*}
|
|
source ${root_path}lib/arguments
|
|
|
|
website=$1
|
|
|
|
run_command() {
|
|
|
|
if [[ "$website" == "" ]]; then
|
|
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Please specify a site."
|
|
exit 1
|
|
fi
|
|
|
|
# Load site info
|
|
while read site_configs; do declare "$site_configs"; done <<< "$(captaincore site get $website --bash --captain_id=$captain_id)"
|
|
|
|
# Check for directory
|
|
if [ ! -d "$path/${site}_${site_id}/updates" ]; then
|
|
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Did not find any update logs."
|
|
exit 1
|
|
fi
|
|
|
|
cd $path/${site}_${site_id}/updates
|
|
|
|
count=$(find . -type f -name '*.json' | wc -l | tr -d '[:space:]')
|
|
|
|
# Check for directory
|
|
if [[ "$count" == "0" ]]; then
|
|
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Did not find any update logs."
|
|
exit 1
|
|
fi
|
|
|
|
# Outputs json from all update files
|
|
json="["
|
|
for file in *.json; do
|
|
|
|
if [[ "$file" == *"-plugins.json" ]]; then
|
|
type="plugin"
|
|
fi
|
|
if [[ "$file" == *"-themes.json" ]]; then
|
|
type="theme"
|
|
fi
|
|
date=${file:0:17}
|
|
json+="{\"date\":\"$date\",\"type\":\"$type\",\"updates\":$(cat $file)},";
|
|
done
|
|
json=${json%?}
|
|
json+="]"
|
|
|
|
echo "$json"
|
|
|
|
}
|
|
run_command
|