-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathenv.sh
More file actions
116 lines (102 loc) · 2.53 KB
/
env.sh
File metadata and controls
116 lines (102 loc) · 2.53 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
if [ -z "$INSTALLER_ENV_SH" ]; then
INSTALLER_ENV_SH=1
# Terminate on error
set -e
# Referencing an undefined variable is an error
set -u
# Root dir
installer_dir=$(readlink -f $(dirname $BASH_SOURCE))
# Read the config file
if [ -f $installer_dir/config.sh ]; then
. $installer_dir/config.sh
# Check for required variables
varnames=(platform)
for vis in pub priv; do
for x in app mod data; do
varnames+=("${vis}_${x}_dir")
done
done
for varname in ${varnames[@]}; do
if [ -z "${!varname}" ]; then
echo "config.sh does not define required variable $varname"
exit 1
fi
done
# Assign defaults if they've not been provided
make_parallelism=${make_parallelism:-16}
else
echo "config.sh does not exist"
exit 1
fi
# Idempotent version of module use
function mod_use_idem {
local mod_dir
for mod_dir in "$@"; do
if [[ ! "$MODULEPATH" =~ ".*$mod_dir.*" ]]; then
module use $mod_dir
fi
done
}
# Ensure our modules are available
mod_use_idem $pub_mod_dir
mod_use_idem $priv_mod_dir
# Initialise to work on a package
function installer_init {
# Check we have set the required variables in our package env
local varname
for varname in name version visibility; do
if [ -z "${!varname}" ]; then
echo "package env does not define required variable $varname"
exit 1
fi
done
# Read in the platform's configuration
platform_dir=$installer_dir/platforms/$platform
if [ -d $platform_dir ]; then
if [ -f $platform_dir/env.sh ]; then
. $platform_dir/env.sh
fi
else
echo "Platform directory for $platform does not exist"
exit 1
fi
# Setup for world/project readable installation
case $visibility in
pub|public)
app_dir=$pub_app_dir
mod_dir=$pub_mod_dir
data_dir=$pub_data_dir
;;
priv|private)
app_dir=$priv_app_dir
mod_dir=$priv_mod_dir
data_dir=$priv_data_dir
;;
*)
echo "Unknown package visibility: $visibility"
exit 1
;;
esac
# The destination for the package's tree
prefix=$app_dir/$name/$version
# Now read any package-specific config for the platform
package_platform_dir="$platform_dir/$name"
local conf="$package_platform_dir/config.sh"
if [ -d "$package_platform_dir" ]; then
if [ -f "$conf" ]; then
. "$conf"
else
echo "No file $conf"
fi
else
echo "No directory $package_platform_dir"
fi
}
# Make a directory and chmod g+w, if it doesn't exist.
function mkdir_gw {
if [ ! -d $1 ]; then
mkdir $1
chmod g+w $1
fi
}
fi