-#!/usr/bin/python
+#!/usr/bin/python3
# Copyright (C) 2018 - Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
#
# This program is free software: you can redistribute it and/or modify
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-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 = [
'automake',
'bash-completion',
'bison',
- 'bsdtar',
'build-essential',
'chrpath',
'clang',
'cloc',
- 'cppcheck',
'curl',
'elfutils',
'flex',
'git',
'htop',
'jq',
+ 'libarchive-tools',
'libdw-dev',
'libelf-dev',
'libffi-dev',
'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',
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"
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()