commit 29e4412d1f84b4c6f88ca9dc66beeff38b135938 Author: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Tue Nov 26 21:54:06 2024 +0200 repomaker complete diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..038d105 --- /dev/null +++ b/LICENSE @@ -0,0 +1,25 @@ +BSD 2-Clause License + +Copyright (c) 2024, mykola2312. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a4d746f --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# repomaker + +Bash tool to quickly initialize git repos + diff --git a/repomaker.sh b/repomaker.sh new file mode 100755 index 0000000..938557a --- /dev/null +++ b/repomaker.sh @@ -0,0 +1,451 @@ +#!/usr/bin/env bash + +# configuration! replace witt your own remotes and names +# but keep REPO_NAME in remote, since it's template and will be replaced be sed +DEV_PATH="/home/USER/dev" +COPYRIGHT_HOLDER="USER" + +REMOTES=( + "git@github.com:USER/REPO_NAME.git" + "https://some.real.git.instance/USER/REPO_NAME.git" +) + +# cat raw.txt | gzip -c -n -f | base64 > encoded.txt +# cat encoded.txt | base64 -d | gzip -d -c -n + +# COPYRIGHT_YEAR, COPYRIGHT_HOLDER +LICENSE_BSD2CLAUSE=$(cat < "$license_file" + + license_template "$license_file" "COPYRIGHT_YEAR" "$(date +%Y)" + license_template "$license_file" "COPYRIGHT_HOLDER" "$COPYRIGHT_HOLDER" + + output=$(cat "$license_file") + rm "$license_file" + echo "$output" +} + +function repomaker_init() { + printf "Enter repo name: "; read repo_name + printf "Enter repo description: "; read repo_desc + + echo "Remotes: " + for i in "${!REMOTES[@]}"; do + printf "\t%d. %s\n" $i "${REMOTES[$i]}" + done + + printf "Select primary remote: "; read iremote_primary + remote_primary="${REMOTES[$iremote_primary]}" + + # create repo directory + repo_path="$DEV_PATH/$repo_name" + mkdir -p "$repo_path" + # generate license + select_license + repomaker_genlicense > "$repo_path/LICENSE" + # add readme + printf "# $repo_name\n\n$repo_desc\n" > "$repo_path/README.md" + # init git repo + cd "$repo_path" + git init + # add primary remote + git remote add origin $(echo "$remote_primary" | sed "s/REPO_NAME/$repo_name/") + # add push remotes + for i in "${!REMOTES[@]}"; do + if [ "$i" -ne "$iremote_primary" ]; then + git remote set-url --add origin $(echo "${REMOTES[$i]}" | sed "s/REPO_NAME/$repo_name/") + fi + done + # all done! +} + + +case "$1" in + "init") + repomaker_init + ;; + "genlicense") + select_license + repomaker_genlicense + ;; + *) + echo "repomaker.sh init/genlicense"; exit 1 +esac