forked from openSUSE/obs-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
obs-docker-support
executable file
·229 lines (220 loc) · 5.1 KB
/
obs-docker-support
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
################################################################
#
# Enable docker build support in container.
#
# Author: Marco Strigl
#
################################################################
#
# Copyright (c) 2017 SUSE Linux Products GmbH
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or 3 as
# published by the Free Software Foundation.
#
# 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 COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################
LOCAL_REPOS_D="/etc/repos_obs_dockersupport.d/"
LOCAL_APTREPOS_D="/etc/aptrepos_obs_dockersupport.d/"
DATA_DIR=
zypper() {
cmd=
# try to find the command
globalopts=()
while test -n "$1"; do
case $1 in
-*)
globalopts[${#globalopts[@]}]="$1"
shift
;;
*)
cmd=$1
shift
break
;;
esac
done
case $cmd in
in|install|rm|remove|up|update|if|info)
exec /usr/bin/zypper -D $LOCAL_REPOS_D "${globalopts[@]}" "$cmd" "$@"
;;
ar|addrepo)
exec /usr/bin/zypper "${globalopts[@]}" "$cmd" -C "$@"
;;
ref|refresh)
echo "skipping zypper refresh"
exit 0
;;
*)
exec /usr/bin/zypper "${globalopts[@]}" "$cmd" "$@"
;;
esac
}
obs_pkg_mgr() {
case "$1" in
install|remove)
shift
exec /usr/bin/zypper -D $LOCAL_REPOS_D --no-gpg-checks -n in "$@"
;;
add_repo)
shift
exec /usr/bin/zypper ar -C "$@"
;;
*)
echo "Usage: obs_pkg_mgr (install|add_repo) args" >&2
exit 1
;;
esac
}
apt_get() {
cmd=
# try to find the command
globalopts=()
while test -n "$1"; do
case $1 in
-*)
globalopts[${#globalopts[@]}]="$1"
shift
;;
*)
cmd=$1
shift
break
;;
esac
done
case $cmd in
update)
exit 0
;;
install|upgrade)
exec /usr/bin/apt-get -o Dir::Etc::SourceList=$LOCAL_APTREPOS_D/obssource -o Dir::Etc::SourceParts=$LOCAL_APTREPOS_D --allow-unauthenticated "${globalopts[@]}" "$cmd" "$@"
;;
*)
exec /usr/bin/apt-get "${globalopts[@]}" "$cmd" "$@"
;;
esac
}
dnf() {
# try to find command
globalopts=()
while test -n "$1"; do
case $1 in
-*)
globalopts[${#globalopts[@]}]="$1"
shift
;;
*)
cmd=$1
shift
break
;;
esac
done
case $cmd in
in|install|up|update)
exec /usr/bin/dnf --setopt=reposdir=$LOCAL_REPOS_D "${globalopts[@]}" "$cmd" "$@"
;;
*)
exec /usr/bin/dnf "${globalopts[@]}" "$cmd" "$@"
;;
esac
}
yum() {
# try to find command
globalopts=()
while test -n "$1"; do
case $1 in
-*)
globalopts[${#globalopts[@]}]="$1"
shift
;;
*)
cmd=$1
shift
break
;;
esac
done
case $cmd in
in|install|up|update)
exec /usr/bin/yum --setopt=reposdir=$LOCAL_REPOS_D "${globalopts[@]}" "$cmd" "$@"
;;
*)
exec /usr/bin/yum "${globalopts[@]}" "$cmd" "$@"
;;
esac
}
obs_docker_support() {
case "$1" in
--install|-i)
data_url=http://localhost:80
test -n "$DATA_DIR" && data_url="file:$DATA_DIR"
test -e /usr/bin/zypper && ln -s obs-docker-support /usr/local/sbin/zypper
test -e /usr/bin/yum && ln -s obs-docker-support /usr/local/sbin/yum
test -e /usr/bin/dnf && ln -s obs-docker-support /usr/local/sbin/dnf
test -e /usr/bin/apt-get && ln -s obs-docker-support /usr/local/sbin/apt-get
ln -s obs-docker-support /usr/local/sbin/obs_pkg_mgr
if test -e /usr/bin/zypper -o -e /usr/bin/yum -o -e /usr/bin/dnf ; then
mkdir -p "$LOCAL_REPOS_D"
cat >$LOCAL_REPOS_D/obs_repository.repo <<EOF
[obs_repository]
name=obs_repository
enabled=1
autorefresh=0
baseurl=$data_url
type=rpm-md
gpgcheck=0
EOF
test -x /usr/bin/zypper && /usr/bin/zypper -D $LOCAL_REPOS_D ref
fi
if test -e /usr/bin/apt-get ; then
mkdir -p "$LOCAL_APTREPOS_D"
echo "deb $data_url ./" > $LOCAL_APTREPOS_D/obssource
test -e /var/lib/apt && mv /var/lib/apt /var/lib/apt.obssave
/usr/bin/apt-get -o Dir::Etc::SourceList=$LOCAL_APTREPOS_D/obssource -o Dir::Etc::SourceParts=$LOCAL_APTREPOS_D update
fi
;;
--uninstall|-u)
rm -rf "$LOCAL_REPOS_D"
rm -rf "$LOCAL_APTREPOS_D"
rm -f /usr/local/sbin/zypper
rm -f /usr/local/sbin/yum
rm -f /usr/local/sbin/dnf
rm -f /usr/local/sbin/apt-get
rm -f /usr/local/sbin/obs_pkg_mgr
if test -e /var/lib/apt.obssave ; then
rm -rf /var/lib/apt
mv /var/lib/apt.obssave /var/lib/apt
fi
rm -f /usr/local/sbin/obs-docker-support
;;
esac
}
case ${0##*/} in
obs-docker-support)
obs_docker_support "$@"
;;
obs_pkg_mgr)
obs_pkg_mgr "$@"
;;
zypper)
zypper "$@"
;;
apt-get)
apt_get "$@"
;;
*)
echo "obs-docker-support: unsupported mode ${0##*/}" >&2
exit 1
esac