|
#!/bin/bash |
|
# Copyright 2019 Google LLC |
|
# |
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
# you may not use this file except in compliance with the License. |
|
# You may obtain a copy of the License at |
|
# |
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
# |
|
# Unless required by applicable law or agreed to in writing, software |
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
# See the License for the specific language governing permissions and |
|
# limitations under the License. |
|
|
|
if [ -z "$1" ]; then |
|
echo "Please pass as first argument the directory." >&2 |
|
exit |
|
fi |
|
|
|
if [ -z "$DATABASE_URL" ]; then |
|
echo "Please set DATABASE_URL as an env variable." >&2 |
|
exit |
|
fi |
|
|
|
TASKS_URL="$DATABASE_URL/tasks.json" |
|
TASKS_QUERY_URL="$TASKS_URL?orderBy=\"visible\"&equalTo=true" |
|
TASKS=$((curl "$TASKS_QUERY_URL" 2>/dev/null) | jq keys | jq -r 'join(" ")') |
|
|
|
if [ -z "$TASKS" ]; then |
|
echo "Invalid database-url" >&2 |
|
exit |
|
fi |
|
|
|
if [ "$TASKS" == "error" ]; then |
|
echo "Error fetching tasks" >&2 |
|
echo $TASKS_QUERY_URL |
|
curl "$TASKS_QUERY_URL" |
|
exit |
|
fi |
|
|
|
echo $TASKS_QUERY_URL |
|
|
|
mkdir -p $1 |
|
pushd $1 |
|
for task in $TASKS; do |
|
mkdir -p $task |
|
pushd $task |
|
(curl "$TASKS_QUERY_URL" 2>/dev/null) | jq '.["'$task'"]' > .metadata.json |
|
visible=$(jq .visible .metadata.json) |
|
if [ "$visible" == "false" ]; then |
|
echo This task is not released > README.md |
|
else |
|
name=$(jq -r .name .metadata.json) |
|
echo "# $name" > README.md |
|
label=$(jq -r .label .metadata.json) |
|
if [ "$label" != "null" ]; then |
|
echo "*$label*" >> README.md |
|
fi |
|
|
|
echo '## Description' >> README.md |
|
jq -r .description .metadata.json >> README.md |
|
|
|
echo '## Aritfacts' >> README.md |
|
attachment=$(jq -r .attachment .metadata.json) |
|
if [ "$attachment" != "null" ]; then |
|
(curl -o attachment.zip $attachment 2>/dev/null) |
|
unzip -o attachment.zip |
|
echo "### Attachments" >> README.md |
|
zip -sf attachment.zip >> README.md |
|
fi |
|
host=$(jq -r .host .metadata.json) |
|
if [ "$host" != "null" ]; then |
|
echo "nc $host" > connect.sh |
|
chmod +x connect.sh |
|
echo "### Remote Server" >> README.md |
|
echo $host >> README.md |
|
fi |
|
link=$(jq -r .link .metadata.json) |
|
if [ "$link" != "null" ]; then |
|
echo "xdg-open $link" > open.sh |
|
chmod +x open.sh |
|
echo "### Website" >> README.md |
|
echo "[$link]($link)" >> README.md |
|
fi |
|
fi |
|
popd |
|
done |
|
popd |