f68678d84cc5ab7ff070348456d97d2445a65896
[lttng-ci.git] / lava / rootfs / vmdeboostrap / generate-root.py
1 #!/usr/bin/python3
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
17 import argparse
18 import gzip
19 import os
20 import shutil
21 import subprocess
22 import sys
23
24 from datetime import datetime
25
26
27 def compress(filename):
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)
36
37
38 packages = [
39 'autoconf',
40 'automake',
41 'bash-completion',
42 'bison',
43 'build-essential',
44 'chrpath',
45 'clang',
46 'cloc',
47 'curl',
48 'elfutils',
49 'flex',
50 'gettext',
51 'git',
52 'htop',
53 'jq',
54 'libarchive-tools',
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',
67 'netcat-traditional',
68 'openssh-server',
69 'psmisc',
70 'python3-virtualenv',
71 'python3',
72 'python3-dev',
73 'python3-numpy',
74 'python3-pandas',
75 'python3-pip',
76 'python3-setuptools',
77 'python3-sphinx',
78 'rsync',
79 'stress',
80 'swig',
81 'systemd-timesyncd',
82 'systemtap-sdt-dev',
83 'texinfo',
84 'tree',
85 'uuid-dev',
86 'vim',
87 'wget',
88 ]
89
90
91 def main():
92 parser = argparse.ArgumentParser(description='Generate lava lttng rootfs')
93 parser.add_argument("--arch", default='amd64')
94 parser.add_argument("--distribution", default='bookworm')
95 parser.add_argument("--mirror", default='https://deb.debian.org/debian')
96 parser.add_argument(
97 "--component", default='main')
98 args = parser.parse_args()
99
100 name = "rootfs_{}_{}_{}".format(args.arch, args.distribution,
101 datetime.now().strftime("%Y-%m-%d"))
102
103 hostname = "linaro-server"
104 user = "linaro/linaro"
105 root_password = "root"
106 print(name)
107 command = [
108 "debootstrap",
109 "--arch={}".format(args.arch),
110 "--components={}".format(args.component),
111 "--verbose",
112 args.distribution, # SUITE
113 name, # TARGET (directory is created)
114 args.mirror, # MIRROR
115 ]
116 completed_command = subprocess.run(command, check=True)
117
118 # packages
119 command = [
120 'chroot', name,
121 'apt-get', 'install', '-y', ] + packages
122 completed_command = subprocess.run(command, check=True)
123
124 # hostname
125 with open(os.path.join(name, 'etc', 'hostname'), 'w', encoding='utf-8') as f:
126 f.write(hostname + "\n")
127
128 # user
129 command = [
130 'chroot', name,
131 'adduser', '--gecos', '', '--disabled-password', 'linaro',
132 ]
133 completed_process = subprocess.run(command, check=True)
134
135 command = [
136 'chroot', name, 'chpasswd',
137 ]
138 process = subprocess.Popen(command, stdin=subprocess.PIPE, text=True)
139 process.communicate(input='linaro:linaro')
140
141 # root password
142 process = subprocess.Popen(command, stdin=subprocess.PIPE, text=True)
143 process.communicate(input="root:root")
144
145 compress(name)
146
147
148 if __name__ == "__main__":
149 if os.getuid() != 0:
150 print("This script should be run as root: this is required by deboostrap", file=sys.stderr)
151 sys.exit(1)
152 main()
This page took 0.03505 seconds and 3 git commands to generate.