-
Notifications
You must be signed in to change notification settings - Fork 0
/
installOIS.sh
149 lines (127 loc) · 4.22 KB
/
installOIS.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
#!/bin/bash
# Initialize default values
DEPLOYER_TAG="master"
CORE_TAG=""
# Function to display usage information
usage() {
echo "Usage: $0 [-d <deployer_tag>] [-c <core_tag>] [-h]"
echo "Options:"
echo " -d <deployer_tag> Specify the deployer tag (default: master)"
echo " -c <core_tag> Specify the core tag (optional, determined automatically if not specified)"
echo " -h Display this help message"
exit 1
}
# Parse command-line options
while getopts "d:c:h" opt; do
case "$opt" in
d)
DEPLOYER_TAG="$OPTARG"
;;
c)
CORE_TAG="$OPTARG"
;;
h)
usage
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
esac
done
# Determine the operating system
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="mac"
elif [[ "$OSTYPE" == "cygwin" ]]; then
OS="windows"
elif [[ "$OSTYPE" == "msys" ]]; then
OS="windows"
elif [[ "$OSTYPE" == "win32" ]]; then
OS="windows"
else
OS="unknown"
fi
# Function to check if directory exists and is not empty
directory_exists_and_not_empty() {
dir_path=$1
if [ -d "$dir_path" ] && [ -n "$(ls -A "$dir_path")" ]; then
return 0 # Directory doesn't exist or is empty
else
return 1 # Directory exists and is not empty
fi
}
# Function to clone a repository
clone_repository() {
repo_url=$1
tag=$2
repo_name=$(basename "$repo_url" .git)
clone_dir="$base_dir/$repo_name-$tag"
# Check if the directory exists and is not empty
if directory_exists_and_not_empty "$clone_dir"; then
echo "$clone_dir exists and is not empty. Skipping cloning."
else
mkdir -p "$clone_dir"
echo "cloning $repo_url ${tag}."
# Clone the repository with the specified tag or master if not specified
git clone --branch "$tag" "$repo_url" "$clone_dir"
fi
}
publish_repository() {
repo_dir=$1
cd "$repo_dir"
# Publish the repository to Maven Local
echo "publishing $repo_dir to mavenLocal."
if [[ "$OS" == "windows" ]]; then
./gradlew.bat publishToMavenLocal
else
./gradlew publishToMavenLocal
fi
cd ..
}
# Function to clone and publish a repository
clone_and_publish() {
repo_url=$1
tag=$2
# Clone the repository
clone_repository "$repo_url" "$tag"
repo_name=$(basename "$repo_url" .git)
repo_dir="$base_dir/$repo_name"
# Publish the repository
publish_repository "$repo_dir"
}
# Set the base directory for cloning
base_dir="$HOME/.ois"
mkdir -p "$base_dir"
if [ -z "$CORE_TAG" ]; then
# Clone the deployer repository
clone_repository https://github.com/attiasas/open-interactive-simulation-deployer.git $DEPLOYER_TAG
echo "Determine the core tag from deployer build.gradle."
DEPLOYER_DIR="$base_dir/$(basename https://github.com/attiasas/open-interactive-simulation-deployer.git .git)-$DEPLOYER_TAG"
DEPLOYER_BUILD_GRADLE="$DEPLOYER_DIR/build.gradle"
if [ -f "$DEPLOYER_BUILD_GRADLE" ]; then
core_version_line=$(grep "coreVersion" "$DEPLOYER_BUILD_GRADLE")
if [[ "$core_version_line" =~ coreVersion\ *=\ *[\'\"]([0-9]+\.[0-9]+(\.[0-9]+)*(-[a-zA-Z0-9]+)*)[\'\"] ]]; then
CORE_TAG="${BASH_REMATCH[1]}"
echo "Found coreVersion: $CORE_TAG"
# Clone and publish the core repository
clone_and_publish https://github.com/attiasas/open-interactive-simulation-core.git $CORE_TAG
# Publish the deployer repository
publish_repository "$DEPLOYER_DIR"
else
echo "coreVersion not found in $DEPLOYER_BUILD_GRADLE. Exiting."
exit 1
fi
else
echo "$DEPLOYER_BUILD_GRADLE not found. Unable to determine coreVersion. Exiting."
exit 1
fi
else
echo "Installing core library $CORE_TAG and deployer plugin $DEPLOYER_TAG."
# Clone and publish the core repository
clone_and_publish https://github.com/attiasas/open-interactive-simulation-core.git $CORE_TAG
# Clone and publish the deployer repository
clone_and_publish https://github.com/attiasas/open-interactive-simulation-deployer.git $DEPLOYER_TAG
fi
echo "core library $CORE_TAG and deployer plugin $DEPLOYER_TAG installed successfully."