From: Neil Bothwick <neil@digimed.co.uk>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] Hoping someone can help explain distcc to me
Date: Sun, 21 Aug 2011 18:42:36 +0100 [thread overview]
Message-ID: <20110821184236.38d3ffe6@digimed.co.uk> (raw)
In-Reply-To: <1522485.Prk91GPbbn@eve>
[-- Attachment #1.1: Type: text/plain, Size: 515 bytes --]
On Sun, 21 Aug 2011 15:53:15 +0200, Joost Roeleveld wrote:
> Is there a way to automate the steps inside the chroot without having
> to have a script inside the chroot?
This is the script I use. You can call it with "ch hostname" or symlink
it to chhostname. That way I can use the same script for multiple
computers. The -w option causes it to enter the chroot, emerge world and
exit.
--
Neil Bothwick
Printer: (n.) a small box attached to a computer and used to start
fires in cold weather.
[-- Attachment #1.2: ch --]
[-- Type: application/octet-stream, Size: 3378 bytes --]
#!/usr/bin/python2.7
# -*- coding: iso-8859-1 -*-
import argparse, os, socket, subprocess, sys
# read arguments
parser = argparse.ArgumentParser(description='Enter chroot build environment for a host')
parser.add_argument('-H', '--host')
parser.add_argument('-k', '--kernel', action='store_true')
parser.add_argument('-c' , '--command')
parser.add_argument('-e', '--exit', action='store_true')
parser.add_argument('-w', '--world', action='store_true')
parser.add_argument('-v', '--verbose', action='store_true')
args = parser.parse_args()
# must be run as root
if os.getuid() != 0:
print '\n%smust be run as root!\n' % os.path.basename(sys.argv[0])
parser.print_help()
sys.exit(1)
# get host from name or command line
if os.path.basename(sys.argv[0]) != 'ch':
args.host = os.path.basename(sys.argv[0])[2:]
if not args.host:
parser.print_help()
sys.exit(1)
if args.verbose:
print 'Creating autorun file'
# create .autorun file if asked
if args.world:
args.command = 'world-update'
args.exit = True
if args.command:
arun = open('/mnt/%s/.autorun' % args.host, 'w')
arun.write('%s\n' % args.command)
if args.exit:
arun.write('exit\n')
arun.close()
else:
try:
os.remove('/mnt/%s/.autorun' % args.host)
except OSError:
pass
if args.verbose:
print 'Pinging host'
# check if host is available for syncing
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(10)
try:
s.connect((args.host, 22))
s.close()
sync_paths = ['etc/portage/', 'var/lib/portage/world', 'var/lib/portage/world_sets', 'usr/local/bin/', 'home/nelz/bin/']
sync_cmd = ['rsync', '--archive', '--delete-before']
if args.verbose:
print 'Syncing host'
sync_cmd.append('--verbose')
if args.kernel:
print 'Syncing kernel sources... be patient'
sync_paths.extend(['usr/src/', 'lib/modules/', 'boot/'])
for path in sync_paths:
if os.path.exists(os.path.join('/mnt/', args.host, path)):
src_dest = ['%s:/%s' % (args.host, path), os.path.join('/mnt/', args.host, path)]
if args.verbose:
print 'syncing', ' to '.join(src_dest)
subprocess.call(sync_cmd + src_dest)
except socket.error:
print args.host, 'not available, syncing skipped'
if args.verbose:
print 'Setting up chroot mounts'
# set up mounts in the chroot
try:
os.mkdir('/var/tmp/%s' % args.host, 1777)
except OSError:
pass
subprocess.call(['mount', '-t', 'proc', 'none', '/mnt/%s/proc' % args.host])
subprocess.call(['mount', '--bind', '/var/tmp/%s' % args.host, '/mnt/%s/var/tmp' % args.host])
for dir in ('dev', 'var/portage', 'mnt/portage'):
subprocess.call(['mount', '--bind', '/%s' % dir, '/mnt/%s/%s' % (args.host, dir)])
subprocess.call(['cp', '-f', '/etc/resolv.conf', '/mnt/%s/etc/' % args.host])
if args.verbose:
print 'Entering chroot'
# enter chroot
if os.path.exists('/mnt/%s/bin/zsh' % args.host):
#subprocess.call(['chroot', '/mnt/%s' % args.host, '/bin/zsh'])
subprocess.call(['su' , '-', '-c', 'chroot /mnt/%s /bin/zsh' % args.host])
else:
#subprocess.call(['chroot', '/mnt/%s' % args.host, '/bin/bash'])
subprocess.call(['su' , '-', '-c', 'chroot /mnt/%s /bin/bash' % args.host])
if args.verbose:
print 'Cleaning up'
# clean up after exiting chroot
try:
os.remove('/mnt/%s/.autorun' % args.host)
except OSError:
pass
for dir in ('var/tmp', 'mnt/portage', 'var/portage', 'proc', 'dev'):
subprocess.call(['umount' , '/mnt/%s/%s' % (args.host, dir)])
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
next prev parent reply other threads:[~2011-08-21 17:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-20 22:56 [gentoo-user] Hoping someone can help explain distcc to me Paul Hartman
2011-08-21 0:35 ` Peter Humphrey
2011-08-21 1:08 ` Paul Hartman
2011-08-21 1:58 ` Peter Humphrey
2011-08-21 2:46 ` Dale
2011-08-21 3:04 ` Matthew Finkel
2011-08-21 9:41 ` Peter Humphrey
2011-08-21 13:53 ` Joost Roeleveld
2011-08-21 16:27 ` Peter Humphrey
2011-08-21 17:42 ` Neil Bothwick [this message]
2011-08-24 11:04 ` Dale
2011-08-21 1:34 ` victor romanchuk
2011-08-21 10:38 ` Alex Schuster
2011-08-21 14:39 ` victor romanchuk
2011-08-22 20:41 ` Alex Schuster
2011-08-22 22:36 ` Bill Longman
2011-08-22 22:41 ` Bill Longman
2011-08-22 19:47 ` [gentoo-user] " Paul Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110821184236.38d3ffe6@digimed.co.uk \
--to=neil@digimed.co.uk \
--cc=gentoo-user@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox