Skip to content

Commit afc16f6

Browse files
author
Jeff Frontz
committed
Ensure backwards compatibility
1 parent 3d3d473 commit afc16f6

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

bin/gbuild

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ def build_one_configuration(suite, arch, build_desc)
4646
ENV["LXC_SUITE"] = suite
4747
end
4848

49+
if ENV["USE_DOCKER"] and build_desc["distro"].eql? "centos"
50+
ontarget_root_extra = "-w /root"
51+
else
52+
ontarget_root_extra = ""
53+
end
54+
4955
suitearch = "#{suite}-#{arch}"
5056

5157
info "Stopping target if it is up"
@@ -73,7 +79,7 @@ def build_one_configuration(suite, arch, build_desc)
7379

7480
system! "on-target true"
7581

76-
system! "on-target -u root tee -a /etc/sudoers.d/#{ENV['DISTRO'] || 'ubuntu'} > /dev/null << EOF
82+
system! "on-target -u root #{ontarget_root_extra} tee -a /etc/sudoers.d/#{ENV['DISTRO'] || 'ubuntu'} > /dev/null << EOF
7783
%#{ENV['DISTRO'] || 'ubuntu'} ALL=(ALL) NOPASSWD: ALL
7884
EOF" if build_desc["sudo"] and @options[:allow_sudo]
7985

@@ -98,54 +104,54 @@ EOF" if build_desc["sudo"] and @options[:allow_sudo]
98104
if build_desc["multiarch"]
99105
info "Adding multiarch support (log in var/install.log)"
100106
for a in build_desc["multiarch"]
101-
system! "on-target -u root dpkg --add-architecture #{a} >> var/install.log 2>&1"
107+
system! "on-target -u root #{ontarget_root_extra} dpkg --add-architecture #{a} >> var/install.log 2>&1"
102108
end
103109
end
104110

105111
case build_desc["distro"]
106112
when "centos"
107113
info "Updating yum repository (log in var/install.log)"
108-
system! "on-target -u root -w /root yum -y makecache fast >> var/install.log 2>&1"
114+
system! "on-target -u root #{ontarget_root_extra} yum -y makecache fast >> var/install.log 2>&1"
109115
else
110116
info "Updating apt-get repository (log in var/install.log)"
111-
system! "on-target -u root apt-get update >> var/install.log 2>&1"
117+
system! "on-target -u root #{ontarget_root_extra} apt-get update >> var/install.log 2>&1"
112118
end
113119

114120
info "Installing additional packages (log in var/install.log)"
115121

116122
case build_desc["distro"]
117123
when "centos"
118-
system! "on-target -u root -w /root yum -y install #{build_desc["packages"].join(" ")} > var/install.log 2>&1"
124+
system! "on-target -u root #{ontarget_root_extra} yum -y install #{build_desc["packages"].join(" ")} > var/install.log 2>&1"
119125
else
120-
system! "on-target -u root -e DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -y install #{build_desc["packages"].join(" ")} >> var/install.log 2>&1"
126+
system! "on-target -u root #{ontarget_root_extra} -e DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -y install #{build_desc["packages"].join(" ")} >> var/install.log 2>&1"
121127
end
122128

123129
if build_desc["alternatives"]
124130
info "Set alternatives (log in var/install.log)"
125131
for a in build_desc["alternatives"]
126-
system! "on-target -u root update-alternatives --set #{a["package"]} #{a["path"]} >> var/install.log 2>&1"
132+
system! "on-target -u root #{ontarget_root_extra} update-alternatives --set #{a["package"]} #{a["path"]} >> var/install.log 2>&1"
127133
end
128134
end
129135

130-
if @options[:upgrade] || system("on-target -u root '[ ! -e /var/cache/gitian/initial-upgrade ]'")
136+
if @options[:upgrade] || system("on-target -u root #{ontarget_root_extra} '[ ! -e /var/cache/gitian/initial-upgrade ]'")
131137
info "Upgrading system, may take a while (log in var/install.log)"
132138
case build_desc["distro"]
133139
when "centos"
134-
system! "on-target -u root -w /root mkdir -p /var/cache/gitian"
135-
system! "on-target -u root -w /root yum -y update > var/upgrade.log 2>&1"
140+
system! "on-target -u root #{ontarget_root_extra} mkdir -p /var/cache/gitian"
141+
system! "on-target -u root #{ontarget_root_extra} yum -y update > var/upgrade.log 2>&1"
136142
system! "copy-to-target #{@quiet_flag} var/upgrade.log /var/cache/gitian/upgrade.log"
137-
system! "on-target -u root -w /root touch /var/cache/gitian/initial-upgrade"
143+
system! "on-target -u root #{ontarget_root_extra} touch /var/cache/gitian/initial-upgrade"
138144
else
139-
system! "on-target -u root bash < target-bin/upgrade-system.sh >> var/install.log 2>&1"
145+
system! "on-target -u root #{ontarget_root_extra} bash < target-bin/upgrade-system.sh >> var/install.log 2>&1"
140146
end
141147
end
142148
info "Creating package manifest"
143149

144150
case build_desc["distro"]
145151
when "centos"
146-
system! "on-target -u root -w /root yumdb get checksum_data | awk '/checksum_data =/ { print $3, package; next } { package=$1 }' | sort --key 2 > var/base-#{suitearch}.manifest"
152+
system! "on-target -u root #{ontarget_root_extra} yumdb get checksum_data | awk '/checksum_data =/ { print $3, package; next } { package=$1 }' | sort --key 2 > var/base-#{suitearch}.manifest"
147153
else
148-
system! "on-target -u root bash < target-bin/grab-packages.sh > var/base-#{suitearch}.manifest"
154+
system! "on-target -u root #{ontarget_root_extra} bash < target-bin/grab-packages.sh > var/base-#{suitearch}.manifest"
149155
end
150156

151157
info "Creating build script (var/build-script)"

libexec/on-target

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ if [ $# != 0 ] ; then
3131
shift 2
3232
;;
3333
--workdir|-w)
34-
# newer docker version is strict about non-default-user working dir
35-
if docker exec -u root -w /root gitian-target true > /dev/null 2>&1
36-
then
37-
TWORKDIR="-w $2"
34+
if [ -n "$USE_DOCKER" ]; then
35+
if docker exec -u root -w /root gitian-target true > /dev/null 2>&1; then
36+
# newer docker version is strict about non-default-user working dir
37+
TWORKDIR="-w $2"
38+
fi
39+
shift 2
40+
else
41+
echo "unrecognized option $1"
42+
exit 1
3843
fi
39-
shift 2
4044
;;
4145
--*)
4246
echo "unrecognized option $1"

0 commit comments

Comments
 (0)