forked from Josee9988/project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SETUP_TEMPLATE.sh
executable file
·159 lines (142 loc) · 7.42 KB
/
SETUP_TEMPLATE.sh
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
# SCRIPT: SETUP_TEMPLATE.sh
# USAGE: bash SETUP_TEMPLATE.sh | ./SETUP_TEMPLATE.sh
# PURPOSE: Shell script that setups the @Josee9988/project-template github project template.
# It detects the user's GitHub username, email and project name,
# then it prompts for the type of project that it is. All the data can be manually specified using the
# script optional arguments. For more information please execute the script with the '--help' flag.
# After it will customize all the files with the user's data, and remove some files and folders,
# even this own script.
# TITLE: SETUP_TEMPLATE
# AUTHOR: @Josee9988
# VERSION: See in CHANGELOG.md
# NOTES: This script will auto remove itself, and in case of wanting to run it again, the user must download
# it again or do a 'git stash' and revert the changes.
# BASH_VERSION: 5.1.4(1)-release (x86_64-pc-linux-gnu)
# LICENSE: see in LICENSE (project root) or https://github.com/Josee9988/project-template/blob/master/LICENSE
# GITHUB: https://github.com/Josee9988/
# REPOSITORY: https://github.com/Josee9988/project-template
# ISSUES: https://github.com/Josee9988/project-template/issues
# MAIL: jgracia9988@gmail.com
#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
RED='\033[1;31m' # color red
NAME_AND_PROJECT_UNPARSED=$(git ls-remote --get-url) # READ GITHUB USERNAME AND GITHUB PROJECT NAME
NEW_USERNAME=$(echo "$NAME_AND_PROJECT_UNPARSED" | cut -d':' -f 2 | cut -d'/' -f 1)
PROJECT_NAME=$(echo "$NAME_AND_PROJECT_UNPARSED" | cut -d'/' -f 2 | cut -d'.' -f 1)
NEW_EMAIL=$(git config user.email)
TEMP_TEST_OUTPUT=".ignore.test_output.txt"
PROJECT_TYPE="repository" # default value if not specified
will_omit_verification=false
will_omit_commit=false
will_omit_test=false
SCRIPT_VERSION="1.11.7"
FILE_FUNCTION_HELPERS=bin/FUNCTION_HELPERS.sh
if [ ! -f "$FILE_FUNCTION_HELPERS" ]; then # check if the function helpers file is not found
echo -e "${RED}X Can not find ${FILE_FUNCTION_HELPERS}"
exit 1 # it will exit if the function helpers file is not found
else
# shellcheck source=bin/FUNCTION_HELPERS.sh disable=SC1091
source $FILE_FUNCTION_HELPERS || exit 1 # obtain some global functions and variables, if the file isn't found exit
fi
# PARSE THE ARGUMENTS
for i in "$@"; do
case $i in
-u=* | --user=* | --username=* | --name=*)
NEW_USERNAME="${i#*=}"
shift # past argument=value
;;
-p=* | --project=* | --project-name=* | --project_name=* | --projectName=*)
PROJECT_NAME="${i#*=}"
shift # past argument=value
;;
-e=* | --email=* | --mail=*)
NEW_EMAIL="${i#*=}"
shift # past argument=value
;;
-t=* | --type=* | --project_type=* | --projectType=*)
PROJECT_TYPE="${i#*=}"
shift # past argument=value
;;
-h | --help | --info | --information)
displayHelpTexts
exit 0
shift # past argument=value
;;
-v | --version)
echo -e "${GREEN}$SCRIPT_VERSION${NC}"
exit 0
shift # past argument=value
;;
-o | --omit | --omit-commit-and-confirmation)
echo -e "${BBLUE}X Deprecated:${NC} The arguments '--omit-commit-and-confirmation', '-o' and '--omit' are ${RED}deprecated${NC}. Use '--omit-verification' and/or ' --omit-commit' instead."
will_omit_verification=true
will_omit_commit=true
choice="y"
shift # past argument with no value
;;
--omit-verification)
will_omit_verification=true
choice="y"
shift # past argument with no value
;;
--omit-commit)
will_omit_commit=true
shift # past argument with no value
;;
--omit-test-check | --omit-tests-check | --omit-tests)
will_omit_test=true
shift # past argument with no value
;;
*) # unknown option
echo -e "${RED}X Unknown option:${NC} '${i}', type the flag '${BBLUE}--help${NC}' to view all the options and flags."
;;
esac
done
echo -e "Thanks for using ${GREEN}@Josee9988/project-template${NC}"
echo -e "Read carefully all the documentation before you continue executing this script: ${UPURPLE}https://github.com/Josee9988/project-template${NC}\n"
bash tests/TESTS_RUNNER.sh >/dev/null 2>&1 # PERFORM the TESTS
if [ "$?" -eq 1 ] && [ $will_omit_test = false ]; then # if when running the tests any error was found
rm "$TEMP_TEST_OUTPUT" 2>/dev/null || :
displayTestErrorTexts
exit 1
fi
rm "$TEMP_TEST_OUTPUT" 2>/dev/null || :
if [ "$PROJECT_TYPE" = "repository" ]; then # if the project's type has not been manually specified
read -p "Enter $(echo -e "$BBLUE""what your project is""$NC") (program/extension/API/web/CLI tool/backend/frontend/scrapper/automation tool/etc): " PROJECT_TYPE
fi
if [ $will_omit_verification = false ]; then # if the ignore flag has not been manually specified
read -p "Is this data correct: username \"$(echo -e "$GREEN""$NEW_USERNAME""$NC")\", email: \"$(echo -e "$GREEN""$NEW_EMAIL""$NC")\", project name: \"$(echo -e "$GREEN""$PROJECT_NAME""$NC")\", of type: \"$(echo -e "$GREEN""$PROJECT_TYPE""$NC")\" (y/n)? " choice
fi
# confirm that the data is correct
case "$choice" in
y | Y)
center "Setting everything up for you ;)"
# replace the username and email
find .github/ -type f -name "*" -print0 | xargs -0 sed -i "s/Josee9988/${NEW_USERNAME}/g"
find .github/ -type f -name "*" -print0 | xargs -0 sed -i "s/jgracia9988@gmail.com/${NEW_EMAIL}/g"
find .github/ -type f -name "*" -print0 | xargs -0 sed -i "s/project-template/${PROJECT_NAME}/g"
find .gitignore -type f -name "*" -print0 | xargs -0 sed -i "s/Josee9988\/project-template/${NEW_USERNAME}\/${PROJECT_NAME}/g"
rm LICENSE 2>/dev/null || : # remove the license
rm -r bin/ 2>/dev/null || : # remove the bin folder
rm -r tests/ 2>/dev/null || : # remove the tests folder
rm -r .github/workflows/ 2>/dev/null || : # remove the workflow folder
writeREADME # write the new README.md
writeCHANGELOG # write the basic structure of the CHANGELOG.md
echo -e "# add your own funding links" >.github/FUNDING.yml # remove author's custom funding links
if [ $will_omit_commit = false ]; then # if the ignore option for tests has been specified
git add CHANGELOG.md README.md .gitignore .github SETUP_TEMPLATE.sh LICENSE bin tests # commit the new files
git -c color.status=always status | less -REX # show git status with colours
echo -e "Committing the changes for you :)\n"
git commit -m "Set up '@Josee9988/project-template' template: Personalized files by executing the SETUP_TEMPLATE.sh script.🚀"
echo -e "\nRemember to review every file and customize it as you like.\nYou are ready to start your brand new awesome project🚀🚀." else
fi
# self remove this script
rm -- "$0" 2>/dev/null || :
;;
n | N)
echo -e "\nIf your username, project name or email were NOT right, you can manually change them. Read how to do it with the script's help: ${UPURPLE}bash SETUP_TEMPLATE.sh --help${NC}\n"
;;
*) echo -e "${RED}X Invalid option${NC}" ;;
esac
exit 0