-
Notifications
You must be signed in to change notification settings - Fork 1
/
go.sh
executable file
·154 lines (132 loc) · 4.18 KB
/
go.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
150
151
152
153
154
#!/bin/bash
#
# Open Hospital (www.open-hospital.org)
# Copyright © 2006-2023 Informatici Senza Frontiere (info@informaticisenzafrontiere.org)
#
# Open Hospital is a free and open source software for healthcare data management.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# https://www.gnu.org/licenses/gpl-3.0-standalone.html
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# SET DEBUG mode
# saner programming env: these switches turn some bugs into errors
#set -o errexit -o pipefail -o noclobber -o nounset
######## Open Hospital - Portable Open Hospital Configuration
# OH_PATH is the directory where Portable OpenHospital files are located
# OH_PATH=/usr/local/PortableOpenHospital
OH_SUBDIR="oh-1.14.dev"
OH_REPO="https://github.com/mizzioisf/openhospital-client"
######## Software configuration - change at your own risk :-)
OH_DIR="oh"
######## Define architecture
# name of this shell script
SCRIPT_NAME=$(basename "$0")
SCRIPT_ARGS=$@
#SCRIPT_DIR=$(dirname $(readlink -f $0))
# script to launch
TARGET_SCRIPT=oh.sh
######################## DO NOT EDIT BELOW THIS LINE ########################
######## User input / option parsing
function script_usage {
echo ""
echo " Open Hospital Client - Web start - beta "
echo ""
echo " Usage: $SCRIPT_NAME [-h][-option]"
echo ""
echo " If the script finds an OH installation in the current dir, it launches $TARGET_SCRIPT [-params]"
echo " Otherwise it downloads an OpenHospital dev distribution with all the necessary software libraries"
echo " in a subdirectory (oh-version-x.x) and launches $TARGET_SCRIPT passing the command line options (go.sh -v -> oh-version-x.x/oh.sh -v)"
echo ""
echo " -h show this help"
echo ""
exit 0
}
######## Functions
function get_confirmation {
read -p "(y/n)? " choice
case "$choice" in
y|Y ) echo "yes";;
n|N ) echo "Exiting..."; exit 0;;
* ) echo "Invalid choice. Exiting."; exit 1 ;;
esac
}
function set_path {
# set current dir
CURRENT_DIR=$PWD
# set OH_PATH if not defined
if [ -z ${OH_PATH+x} ]; then
echo "Warning: OH_PATH not found - using current directory"
fi
OH_PATH=$PWD
OH_PATH_ESCAPED=$(echo $OH_PATH | sed -e 's/\//\\\//g')
}
function oh_check_and_go {
if [ ! -f "$OH_PATH/$OH_DIR/bin/OH-gui.jar" ]; then
echo "Warning - OH not found in current dir. Do you want to download it? (120 MB)"
get_confirmation;
read -p "Enter subdirectory for installation (default $OH_SUBDIR) -> " OH_SUBDIR_TMP
if [ -z $OH_SUBDIR_TMP ]; then
echo "Using $OH_SUBDIR"
else
OH_SUBDIR=$OH_SUBDIR_TMP
fi
# Downloading oh
echo "Downloading Open Hospital..."
if [ ! -d $OH_PATH/$OH_SUBDIR ]; then
git clone $OH_REPO $OH_SUBDIR
fi
# set new OH_PATH
OH_PATH=$OH_PATH/$OH_SUBDIR/
export OH_PATH;
cd $OH_PATH
echo "Pulling updates..."
git pull;
echo "Download completed!"
fi
if [ -x "$OH_PATH/$TARGET_SCRIPT" ]; then
echo "$TARGET_SCRIPT found!"
echo "Do you want to start OH?"
get_confirmation;
echo "Starting $OH_PATH/$TARGET_SCRIPT.."
$OH_PATH/$TARGET_SCRIPT $SCRIPT_ARGS
exit 0;
fi
echo "OH installation not working. Exiting."
exit 1;
}
# list of arguments expected in user the input
OPTIND=1 # Reset in case getopts has been used previously in the shell.
OPTSTRING=":ht:"
# function to parse input
while getopts ${OPTSTRING} opt; do
case ${opt} in
h) # help
script_usage;
;;
esac
done
######################## Script start ########################
# check user
if [ $(id -u) -eq 0 ]; then
echo "Error - do not run this script as root. Exiting."
exit 1
fi
######## Environment setup
set_path;
# start script
oh_check_and_go;
# go back to starting directory
cd $CURRENT_DIR