#!/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