X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=lava%2Frootfs%2Fvmdeboostrap%2Fgenerate-root.py;h=4023adbd3e4aa87a355ae86f6e1e09449e73c6c9;hb=48c27b896fa98d43513e2bdf47ed3d84b619c7d4;hp=fbc7b849727d48c81b71af8c654e3489c6790819;hpb=888abe0b8ea64c9c0d6cc38c321374352a4bf771;p=lttng-ci.git diff --git a/lava/rootfs/vmdeboostrap/generate-root.py b/lava/rootfs/vmdeboostrap/generate-root.py index fbc7b84..4023adb 100755 --- a/lava/rootfs/vmdeboostrap/generate-root.py +++ b/lava/rootfs/vmdeboostrap/generate-root.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # Copyright (C) 2018 - Jonathan Rajotte-Julien # # This program is free software: you can redistribute it and/or modify @@ -14,17 +14,25 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import subprocess import argparse -from datetime import datetime import gzip +import os import shutil +import subprocess +import sys + +from datetime import datetime def compress(filename): - with open(filename, 'rb') as f_in: - with gzip.open('{}.gz'.format(filename), 'wb') as f_out: - shutil.copyfileobj(f_in, f_out) + command = [ + 'tar', '-c', '-z', + '-f', filename + ".tar.gz", + '-C', filename, + './' + ] + subprocess.run(command, check=True) + shutil.rmtree(filename) packages = [ @@ -32,12 +40,10 @@ packages = [ 'automake', 'bash-completion', 'bison', - 'bsdtar', 'build-essential', 'chrpath', 'clang', 'cloc', - 'cppcheck', 'curl', 'elfutils', 'flex', @@ -45,6 +51,7 @@ packages = [ 'git', 'htop', 'jq', + 'libarchive-tools', 'libdw-dev', 'libelf-dev', 'libffi-dev', @@ -57,14 +64,16 @@ packages = [ 'libtool', 'libxml2', 'libxml2-dev', + 'netcat-traditional', + 'openssh-server', 'psmisc', - 'python-virtualenv', + 'python3-virtualenv', 'python3', - 'python3-setuptools', 'python3-dev', 'python3-numpy', 'python3-pandas', 'python3-pip', + 'python3-setuptools', 'python3-sphinx', 'stress', 'swig', @@ -79,13 +88,13 @@ packages = [ def main(): parser = argparse.ArgumentParser(description='Generate lava lttng rootfs') parser.add_argument("--arch", default='amd64') - parser.add_argument("--distribution", default='bionic') + parser.add_argument("--distribution", default='jammy') parser.add_argument("--mirror", default='http://archive.ubuntu.com/ubuntu') parser.add_argument( "--component", default='universe,multiverse,main,restricted') args = parser.parse_args() - name = "rootfs_{}_{}_{}.tar".format(args.arch, args.distribution, + name = "rootfs_{}_{}_{}".format(args.arch, args.distribution, datetime.now().strftime("%Y-%m-%d")) hostname = "linaro-server" @@ -93,26 +102,48 @@ def main(): root_password = "root" print(name) command = [ - "sudo", - "vmdebootstrap", + "debootstrap", "--arch={}".format(args.arch), - "--distribution={}".format(args.distribution), - "--mirror={}".format(args.mirror), - "--debootstrapopts=components={}".format(args.component), - "--tarball={}".format(name), - "--package={}".format(",".join(packages)), - "--hostname={}".format(hostname), - "--user={}".format(user), - "--root-password={}".format(root_password), - "--no-kernel", - "--enable-dhcp", + "--components={}".format(args.component), "--verbose", + args.distribution, # SUITE + name, # TARGET (directory is created) + args.mirror, # MIRROR ] + completed_command = subprocess.run(command, check=True) + # packages + command = [ + 'chroot', name, + 'apt-get', 'install', '-y', ] + packages completed_command = subprocess.run(command, check=True) + # hostname + with open(os.path.join(name, 'etc', 'hostname'), 'w', encoding='utf-8') as f: + f.write(hostname + "\n") + + # user + command = [ + 'chroot', name, + 'adduser', '--gecos', '', '--disabled-password', 'linaro', + ] + completed_process = subprocess.run(command, check=True) + + command = [ + 'chroot', name, 'chpasswd', + ] + process = subprocess.Popen(command, stdin=subprocess.PIPE, text=True) + process.communicate(input='linaro:linaro') + + # root password + process = subprocess.Popen(command, stdin=subprocess.PIPE, text=True) + process.communicate(input="root:root") + compress(name) if __name__ == "__main__": + if os.getuid() != 0: + print("This script should be run as root: this is required by deboostrap", file=sys.stderr) + sys.exit(1) main()