lava: Switch from vmdebootstrap to debootstrap
[lttng-ci.git] / lava / rootfs / vmdeboostrap / generate-root.py
CommitLineData
11d1fd9c 1#!/usr/bin/python3
888abe0b
JR
2# Copyright (C) 2018 - Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
888abe0b 17import argparse
888abe0b 18import gzip
1e206006 19import os
888abe0b 20import shutil
1e206006 21import subprocess
7ba728fd 22import sys
1e206006
JR
23
24from datetime import datetime
888abe0b
JR
25
26
27def compress(filename):
7ba728fd
KS
28 command = [
29 'tar', '-c', '-z',
30 '-f', filename + ".tar.gz",
31 '-C', filename,
32 './'
33 ]
34 subprocess.run(command, check=True)
35 shutil.rmtree(filename)
888abe0b
JR
36
37
38packages = [
39 'autoconf',
40 'automake',
41 'bash-completion',
42 'bison',
888abe0b
JR
43 'build-essential',
44 'chrpath',
45 'clang',
46 'cloc',
888abe0b
JR
47 'curl',
48 'elfutils',
49 'flex',
50 'gettext',
51 'git',
52 'htop',
53 'jq',
7ba728fd 54 'libarchive-tools',
888abe0b
JR
55 'libdw-dev',
56 'libelf-dev',
57 'libffi-dev',
58 'libglib2.0-dev',
59 'libmount-dev',
60 'libnuma-dev',
61 'libpfm4-dev',
62 'libpopt-dev',
63 'libtap-harness-archive-perl',
64 'libtool',
65 'libxml2',
66 'libxml2-dev',
3f1bcc40
JR
67 'netcat-traditional',
68 'openssh-server',
888abe0b 69 'psmisc',
7ba728fd 70 'python3-virtualenv',
888abe0b 71 'python3',
888abe0b
JR
72 'python3-dev',
73 'python3-numpy',
74 'python3-pandas',
75 'python3-pip',
3f1bcc40 76 'python3-setuptools',
888abe0b
JR
77 'python3-sphinx',
78 'stress',
79 'swig',
80 'texinfo',
81 'tree',
82 'uuid-dev',
83 'vim',
84 'wget',
85]
86
87
88def main():
89 parser = argparse.ArgumentParser(description='Generate lava lttng rootfs')
90 parser.add_argument("--arch", default='amd64')
7ba728fd 91 parser.add_argument("--distribution", default='jammy')
888abe0b
JR
92 parser.add_argument("--mirror", default='http://archive.ubuntu.com/ubuntu')
93 parser.add_argument(
94 "--component", default='universe,multiverse,main,restricted')
95 args = parser.parse_args()
96
7ba728fd 97 name = "rootfs_{}_{}_{}".format(args.arch, args.distribution,
888abe0b
JR
98 datetime.now().strftime("%Y-%m-%d"))
99
100 hostname = "linaro-server"
101 user = "linaro/linaro"
102 root_password = "root"
103 print(name)
104 command = [
7ba728fd 105 "debootstrap",
888abe0b 106 "--arch={}".format(args.arch),
7ba728fd 107 "--components={}".format(args.component),
888abe0b 108 "--verbose",
7ba728fd
KS
109 args.distribution, # SUITE
110 name, # TARGET (directory is created)
111 args.mirror, # MIRROR
888abe0b 112 ]
7ba728fd 113 completed_command = subprocess.run(command, check=True)
888abe0b 114
7ba728fd
KS
115 # packages
116 command = [
117 'chroot', name,
118 'apt-get', 'install', '-y', ] + packages
888abe0b
JR
119 completed_command = subprocess.run(command, check=True)
120
7ba728fd
KS
121 # hostname
122 with open(os.path.join(name, 'etc', 'hostname'), 'w', encoding='utf-8') as f:
123 f.write(hostname + "\n")
124
125 # user
126 command = [
127 'chroot', name,
128 'adduser', '--gecos', '', '--disabled-password', 'linaro',
129 ]
130 completed_process = subprocess.run(command, check=True)
131
132 command = [
133 'chroot', name, 'chpasswd',
134 ]
135 process = subprocess.Popen(command, stdin=subprocess.PIPE, text=True)
136 process.communicate(input='linaro:linaro')
137
138 # root password
139 process = subprocess.Popen(command, stdin=subprocess.PIPE, text=True)
140 process.communicate(input="root:root")
141
888abe0b
JR
142 compress(name)
143
144
145if __name__ == "__main__":
7ba728fd
KS
146 if os.getuid() != 0:
147 print("This script should be run as root: this is required by deboostrap", file=sys.stderr)
148 sys.exit(1)
888abe0b 149 main()
This page took 0.030691 seconds and 4 git commands to generate.