forked from tegonal/oss-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·101 lines (89 loc) · 3.74 KB
/
init.sh
File metadata and controls
executable file
·101 lines (89 loc) · 3.74 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
#!/usr/bin/env bash
#
# __ __
# / /____ ___ ____ ___ ___ _/ / This file is provided to you by https://github.com/tegonal/oss-template
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2024 Tegonal Genossenschaft
# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Creative Commons Zero v1.0 Universal
# /___/ Please report bugs and contribute back your improvements
#
# Version: v0.1.0-SNAPSHOT
###################################
set -euo pipefail
shopt -s inherit_errexit
unset CDPATH
projectDir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)"
readonly projectDir
if ! [[ -v dir_of_tegonal_scripts ]]; then
dir_of_tegonal_scripts="$projectDir/lib/tegonal-scripts/src"
source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
fi
sourceOnce "$dir_of_tegonal_scripts/utility/log.sh"
printf "Please choose your license:\n(1) EUPL 1.2\n(2) AGPL 3\n(3) Apache 2.0\n(4) CC0 1.0 Universal\nYour selection (default (1) EUPL 1.2): "
read -r choice
if [[ -z "$choice" ]]; then
choice=1
fi
if [[ choice -eq 1 ]]; then
licenseUrl="https://joinup.ec.europa.eu/collection/eupl/eupl-text-11-12"
licenseShortName="EUPL 1.2"
licenseFullName="European Union Public Licence v. 1.2"
cp "$projectDir/EUPL.LICENSE.txt" "$projectDir/LICENSE.txt"
elif [[ choice -eq 2 ]]; then
licenseUrl="https://www.gnu.org/licenses/agpl-3.0.en.html"
licenseShortName="AGPL 3"
licenseFullName="GNU Affero General Public License v3"
cp "$projectDir/AGPL.LICENSE.txt" "$projectDir/LICENSE.txt"
elif [[ choice -eq 3 ]]; then
licenseUrl="https://www.apache.org/licenses/LICENSE-2.0"
licenseShortName="Apache 2.0"
licenseFullName="Apache License, Version 2.0"
cp "$projectDir/Apache.LICENSE.txt" "$projectDir/LICENSE.txt"
elif [[ choice -eq 4 ]]; then
licenseUrl="https://creativecommons.org/publicdomain/zero/1.0/"
licenseShortName="CC0 1.0"
licenseFullName="Creative Commons Zero v1.0 Universal"
cp "$projectDir/CC0.LICENSE.txt" "$projectDir/LICENSE.txt"
else
die "the selection %s is invalid, chose one between 1 and 4" "$choice"
fi
printf "Please insert the project name: "
read -r projectName
tmpName="${projectName//-/_}"
projectNameUpper="${tmpName^^}"
printf "Please insert the github name (default %s): " "$projectName"
read -r projectNameGithub
licenseBadge="[]($licenseUrl \"License\")"
licenseLink="[$licenseFullName]($licenseUrl)"
find "$projectDir" -type f \
-not -path "$projectDir/.gt/**/lib/**" \
-not -path "$projectDir/lib/**" \
-not -name "init.sh" \
-not -name "cleanup.yml" \
-not -name "gt-update.yml" \
-not -name "CODE_OF_CONDUCT.md" \
\( -name "*.md" -o -name "*.yaml" -o -name "*.yml" -o -name "*.sh" \) \
-print0 |
while read -r -d $'\0' file; do
PROJECT_NAME_UPPER="${projectNameUpper}" \
PROJECT_NAME="$projectName" \
PROJECT_NAME_GITHUB="$projectNameGithub" \
LICENSE_BADGE="$licenseBadge" \
LICENSE_LINK="$licenseLink" \
LICENSE_FULLNAME="$licenseFullName" \
YEAR=$(date +%Y) \
perl -0777 -i \
-pe "s@PROJECT_NAME_GITHUB@\$ENV{PROJECT_NAME_GITHUB}@g;" \
-pe "s@PROJECT_NAME_UPPER@\$ENV{PROJECT_NAME_UPPER}@g;" \
-pe "s@PROJECT_NAME@\$ENV{PROJECT_NAME}@g;" \
-pe "s@LICENSE_BADGE@\$ENV{LICENSE_BADGE}@g;" \
-pe "s@LICENSE_LINK@\$ENV{LICENSE_LINK}@g;" \
-pe "s@LICENSE_FULLNAME@\$ENV{LICENSE_FULLNAME}@g;" \
-pe "s@YEAR@\$ENV{YEAR}@g;" \
"$file"
done
find "$projectDir" -maxdepth 1 -name "*.LICENSE.txt" -print0 |
while read -r -d $'\0' license; do
rm "$license"
done
logSuccess "initialised the repository, please follow the remaining steps in README.md"
rm "$projectDir/init.sh"