Commit | Line | Data |
---|---|---|
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 | 17 | import argparse |
888abe0b | 18 | import gzip |
1e206006 | 19 | import os |
888abe0b | 20 | import shutil |
1e206006 | 21 | import subprocess |
7ba728fd | 22 | import sys |
1e206006 JR |
23 | |
24 | from datetime import datetime | |
888abe0b JR |
25 | |
26 | ||
27 | def 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 | ||
38 | packages = [ | |
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', | |
db5b1495 | 67 | 'locales', |
3f1bcc40 JR |
68 | 'netcat-traditional', |
69 | 'openssh-server', | |
888abe0b | 70 | 'psmisc', |
7ba728fd | 71 | 'python3-virtualenv', |
888abe0b | 72 | 'python3', |
888abe0b JR |
73 | 'python3-dev', |
74 | 'python3-numpy', | |
75 | 'python3-pandas', | |
76 | 'python3-pip', | |
3f1bcc40 | 77 | 'python3-setuptools', |
888abe0b | 78 | 'python3-sphinx', |
db5b1495 | 79 | 'python3-venv', |
d0ffdf18 | 80 | 'rsync', |
888abe0b JR |
81 | 'stress', |
82 | 'swig', | |
d0ffdf18 KS |
83 | 'systemd-timesyncd', |
84 | 'systemtap-sdt-dev', | |
888abe0b JR |
85 | 'texinfo', |
86 | 'tree', | |
87 | 'uuid-dev', | |
88 | 'vim', | |
89 | 'wget', | |
90 | ] | |
91 | ||
92 | ||
93 | def main(): | |
94 | parser = argparse.ArgumentParser(description='Generate lava lttng rootfs') | |
95 | parser.add_argument("--arch", default='amd64') | |
d0ffdf18 KS |
96 | parser.add_argument("--distribution", default='bookworm') |
97 | parser.add_argument("--mirror", default='https://deb.debian.org/debian') | |
888abe0b | 98 | parser.add_argument( |
d0ffdf18 | 99 | "--component", default='main') |
888abe0b JR |
100 | args = parser.parse_args() |
101 | ||
7ba728fd | 102 | name = "rootfs_{}_{}_{}".format(args.arch, args.distribution, |
888abe0b JR |
103 | datetime.now().strftime("%Y-%m-%d")) |
104 | ||
105 | hostname = "linaro-server" | |
106 | user = "linaro/linaro" | |
107 | root_password = "root" | |
108 | print(name) | |
109 | command = [ | |
7ba728fd | 110 | "debootstrap", |
888abe0b | 111 | "--arch={}".format(args.arch), |
7ba728fd | 112 | "--components={}".format(args.component), |
888abe0b | 113 | "--verbose", |
7ba728fd KS |
114 | args.distribution, # SUITE |
115 | name, # TARGET (directory is created) | |
116 | args.mirror, # MIRROR | |
888abe0b | 117 | ] |
7ba728fd | 118 | completed_command = subprocess.run(command, check=True) |
888abe0b | 119 | |
7ba728fd KS |
120 | # packages |
121 | command = [ | |
122 | 'chroot', name, | |
123 | 'apt-get', 'install', '-y', ] + packages | |
888abe0b JR |
124 | completed_command = subprocess.run(command, check=True) |
125 | ||
7ba728fd KS |
126 | # hostname |
127 | with open(os.path.join(name, 'etc', 'hostname'), 'w', encoding='utf-8') as f: | |
128 | f.write(hostname + "\n") | |
129 | ||
130 | # user | |
131 | command = [ | |
132 | 'chroot', name, | |
133 | 'adduser', '--gecos', '', '--disabled-password', 'linaro', | |
134 | ] | |
135 | completed_process = subprocess.run(command, check=True) | |
136 | ||
137 | command = [ | |
138 | 'chroot', name, 'chpasswd', | |
139 | ] | |
140 | process = subprocess.Popen(command, stdin=subprocess.PIPE, text=True) | |
141 | process.communicate(input='linaro:linaro') | |
142 | ||
143 | # root password | |
144 | process = subprocess.Popen(command, stdin=subprocess.PIPE, text=True) | |
145 | process.communicate(input="root:root") | |
146 | ||
888abe0b JR |
147 | compress(name) |
148 | ||
149 | ||
150 | if __name__ == "__main__": | |
7ba728fd KS |
151 | if os.getuid() != 0: |
152 | print("This script should be run as root: this is required by deboostrap", file=sys.stderr) | |
153 | sys.exit(1) | |
888abe0b | 154 | main() |