-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·45 lines (37 loc) · 1.37 KB
/
setup.sh
File metadata and controls
executable file
·45 lines (37 loc) · 1.37 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
#!/bin/bash
# Directory of the script
ROOT_DIR="$(realpath $(dirname "${BASH_SOURCE[0]}"))"
TEMPLATE_DIR="$ROOT_DIR/template"
cd ${ROOT_DIR}
source template/_scripts/funcs.sh
debug_var ROOT_DIR
# Set variables to be replaced in the template files
export APP=$(
git remote get-url origin |
sed -E 's#.*/([^/]+)\.git$#\1#; t; s#.*/([^/]+)$#\1#; t; s#.*#app#'
)
export GIT_USERNAME=$(git remote get-url origin | sed -E 's/^(https:\/\/|git@github\.com:)([^\/]+).*$/\2/; t; s/.*/username/')
export GIT_USERNAME=${GIT_USERNAME,,}
export YEAR=$(date +%Y)
export APP_PREFIX=${APP^^//[ -]/_}
check_var APP GIT_USERNAME YEAR
debug_var APP
debug_var GIT_USERNAME
debug_var YEAR
# Rename PROJECT directory to the same name as the app
mv "${TEMPLATE_DIR}/PROJECT" "${TEMPLATE_DIR}/${APP}"
# Copy files recursively and replace variables
while IFS= read -r -d '' file; do
# Determine relative path and destination path
REL_PATH="${file#$TEMPLATE_DIR/}"
DEST_PATH="$ROOT_DIR/$REL_PATH"
# Create destination directory if it doesn't exist
mkdir -p "$(dirname "$DEST_PATH")"
# Replace variables using envsubst and copy the file
envsubst '${APP} ${APP_PREFIX} ${GIT_USERNAME} ${YEAR}' < "$file" > "$DEST_PATH"
echo "Processed: $file -> $DEST_PATH"
done < <(find "$TEMPLATE_DIR" -type f -print0)
echo "Template render complete!"
rm -rf template setup.sh
just test
git add .