diff --git a/rtenets b/rtenets index 01d6f99..564a37e 100755 --- a/rtenets +++ b/rtenets @@ -100,7 +100,7 @@ gitea() { local method="$1" local request="$2" - curl -X "${request}" -H "Content-Type: application/json" -H "Authorization: token ${TOKEN}" "${ENDPOINT}/${method}" + \curl -X "${request}" -H "Content-Type: application/json" -H "Authorization: token ${TOKEN}" "${ENDPOINT}/${method}" } # ----------------- Git commands ----------------------- @@ -145,8 +145,44 @@ init_repo() { \git init } -# Create required files -create_tenet_file_tree() { +# Make bash script stub +script_stub() { + local script_name="$1" + local start_phrase="$2" + + if ! [ -f "${script_name}" ]; then + mkdir -p "$(dirname "${script_name}")" + cat << STUB > "${script_name}" +#!/usr/bin/env bash +set -euo pipefail + +main() { + printf "${start_phrase}\\n" 1>&2 + # put code here +} + +main "\$@" +STUB + chmod +x "${script_name}" + fi +} + +# Fetch licence +fetch_licence() { + local licence="COPYING" + + if ! [ -f "${licence}" ]; then + if has_command curl; then + info "setting licence to GPL by default, see https://www.gnu.org/licenses for more options" + \curl "https://www.gnu.org/licenses/gpl-3.0.txt" > "${licence}" + else + warning "please choose a free software licence, see https://www.gnu.org/licenses" + fi + fi +} + +# Create README +create_readme() { local readme="README.md~" if ! [ -f "${readme}" ]; then @@ -169,7 +205,7 @@ Here are the dependencies to build and run the code: Here is how to run the code: \`\`\` - +./make_all_figures \`\`\` ## Tests @@ -177,27 +213,27 @@ Here is how to run the code: Here is how to run the tests: \`\`\` - +./tests/run_all_tests \`\`\` READMEMSG info "wrote '${readme}'" fi +} +create_authors_file() { if ! [ -f AUTHORS ]; then printf "%s\\n" "${USER} <${EMAIL}> ${AFFILIATION}" > AUTHORS fi +} - local licence="COPYING" - - if ! [ -f "${licence}" ]; then - if has_command curl; then - info "setting licence to GPL by default, see https://www.gnu.org/licenses for more options" - curl "https://www.gnu.org/licenses/gpl-3.0.txt" > "${licence}" - else - warning "please choose a free software licence, see https://www.gnu.org/licenses" - fi - fi +# Create required files +create_tenet_file_tree() { + create_readme + create_authors_file + fetch_licence + script_stub tests/run_all_tests "Running all tests..." + script_stub make_all_figures "Generating figures..." } # Create git repository