-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_build.sh
More file actions
executable file
·176 lines (153 loc) · 4.97 KB
/
_build.sh
File metadata and controls
executable file
·176 lines (153 loc) · 4.97 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/bash
set -e
# Variables
dlurl="https://github.com/HL7/fhir-ig-publisher/releases/latest/download/publisher.jar"
publisher_jar="publisher.jar"
input_cache_path="$(pwd)/input-cache/"
skipPrompts=false
upper_path="../"
scriptdlroot="https://raw.githubusercontent.com/HL7/ig-publisher-scripts/main"
build_bat_url="${scriptdlroot}/_build.bat"
build_sh_url="${scriptdlroot}/_build.sh"
function check_jar_location() {
if [ -f "${input_cache_path}${publisher_jar}" ]; then
jar_location="${input_cache_path}${publisher_jar}"
echo "Found publisher.jar in input-cache"
elif [ -f "${upper_path}${publisher_jar}" ]; then
jar_location="${upper_path}${publisher_jar}"
echo "Found publisher.jar in parent folder"
else
jar_location="not_found"
echo "publisher.jar not found in input-cache or parent folder"
fi
}
function check_internet_connection() {
if ping -c 1 tx.fhir.org &>/dev/null; then
online=true
echo "We're online and tx.fhir.org is available."
latest_version=$(curl -s https://api.github.com/repos/HL7/fhir-ig-publisher/releases/latest | grep tag_name | cut -d'"' -f4)
else
online=false
echo "We're offline or tx.fhir.org is unavailable."
fi
}
function update_publisher() {
echo "Publisher jar location: ${input_cache_path}${publisher_jar}"
read -p "Download or update publisher.jar? (Y/N): " confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
echo "Downloading latest publisher.jar (~200 MB)..."
mkdir -p "$input_cache_path"
curl -L "$dlurl" -o "${input_cache_path}${publisher_jar}"
else
echo "Skipped downloading publisher.jar"
fi
update_scripts_prompt
}
function update_scripts_prompt() {
read -p "Update scripts (_build.bat and _build.sh)? (Y/N): " update_confirm
if [[ "$update_confirm" =~ ^[Yy]$ ]]; then
echo "Updating scripts..."
curl -L "$build_bat_url" -o "_build.new.bat" && mv "_build.new.bat" "_build.bat"
curl -L "$build_sh_url" -o "_build.new.sh" && mv "_build.new.sh" "_build.sh"
chmod +x _build.sh
echo "Scripts updated."
else
echo "Skipped updating scripts."
fi
}
function build_ig() {
if [ "$jar_location" != "not_found" ]; then
args=()
if [ "$online" = "false" ]; then
args+=("-tx" "n/a")
fi
java -Dfile.encoding=UTF-8 -jar "$jar_location" -ig . "${args[@]}" "$@"
else
echo "publisher.jar not found. Please run update."
fi
}
function build_nosushi() {
if [ "$jar_location" != "not_found" ]; then
java -Dfile.encoding=UTF-8 -jar "$jar_location" -ig . -no-sushi "$@"
else
echo "publisher.jar not found. Please run update."
fi
}
function build_notx() {
if [ "$jar_location" != "not_found" ]; then
java -Dfile.encoding=UTF-8 -jar "$jar_location" -ig . -tx n/a "$@"
else
echo "publisher.jar not found. Please run update."
fi
}
function jekyll_build() {
echo "Running Jekyll build..."
jekyll build -s temp/pages -d output
}
function cleanup() {
echo "Cleaning up temp directories..."
if [ -f "${input_cache_path}${publisher_jar}" ]; then
mv "${input_cache_path}${publisher_jar}" ./
rm -rf "${input_cache_path}"*
mkdir -p "$input_cache_path"
mv "$publisher_jar" "$input_cache_path"
fi
rm -rf ./output ./template ./temp
echo "Cleanup complete."
}
check_jar_location
check_internet_connection
# Handle command-line argument or menu
case "$1" in
update) update_publisher ;;
build) build_ig ;;
nosushi) build_nosushi ;;
notx) build_notx ;;
jekyll) jekyll_build ;;
clean) cleanup ;;
exit) exit 0 ;;
*)
# Compute default choice
default_choice=2 # Build by default
if [ "$jar_location" = "not_found" ]; then
default_choice=1 # Download if jar is missing
elif [ "$online" = "false" ]; then
default_choice=4 # Offline build
elif [ -n "$latest_version" ]; then
current_version=$(java -jar "$jar_location" -v 2>/dev/null | tr -d '\r')
if [ "$current_version" != "$latest_version" ]; then
default_choice=1 # Offer update if newer version exists
fi
fi
echo "---------------------------------------------"
echo "Publisher: ${current_version:-unknown}; Latest: ${latest_version:-unknown}"
echo "Publisher location: $jar_location"
echo "Online: $online"
echo "---------------------------------------------"
echo
echo "Please select an option:"
echo "1) Download or update publisher"
echo "2) Build IG"
echo "3) Build IG without Sushi"
echo "4) Build IG without TX server"
echo "5) Jekyll build"
echo "6) Cleanup temp directories"
echo "0) Exit"
echo
# Read with timeout, but default if nothing entered
echo -n "Choose an option [default: $default_choice]: "
read -t 5 choice || choice="$default_choice"
choice="${choice:-$default_choice}"
echo "You selected: $choice"
case "$choice" in
1) update_publisher ;;
2) build_ig ;;
3) build_nosushi ;;
4) build_notx ;;
5) jekyll_build ;;
6) cleanup ;;
0) exit 0 ;;
*) echo "Invalid option." ;;
esac
;;
esac