-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·139 lines (107 loc) · 3.94 KB
/
bootstrap.sh
File metadata and controls
executable file
·139 lines (107 loc) · 3.94 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/env sh
#
# Copyright (C) 2019 StudentIngegneria
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
export LC_ALL=C
askPrompt()
{
echo "$2"
printf "%s" " ➜ "
#shellcheck disable=SC2162
read "$1"
}
checkExecutable()
{
if ! command -v "$1" > /dev/null ; then
echo "ERROR: $1 executable not found in PATH"
exit 2
fi
}
abort()
{
echo "[*] Error. Program aborted. Cleaning up"
eval 'rm -rf $projectName'
exit $1
}
scriptName="$( echo "$0" | sed s/^.*\\/// )"
scriptDir="$( echo "$0" | sed s/[\\/]"${scriptName}"// )"
echo
echo "${scriptName} : StudentIngegneria IT Committee git flow bootstrapper"
echo
echo "====================================================================="
echo "Copyright (C) 2019 StudentIngegneria"
echo "This program is free software: you can redistribute it and/or modify"
echo "it under the terms of the GNU General Public License as published by"
echo "the Free Software Foundation, either version 3 of the License, or"
echo "(at your option) any later version."
echo
echo "This program is distributed in the hope that it will be useful,"
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo "GNU General Public License for more details."
echo
echo "You should have received a copy of the GNU General Public License"
echo "along with this program. If not, see <https://www.gnu.org/licenses/>."
echo "======================================================================"
echo
echo
# Check preconditions
checkExecutable git
checkExecutable git-flow
askPrompt projectPath "Project path ( last element will be the project name )"
askPrompt useOnlineRepo "Sync with an existing online repo ? [yn]"
# shellcheck disable=SC2154
projectName="$( echo "${projectPath}" | sed s/^.*\\/// )"
# TODO: Fix paths if . is specified as project path
# Setup project
mkdir -p "$projectPath" || exit $?
cd "$projectPath" || exit $?
git init
echo ":: Configuring git flow"
git config --local --add gitflow.branch.master release
git config --local --add gitflow.branch.develop dev
git config --local --add gitflow.prefix.feature feature/
git config --local --add gitflow.prefix.bugfix bugfix/
git config --local --add gitflow.prefix.release rc/
git config --local --add gitflow.prefix.hotfix hotfix/
git config --local --add gitflow.prefix.support support/
git config --local --add gitflow.prefix.versiontag v
git config --local --add gitflow.path.hooks .git/hooks
echo ":: Configuring remotes"
while git remote | grep -E '^si$' > /dev/null ; do
echo -e "\t/!\\ WARNING: \"si\" remote already exists. Delete or rename it"
echo -e "\t/!\\ Dropping a subshell. Invoke 'exit' when you're done"
$SHELL
echo -e "\t:: Resuming script execution\n"
done
git remote add si "https://github.com/StudentIngegneria/${projectName}"
# shellcheck disable=SC2154
if [ "$useOnlineRepo" = "y" ] ; then
echo ":: Synchronizing with remote repository"
git fetch --all -q || abort $?
echo ":: Setting up branches"
git checkout -q release
git checkout -q dev
else
echo ":: Bootstrapping branches"
git checkout -b dev
git checkout -b dev
# If log is empty
if [ "$( git log > /dev/null ; echo $? )" -eq 128 ] ; then
echo ":: Creating initial commit"
git commit --allow-empty --quiet -m "Initial commit"
fi
fi
echo ":: DONE"