annotate scripts/create_structure.sh @ 0:a17a4894f4bd draft default tip

Initial commit converting git to mercurial
author Alfred Burgess <aburgess@ucc.asn.au>
date Sun, 14 Apr 2024 19:35:23 +0800
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
1 #!/bin/bash
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
2
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
3 # Script to create the Fam-tree project structure
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
4
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
5 # Set project name
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
6 project_name="fam-tree"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
7 root_dir="."
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
8
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
9 # Set environment variables for your project
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
10 export PROJECT_ENV_VAR1="value1"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
11 export PROJECT_ENV_VAR2="value2"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
12
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
13 # Set logs directory
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
14 logs_directory="$root_dir/logs"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
15
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
16 # Feature Flags
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
17 feature_git=0
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
18 feature_docker=0
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
19
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
20 # Error flag
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
21 error_flag=0
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
22
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
23 # Function to display messages to both console and log file
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
24 log_error() {
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
25 echo "E: $(date +"%Y-%m-%d %H:%M:%S") - $1"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
26 }
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
27 log_message() {
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
28 echo "I: $(date +"%Y-%m-%d %H:%M:%S") - $1"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
29 }
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
30
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
31 # Function to create a directory if it doesn't exist
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
32 create_directory() {
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
33 if [ ! -d "$1" ]; then
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
34 mkdir -p "$1"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
35 if [ $? -ne 0 ]; then
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
36 log_error "Error: Failed to create directory '$1'" >&2
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
37 error_flag=1
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
38 else
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
39 log_message "Created directory: $1"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
40 fi
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
41 else
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
42 log_message "Directory exists. Skipped: $1"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
43 fi
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
44 }
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
45
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
46 # Function to create a file if it doesn't exist
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
47 create_file() {
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
48 if [ ! -f "$1" ]; then
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
49 touch "$1"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
50 if [ $? -ne 0 ]; then
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
51 log_error "Error: Failed to create file '$1'" >&2
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
52 error_flag=1
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
53 else
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
54 log_message "Created file: $1"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
55 fi
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
56 else
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
57 log_message "File exists. Skipped: $1"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
58 fi
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
59 }
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
60
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
61 install_dependency() {
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
62 local dependency="$1"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
63
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
64 if ! command -v "$dependency" &> /dev/null; then
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
65 echo "Installing $dependency..."
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
66 case "$dependency" in
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
67 "docker")
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
68 # Install Docker using the official scrip
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
69 curl -fsSL https://get.docker.com -o get-docker.sh
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
70 sudo sh get-docker.sh
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
71 rm get-docker.sh
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
72 ;;
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
73 *)
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
74 # For other dependencies, use your package manager
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
75 # Add more conditions for different package managers (e.g., apt, yum)
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
76 echo "Please install $dependency manually."
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
77 error_flag=1
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
78 ;;
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
79 esac
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
80 fi
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
81 }
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
82
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
83 check_tool_exists() {
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
84 local tool_name=$1
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
85 command -v "$tool_name" >/dev/null 2>&1
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
86 return $?
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
87 }
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
88
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
89 if check_tool_exists "git"; then
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
90 feature_git=1
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
91 fi
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
92
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
93 if check_tool_exists "docker"; then
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
94 feature_docker=1
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
95 fi
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
96
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
97 # Function to generate GitLab CI configuration
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
98 generate_gitlab_ci() {
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
99 local gitlab_ci_file=".gitlab-ci.yml"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
100 cat <<EOL > "$gitlab_ci_file"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
101 stages:
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
102 - build
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
103 - test
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
104 - deploy
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
105
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
106 variables:
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
107 DOCKER_COMPOSE_VERSION: "1.27.4"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
108
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
109 before_script:
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
110 - docker --version
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
111 - docker-compose --version
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
112
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
113 services:
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
114 - docker:$DOCKER_COMPOSE_VERSION
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
115
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
116 build:
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
117 stage: build
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
118 script:
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
119 - docker-compose build
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
120
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
121 test:
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
122 stage: test
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
123 script:
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
124 - docker-compose run --rm backend /your/test/command
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
125
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
126 deploy:
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
127 stage: deploy
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
128 script:
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
129 - echo "Deploy your application here"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
130 EOL
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
131
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
132 echo "GitLab CI file created: $gitlab_ci_file"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
133 }
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
134
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
135
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
136 # Create logs directory
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
137 create_directory "$logs_directory"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
138
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
139 # Create log file with timestamp
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
140 log_file="$logs_directory/$(date +"%Y%m%d%H%M%S").log"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
141 touch "$log_file"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
142
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
143 # Redirect all subsequent output to the log file
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
144 exec 3>&1 4>&2 1>>"$log_file" 2>&1
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
145
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
146
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
147 # Display welcome message in the log
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
148 log_message "Creating project structure for $project_name"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
149
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
150 # Create backend directory
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
151 create_directory "$root_dir/backend"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
152 create_file "$root_dir/backend/main.go"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
153
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
154 # Create API directory
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
155 create_directory "$root_dir/backend/api"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
156 create_file "$root_dir/backend/api/family-tree.proto"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
157
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
158 # Create database directory
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
159 create_directory "$root_dir/backend/database"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
160 create_directory "$root_dir/backend/database/migrations"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
161
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
162 # Create cmd directory for server configurations
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
163 create_directory "$root_dir/backend/cmd"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
164 create_directory "$root_dir/backend/cmd/server"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
165 create_file "$root_dir/backend/cmd/server/config.yaml"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
166 create_file "$root_dir/backend/cmd/server/start.sh"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
167 create_file "$root_dir/backend/cmd/server/stop.sh"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
168
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
169 # Create frontend directory
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
170 create_directory "$root_dir/frontend"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
171 create_directory "$root_dir/frontend/src"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
172 create_directory "$root_dir/frontend/src/components"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
173 create_directory "$root_dir/frontend/src/services"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
174
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
175 # Create proto directory for shared .proto definitions
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
176 create_directory "$root_dir/proto"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
177 create_file "$root_dir/proto/family-tree.proto"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
178
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
179 # Create nginx directory
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
180 create_directory "$root_dir/nginx"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
181 create_file "$root_dir/nginx/nginx.conf"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
182
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
183 # Create backend directory
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
184 create_directory "$root_dir/backend"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
185 create_file "$root_dir/backend/dockerfile"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
186
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
187 # Create frontend directory
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
188 create_directory "$root_dir/frontend"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
189 create_file "$root_dir/frontend/dockerfile"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
190
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
191 # Create docker-compose.yml for Docker Compose configuration
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
192 create_file "$root_dir/docker-compose.yml"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
193
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
194 # Create scripts directory for setup, start, and stop scripts
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
195 create_directory "$root_dir/scripts"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
196 create_file "$root_dir/scripts/setup.sh"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
197 create_file "$root_dir/scripts/start.sh"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
198 create_file "$root_dir/scripts/stop.sh"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
199
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
200 # Create docs directory for documentation
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
201 create_directory "$root_dir/docs"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
202 create_file "$root_dir/docs/api.md"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
203 create_file "$root_dir/docs/database.md"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
204
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
205 # Create cron directory for automated scheduled actions
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
206 create_directory "$root_dir/cron"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
207 create_file "$root_dir/cron/cronjobs"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
208 create_file "$root_dir/cron/tasks"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
209
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
210 # Create tests directory for automated tests
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
211 create_directory "$root_dir/tests"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
212
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
213 # Create ci-cd directory for GitLab CI/CD configuration
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
214 create_directory "$root_dir/ci-cd"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
215 create_file "$root_dir/ci-cd/gitlab-ci.yml"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
216
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
217 # Create config directory for application settings
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
218 create_directory "$root_dir/config"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
219 create_file "$root_dir/config/config.yaml"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
220
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
221 # Create README.md for project documentation
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
222 create_file "$root_dir/README.md"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
223
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
224 # Create .gitignore for Git ignore file
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
225 create_file "$root_dir/.gitignore"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
226 # Function to create a gitignore file
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
227 create_gitignore() {
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
228 cat <<EOL > .gitignore
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
229 # Ignore logs
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
230 logs/
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
231
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
232 # Ignore compiled binaries
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
233 *.exe
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
234 *.dll
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
235 *.out
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
236
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
237 # Ignore user-specific files
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
238 .idea/
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
239 .vscode/
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
240
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
241 # Ignore system files
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
242 .DS_Store
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
243 Thumbs.db
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
244
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
245 # Ignore node modules
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
246 node_modules/
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
247
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
248 # Ignore compiled TypeScript
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
249 *.js
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
250 *.js.map
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
251
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
252 # Ignore Go binary
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
253 *.go
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
254
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
255 # Ignore Docker artifacts
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
256 dockerfile.*
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
257 docker-compose.yml
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
258
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
259 # Ignore dependencies
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
260 vendor/
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
261
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
262 # Ignore compiled Python files
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
263 *.pyc
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
264 __pycache__/
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
265
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
266 # Ignore compiled Java files
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
267 *.class
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
268
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
269 # Ignore temporary files
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
270 *.tmp
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
271
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
272 # Ignore editor backup files
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
273 *~
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
274 *.swp
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
275 *.swo
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
276 *.swn
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
277 *.swm
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
278 *.swl
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
279
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
280 # Ignore environment variables file
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
281 .env
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
282
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
283 # Ignore build artifacts
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
284 build/
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
285 dist/
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
286
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
287 # Ignore database migrations
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
288 database/migrations/*.sql
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
289 EOL
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
290 }
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
291
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
292 initialize_git_repository() {
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
293 if [ "$feature_git" -ne 0 ]; then
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
294 if [ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1;
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
295 then
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
296 log_message "Git repo already enabled"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
297 else
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
298 git init --initial-branch=main
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
299 if [ $? -ne 0 ]; then
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
300 log_error "Error: Failed to initialize Git repository" >&2
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
301 error_flag=1
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
302 else
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
303 git add -A
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
304 git commit -m "Initial commit for project: $project_name"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
305 fi
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
306 fi
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
307 else
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
308 log_message "Git not enabled"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
309 fi
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
310 }
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
311
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
312 # Function to create a pre-commit hook
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
313 create_pre_commit_hook() {
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
314 if [ "$feature_git" -ne 0 ]; then
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
315 local pre_commit_hook=".git/hooks/pre-commit"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
316 local hook_script="#!/bin/bash\n\n# This script runs before every commit to perform linting, formatting, or other checks\n# Add your checks or commands here\n\n# Example: Run a linter\n# lint_command=\"your-linter-command\"\n# \$lint_command\n\n# Example: Run a formatter\n# format_command=\"your-formatter-command\"\n# \$format_command\n\n# If any command fails, the commit will be aborted\n"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
317
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
318 create_file "$pre_commit_hook"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
319 echo "$hook_script" > "$pre_commit_hook"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
320 chmod +x "$pre_commit_hook"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
321 fi
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
322 }
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
323
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
324 # Check for errors
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
325 if [ "$error_flag" -eq 1 ]; then
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
326 echo "Error: One or more errors occurred during script execution. See the log for details." >&2
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
327 exit 1
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
328 fi
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
329
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
330 # Function to create README with a basic structure
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
331 create_readme() {
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
332 local readme_file="README.md"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
333 local readme_content="# $project_name\nThis is a basic README file for the project."
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
334 create_file "$readme_file"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
335 echo "$readme_content" > "$readme_file"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
336 }
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
337
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
338 dependencies=("git" "docker")
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
339 for dep in "${dependencies[@]}"; do
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
340 echo "$dep"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
341 done
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
342
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
343 # Create gitignore file
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
344 create_gitignore
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
345 initialize_git_repository
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
346 create_readme
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
347 generate_gitlab_ci
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
348
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
349 # Display success message in the log
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
350 echo "Gitignore file created successfully"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
351
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
352 # Display success message in the log
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
353 log_message "Project structure for $project_name created successfully"
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
354
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
355 # Restore default output and close the log file
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
356 exec 1>&3 2>&4
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
357 exec 3>&- 4>&-
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
358
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
359 # Display log file path
a17a4894f4bd Initial commit converting git to mercurial
Alfred Burgess <aburgess@ucc.asn.au>
parents:
diff changeset
360 echo "Log file created at: $log_file"