Compare commits
No commits in common. "68683c9c9794078c921547bda73411919cbf48f4" and "2e6f71842fad1e735252aa7f03aa8c925ed1d094" have entirely different histories.
68683c9c97
...
2e6f71842f
51
rtenets
51
rtenets
|
@ -77,23 +77,10 @@ alt_var() {
|
||||||
if is_set "${variable}"; then
|
if is_set "${variable}"; then
|
||||||
printf "%s" "$(eval "printf \"%s\" \"\${${variable}}\"")"
|
printf "%s" "$(eval "printf \"%s\" \"\${${variable}}\"")"
|
||||||
else
|
else
|
||||||
printf "%s" "${value_if_unset}"
|
printf "%s" "$value_if_unset"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Enter value if unset
|
|
||||||
cond_enter() {
|
|
||||||
local input="$1"
|
|
||||||
local var_name="$2"
|
|
||||||
local value="$(alt_var "" "${var_name}")"
|
|
||||||
|
|
||||||
if [[ "${value}" == "" ]]; then
|
|
||||||
value="$(enter "${input}")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf "%s" "${value}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check that command exists
|
# Check that command exists
|
||||||
has_command() {
|
has_command() {
|
||||||
command -v "$1" >/dev/null 2>&1
|
command -v "$1" >/dev/null 2>&1
|
||||||
|
@ -152,15 +139,15 @@ set_git_config() {
|
||||||
while ! [[ -n "${value}" ]]; do
|
while ! [[ -n "${value}" ]]; do
|
||||||
value="$(enter "new value for ${param}: ")"
|
value="$(enter "new value for ${param}: ")"
|
||||||
done
|
done
|
||||||
\git config "${param}" "${value}"
|
\git config --global "${param}" "${value}"
|
||||||
info "setting new value for ${param}: '$(\git config "${param}")'"
|
info "setting new value for ${param}: '$(git config "${param}")'"
|
||||||
printf "${value}"
|
printf "${value}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get value of git config parameter, set if unset
|
# Get value of git config parameter, set if unset
|
||||||
get_git_config() {
|
get_git_config() {
|
||||||
local param="$1"
|
local param="$1"
|
||||||
local value="$(\git config "${param}")"
|
local value="$(git config "${param}")"
|
||||||
if ! [[ -n "${value}" ]]; then
|
if ! [[ -n "${value}" ]]; then
|
||||||
warning "git ${param} is unset"
|
warning "git ${param} is unset"
|
||||||
value="$(set_git_config "${param}")"
|
value="$(set_git_config "${param}")"
|
||||||
|
@ -182,7 +169,7 @@ check_git_config() {
|
||||||
# Initialize git repository
|
# Initialize git repository
|
||||||
init_repo() {
|
init_repo() {
|
||||||
check_git_config
|
check_git_config
|
||||||
info "$(\git init)"
|
\git init
|
||||||
}
|
}
|
||||||
|
|
||||||
# ----------------- Tree commands -----------------------
|
# ----------------- Tree commands -----------------------
|
||||||
|
@ -207,8 +194,6 @@ main "\$@"
|
||||||
STUB
|
STUB
|
||||||
chmod +x "${script_name}"
|
chmod +x "${script_name}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "wrote '${script_name}'"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fetch licence
|
# Fetch licence
|
||||||
|
@ -218,8 +203,7 @@ fetch_licence() {
|
||||||
if ! [[ -f "${licence}" ]]; then
|
if ! [[ -f "${licence}" ]]; then
|
||||||
if has_command curl; then
|
if has_command curl; then
|
||||||
info "setting licence to GPL by default, see https://www.gnu.org/licenses for more options"
|
info "setting licence to GPL by default, see https://www.gnu.org/licenses for more options"
|
||||||
\curl -s "https://www.gnu.org/licenses/gpl-3.0.txt" > "${licence}"
|
\curl "https://www.gnu.org/licenses/gpl-3.0.txt" > "${licence}"
|
||||||
info "wrote '${licence}'"
|
|
||||||
else
|
else
|
||||||
warning "please choose a free software licence, see https://www.gnu.org/licenses"
|
warning "please choose a free software licence, see https://www.gnu.org/licenses"
|
||||||
fi
|
fi
|
||||||
|
@ -231,8 +215,8 @@ create_readme() {
|
||||||
local readme="README.md~"
|
local readme="README.md~"
|
||||||
|
|
||||||
if ! [[ -f "${readme}" ]]; then
|
if ! [[ -f "${readme}" ]]; then
|
||||||
local project_name="$(cond_enter "project name: " PROJECT_NAME)"
|
local project_name="$(enter "project name: ")"
|
||||||
local project_desc="$(cond_enter "project short description: " PROJECT_DESC)"
|
local project_desc="$(enter "project short description: ")"
|
||||||
|
|
||||||
cat << READMEMSG > "${readme}"
|
cat << READMEMSG > "${readme}"
|
||||||
# ${project_name}
|
# ${project_name}
|
||||||
|
@ -270,7 +254,6 @@ create_authors_file() {
|
||||||
if ! [[ -f AUTHORS ]]; then
|
if ! [[ -f AUTHORS ]]; then
|
||||||
printf "%s\\n" "${USER} <${EMAIL}> ${AFFILIATION}" > AUTHORS
|
printf "%s\\n" "${USER} <${EMAIL}> ${AFFILIATION}" > AUTHORS
|
||||||
fi
|
fi
|
||||||
info "wrote 'AUTHORS'"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create required files
|
# Create required files
|
||||||
|
@ -337,7 +320,7 @@ setup_dalembert_gitea() {
|
||||||
local remote_ssh="$(jq '.ssh_url' <<< "${repo_json}")"
|
local remote_ssh="$(jq '.ssh_url' <<< "${repo_json}")"
|
||||||
local remote_http="$(jq '.clone_url' <<< "${repo_json}")"
|
local remote_http="$(jq '.clone_url' <<< "${repo_json}")"
|
||||||
|
|
||||||
if [[ "$(\git remote | \grep -c '^dalembert$' || true)" == "0" ]]; then
|
if [[ "$(\git remote | \grep -c '^dalembert$')" == "0" ]]; then
|
||||||
\git remote add dalembert "${remote_ssh}"
|
\git remote add dalembert "${remote_ssh}"
|
||||||
info "created remote dalembert with '${remote_ssh}"
|
info "created remote dalembert with '${remote_ssh}"
|
||||||
else
|
else
|
||||||
|
@ -354,19 +337,14 @@ init-tree() {
|
||||||
declare desc="usage: rtenets init-tree <directory>"
|
declare desc="usage: rtenets init-tree <directory>"
|
||||||
|
|
||||||
local directory="$1"
|
local directory="$1"
|
||||||
(
|
|
||||||
cd "${directory}"
|
|
||||||
init_repo
|
|
||||||
create_tenet_file_tree
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init-gitea() {
|
init-gitea() {
|
||||||
declare desc="usage: rtenets init-gitea <directory>"
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
init-workflow() {
|
init-workflow() {
|
||||||
declare desc="usage: rtenets init-workflow <directory>"
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create git repository
|
# Create git repository
|
||||||
|
@ -380,13 +358,14 @@ create() {
|
||||||
cd "${repo_name}"
|
cd "${repo_name}"
|
||||||
init_repo
|
init_repo
|
||||||
create_tenet_file_tree
|
create_tenet_file_tree
|
||||||
|
setup_dalembert_gitea
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Print usage and exit
|
# Print usage and exit
|
||||||
usage() {
|
usage() {
|
||||||
cat <<USAGE
|
cat <<USAGE
|
||||||
usage: $0 [--help,-h] [--version,-v] command [args...]
|
usage: $0 [--help,-h] [--version] command [args...]
|
||||||
|
|
||||||
Available commands:
|
Available commands:
|
||||||
- create: create and populate a repository
|
- create: create and populate a repository
|
||||||
|
@ -445,6 +424,4 @@ main() {
|
||||||
"${COMMANDS[${command:-default}]:-${COMMANDS[default]}}" "${other_args}"
|
"${COMMANDS[${command:-default}]:-${COMMANDS[default]}}" "${other_args}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Avoid executing main if sourced
|
main "$@"
|
||||||
# https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced
|
|
||||||
(return 0 2&>/dev/null) && main "$@" || true
|
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
source ../rtenets
|
|
||||||
|
|
||||||
test_init-tree() {
|
|
||||||
info "running test_init-tree"
|
|
||||||
init-tree .
|
|
||||||
|
|
||||||
# Test directory is a git repo
|
|
||||||
\git status > /dev/null 2>&1 \
|
|
||||||
|| ( echo "git failed: $PWD is not a repo"; exit 1 )
|
|
||||||
|
|
||||||
# Test config values
|
|
||||||
[[ "$(\git config user.name)" != "" ]] \
|
|
||||||
&& [[ "$(\git config user.email)" != "" ]] \
|
|
||||||
|| ( echo "git config failed"; exit 1 )
|
|
||||||
|
|
||||||
# Test file structure
|
|
||||||
mandatory_files=("README.md~"
|
|
||||||
"AUTHORS"
|
|
||||||
"COPYING"
|
|
||||||
"make_all_figures"
|
|
||||||
"tests/run_all_tests")
|
|
||||||
for file in ${mandatory_files[*]}; do
|
|
||||||
[[ -f "${file}" ]] || ( echo "file ${file} is missig"; exit 1 )
|
|
||||||
done
|
|
||||||
info "finished test_init-tree"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
main() {
|
|
||||||
readonly PROJECT_NAME="TMP PROJECT"
|
|
||||||
readonly PROJECT_DESC="TMP DESCRIPTION"
|
|
||||||
local tmpdir="$(mktemp -d)"
|
|
||||||
(
|
|
||||||
cd "${tmpdir}"
|
|
||||||
test_init-tree
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
main "$@"
|
|
Loading…
Reference in New Issue