-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·49 lines (37 loc) · 1.49 KB
/
init.sh
File metadata and controls
executable file
·49 lines (37 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
##Usage of init.sh:
## init.sh <module-path>
##
## Reinitializes this repository from scratch using your new module path and
## pushes an initial commit. Assumes the git url is ssh and an appropriately
## named bare repository exists. Probably only works with github or gitlab.
## Feel free to use it or don't. Removes itself on completion.
module=$1
if [[ -z "$module" ]]; then
awk -F'#' '/^##/{print $3}' "$0"
exit 2
fi
project=$(basename "$module")
git_url="git@$(sed 's#/#:#' <<< "$module").git"
printf "module: %s\nproject: %s\ngit_url: %s\n...continue? [y/n] " \
"$module" "$project" "$git_url"
read -r confirm
if [[ $confirm != "y" ]]; then
printf "will not continue, bye\n"
exit 1
fi
die() {
printf "oh noes! init failed at %s\n" "$*"
exit 1
}
rm -rf .git
git init --initial-branch=main || die "git init"
git remote add origin "$git_url" || die "git add origin"
go mod edit -module "$module" || die "go mod edit"
sed -i"" -e "s/strap/$project/g" .gitignore index.html || die "s/strap/$project/"
cat > README.md <<< "# $project"
git add .gitignore README.md go.mod ./*.go index.html static/ || die "git add files"
git commit -m "initialized from github.com/dedelala/strap" || die "initial commit"
git push -u origin main || die "git push"
printf "%s successfully initialized\n" "$module"
rm "$0"