Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
installsystems
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Seblu
installsystems
Commits
5aba87f6
Commit
5aba87f6
authored
13 years ago
by
Sebastien Luttringer
Browse files
Options
Downloads
Patches
Plain Diff
prepare and unprepare enhancement
* tricks /etc/mtab * new output
parent
3101c6a0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
installsystems/tools.py
+45
-21
45 additions, 21 deletions
installsystems/tools.py
with
45 additions
and
21 deletions
installsystems/tools.py
+
45
−
21
View file @
5aba87f6
...
...
@@ -373,25 +373,39 @@ def prepare_chroot(path, mount=True):
check_call
([
"
mount
"
,
"
--bind
"
,
origin
,
target
],
close_fds
=
True
)
except
CalledProcessError
as
e
:
warn
(
"
Mount failed: %s.
\n
"
%
e
)
arrow
(
"
Cheating
"
)
# check path is a kind of linux FHS
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
path
,
"
etc
"
))
or
not
os
.
path
.
exists
(
os
.
path
.
join
(
path
,
"
usr
"
)):
return
# trick resolv.conf
try
:
if
os
.
path
.
exists
(
"
/etc/resolv.conf
"
)
and
os
.
path
.
exists
(
os
.
path
.
join
(
path
,
"
etc
"
)):
resolv_path
=
os
.
path
.
join
(
path
,
"
etc/resolv.conf
"
)
if
os
.
path
.
exists
(
"
/etc/resolv.conf
"
):
arrow
(
"
resolv.conf
"
,
1
)
resolv_path
=
os
.
path
.
join
(
path
,
"
etc
"
,
"
resolv.conf
"
)
if
os
.
path
.
exists
(
resolv_path
):
os
.
rename
(
resolv_path
,
"
%s.isbackup
"
%
resolv_path
)
shutil
.
copy
(
"
/etc/resolv.conf
"
,
resolv_path
)
except
Exception
as
e
:
warn
(
"
resolv.conf tricks fail: %s
"
%
e
)
# trick mtab
try
:
mtab_path
=
os
.
path
.
join
(
path
,
"
etc
"
,
"
mtab
"
)
arrow
(
"
mtab
"
,
1
)
if
os
.
path
.
exists
(
mtab_path
):
os
.
rename
(
mtab_path
,
"
%s.isbackup
"
%
mtab_path
)
os
.
symlink
(
"
/proc/self/mounts
"
,
mtab_path
)
except
Exception
as
e
:
warn
(
"
mtab tricks fail: %s
"
%
e
)
# try to guest distro
distro
=
guess_distro
(
path
)
# in case of debian disable policy
if
distro
==
"
debian
"
:
arrow
(
"
Creating debian chroot housekeepers
"
)
arrow
(
"
Debian specific
"
,
1
)
# create a chroot header
try
:
open
(
os
.
path
.
join
(
path
,
"
etc
/
debian_chroot
"
),
"
w
"
).
write
(
"
CHROOT
"
)
try
:
open
(
os
.
path
.
join
(
path
,
"
etc
"
,
"
debian_chroot
"
),
"
w
"
).
write
(
"
CHROOT
"
)
except
:
pass
# fake policy-rc.d. It must exit 101, it's an expected exitcode.
policy_path
=
os
.
path
.
join
(
path
,
"
usr
/sbin/
policy-rc.d
"
)
policy_path
=
os
.
path
.
join
(
path
,
"
usr
"
,
"
sbin
"
,
"
policy-rc.d
"
)
try
:
open
(
policy_path
,
"
w
"
).
write
(
"
#!/bin/bash
\n
exit 101
\n
"
)
except
:
pass
# policy-rc.d needs to be executable
...
...
@@ -401,22 +415,32 @@ def unprepare_chroot(path, mount=True):
'''
Rollback preparation of a chroot environment inside a directory
'''
# untrick resolv.conf
if
os
.
path
.
exists
(
"
/etc/resolv.conf
"
)
and
os
.
path
.
exists
(
os
.
path
.
join
(
path
,
"
etc
"
))::
resolv_path
=
os
.
path
.
join
(
path
,
"
etc/resolv.conf
"
)
if
os
.
path
.
exists
(
resolv_path
):
os
.
unlink
(
resolv_path
)
if
os
.
path
.
exists
(
"
%s.isbackup
"
%
resolv_path
):
os
.
rename
(
"
%s.isbackup
"
%
resolv_path
,
resolv_path
)
# try to guest distro
distro
=
guess_distro
(
path
)
# cleaning debian stuff
if
distro
==
"
debian
"
:
arrow
(
"
Removing debian chroot housekeepers
"
)
for
f
in
(
"
etc/debian_chroot
"
,
"
usr/sbin/policy-rc.d
"
):
try
:
os
.
unlink
(
os
.
path
.
join
(
path
,
f
))
except
:
pass
arrow
(
"
Uncheating
"
)
# check path is a kind of linux FHS
if
os
.
path
.
exists
(
os
.
path
.
join
(
path
,
"
etc
"
))
and
os
.
path
.
exists
(
os
.
path
.
join
(
path
,
"
usr
"
)):
# untrick mtab
mtab_path
=
os
.
path
.
join
(
path
,
"
etc
"
,
"
mtab
"
)
arrow
(
"
mtab
"
,
1
)
if
os
.
path
.
exists
(
mtab_path
):
os
.
unlink
(
mtab_path
)
if
os
.
path
.
exists
(
"
%s.isbackup
"
%
mtab_path
):
os
.
rename
(
"
%s.isbackup
"
%
mtab_path
,
mtab_path
)
# untrick resolv.conf
if
os
.
path
.
exists
(
"
/etc/resolv.conf
"
):
arrow
(
"
resolv.conf
"
,
1
)
resolv_path
=
os
.
path
.
join
(
path
,
"
etc
"
,
"
resolv.conf
"
)
if
os
.
path
.
exists
(
resolv_path
):
os
.
unlink
(
resolv_path
)
if
os
.
path
.
exists
(
"
%s.isbackup
"
%
resolv_path
):
os
.
rename
(
"
%s.isbackup
"
%
resolv_path
,
resolv_path
)
# try to guest distro
distro
=
guess_distro
(
path
)
# cleaning debian stuff
if
distro
==
"
debian
"
:
arrow
(
"
Debian specific
"
,
1
)
for
f
in
(
"
etc/debian_chroot
"
,
"
usr/sbin/policy-rc.d
"
):
try
:
os
.
unlink
(
os
.
path
.
join
(
path
,
f
))
except
:
pass
# unmounting
if
mount
:
mps
=
(
"
proc
"
,
"
sys
"
,
"
dev
"
,
"
dev/pts
"
,
"
dev/shm
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment