-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstaller
executable file
·209 lines (180 loc) · 4.88 KB
/
installer
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#! /usr/bin/env bash
# __START_OF_LICENSE__
#
# Copyright (c) 2017 Michael D. Adams
# All rights reserved.
#
# This file is part of the Aristotle software.
#
# 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,
# or (at your option) any later version.
#
# 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; see the file LICENSE. If not,
# see <http://www.gnu.org/licenses/>.
#
# __END_OF_LICENSE__
################################################################################
# Bubblewrap: https://github.com/projectatomic/bubblewrap
bwrap_version="v0.11.0"
################################################################################
cmd_dir=$(dirname "$0") || exit 1
panic()
{
echo "ERROR: $@"
exit 1
}
tree_copy()
{
local source_dir="$1"
local destination_dir="$2"
(cd "$source_dir" && tar -cf - .) | \
(cd "$destination_dir" && tar -xf -)
}
tree_adjust_perms()
{
if [ $# -ne 2 ]; then
return 2
fi
local mode="$1"
local dir="$2"
if [ "$mode" = public ]; then
#find "$dir" \( -type f -o -type d \) -exec chmod go=u,g-w,o-w {} \;
find "$dir" \( -type f -o -type d \) -print0 | xargs -n 1 -0 chmod go=u,g-w,o-w
else
#find "$dir" \( -type f -o -type d \) -exec chmod g=,o= {} \;
find "$dir" \( -type f -o -type d \) -print0 | xargs -n 1 -0 chmod g=,o=
fi
}
test_user_namespaces()
{
local max_user_namespaces
if [ -f "/proc/sys/user/max_user_namespaces" ]; then
max_user_namespaces=$(cat /proc/sys/user/max_user_namespaces) || \
return 1
else
max_user_namespaces=0
fi
if [ "$max_user_namespaces" -ne 0 ]; then
echo 1
else
echo 0
fi
}
usage()
{
echo "$@"
cat <<- EOF
Usage
=====
$0 [options] -d \$install_dir
Options
=======
-d \$install_dir
Set the install directory to \$install_dir.
-a \$assignments_dir
Set the default assignment-definition directory to \$assignments_dir.
-c
Remove old files first.
-m \$sandbox_mode
Set the sandbox mode to \$sandbox_mode.
-b \$sandbox_options
Set the extra sandbox options to \$sandbox_options.
Examples
========
$0 -d ${SDE_TOP_DIR-${HOME}/public/sde}/packages/aristotle-current
$0 -d ${SDE_TOP_DIR-${HOME}/public/sde}/packages/aristotle-current -c
$0 -d ${SDE_TOP_DIR-${HOME}/public/sde}/packages/aristotle-current \\
-c -m bwrap -b "-A $HOME/public/sde"
(avoid -c if symlink for assignments might be deleted)
EOF
exit 2
}
clean=0
install_dir=
assignments_dir=
sandbox_mode=
sandbox_option_spec=()
while getopts b:cd:a:m: opt; do
case $opt in
d)
install_dir="$OPTARG";;
a)
assignments_dir="$OPTARG";;
c)
clean=1;;
m)
sandbox_mode="$OPTARG";;
b)
sandbox_option_spec="$OPTARG";;
*)
usage "invalid option";;
esac
done
shift $((OPTIND - 1))
if [ -z "$install_dir" ]; then
usage "no installation directory specified"
fi
abs_install_dir=$(readlink -f "$install_dir") || panic
packages_dir="$abs_install_dir/packages"
bin_dir="$abs_install_dir/bin"
bwrap_dir="$packages_dir/bwrap-$bwrap_version"
ari_config_file="$abs_install_dir/etc/config"
if [ -z "$sandbox_mode" ]; then
has_user_namespaces=$(test_user_namespaces) || panic
if [ "$has_user_namespaces" -ne 0 ]; then
sandbox_mode=bwrap
else
sandbox_mode=unsafe
fi
fi
sandbox_options=($(echo "$sandbox_option_spec")) || panic
umask 022
if [ "$clean" -ne 0 ]; then
if [ -d "$install_dir" ]; then
rm -rf "$install_dir" || panic
if [ -d "$install_dir" ]; then
panic "cannot remove directory $install_dir"
fi
fi
fi
for dir in bin etc packages; do
target_dir="$install_dir/$dir"
if [ ! -d "$target_dir" ]; then
mkdir -p "$target_dir" || panic
fi
done
cat > "$ari_config_file" <<- EOF
sandbox_mode $sandbox_mode
sandbox_options ${sandbox_options[@]}
EOF
[ $? -eq 0 ] || panic "cannot create configuration file"
"$cmd_dir/bin/ari_install_bwrap" -d "$bwrap_dir" -v "$bwrap_version" || panic
rm -f "$packages_dir/bwrap"
rm -f "$bin_dir/bwrap"
ln -s "bwrap-$bwrap_version" "$packages_dir/bwrap" || panic
ln -s "../packages/bwrap/bin/bwrap" "$bin_dir/bwrap" || panic
for dir in bin etc; do
target_dir="$install_dir/$dir"
if [ ! -d "$target_dir" ]; then
panic
fi
tree_copy "$cmd_dir/$dir" "$target_dir" || panic
done
#target_file="$install_dir/etc/default_assignments"
#if [ ! \( -L "$target_file" -o -e "$target_file" \) ]; then
# if [ -z "$assignments_dir" ]; then
# assignments_dir="assignments"
# fi
# ln -s "$assignments_dir" "$target_file" || \
# panic "cannot make symlink $target_file"
#fi
tree_adjust_perms public "$install_dir" || \
panic "cannot set permissions (permissions may be not correct)"