forked from riag/manjaro-linux-for-wsl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
148 lines (119 loc) · 3.82 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# coding=utf-8
import click
import os
import subprocess
import io
import pybee
from pybee.path import working_dir
current_dir = os.path.abspath(os.getcwd())
script_dir = os.path.abspath(os.path.dirname(__file__))
default_build_dir = os.path.join(script_dir, 'build')
dist_dir = os.path.join(script_dir, 'dist')
work_dir = ''
download_dir = ''
linux_dest_dir = ''
dist_file_name=''
def prepare(arg_work_dir, arch):
global download_dir
global linux_dest_dir
global dist_file_name
global work_dir
work_dir = arg_work_dir
download_dir = os.path.join(work_dir,
arch, 'download'
)
linux_dest_dir = os.path.join(work_dir,
arch, 'wsl-dist', 'root.%s' % arch
)
dist_file_name = 'manjaro-linux-wsl-%s-%s.tar.gz' % (
arch, pybee.get_curr_date_time('%Y-%m-%d')
)
pybee.path.mkdir(download_dir, True)
pybee.path.mkdir(linux_dest_dir, True)
pybee.path.mkdir(dist_dir, False)
pybee.shell.exec(
['chmod', '+x',
'./manjaro-bootstrap/manjaro-bootstrap.sh'
]
)
def make_bootstrap(arch, repo):
cmd_list = [
'./manjaro-bootstrap/manjaro-bootstrap.sh',
'-a', arch,
'-r', repo,
'-d', download_dir,
linux_dest_dir
]
pybee.shell.exec(
cmd_list
)
def append_text_to_file(fpath, text, encoding='utf-8'):
with io.open(fpath, 'a',encoding=encoding) as f:
f.write(text)
def exec_command_in_chroot_env(dest_dir, cmd, **kwargs):
chroot_cmd_list = ['chroot', dest_dir, ]
c = None
if type(cmd) is str:
chroot_cmd_list.append(cmd)
c = ' '.join(chroot_cmd_list)
else:
chroot_cmd_list.extend(cmd)
c = chroot_cmd_list
pybee.shell.exec(c, **kwargs)
def make_wsl_linux_dist():
with working_dir(os.path.join(script_dir, 'configs')):
pybee.path.copyfiles(
['os-release', 'issue'],
os.path.join(linux_dest_dir, 'etc')
)
append_text_to_file(
os.path.join(linux_dest_dir, 'etc', 'locale.gen'),
'\nen_US.UTF-8 UTF-8'
)
exec_command_in_chroot_env(linux_dest_dir, ['locale-gen'])
with working_dir(os.path.join(script_dir, 'configs', 'profile.d')):
pybee.path.copyfiles(
['display.sh', 'wsl.sh'],
os.path.join(linux_dest_dir, 'etc', 'profile.d')
)
'''
pybee.path.save_text_file(
os.path.join(linux_dest_dir, 'etc', 'sudoers'),
'Defaults lecture_file = /etc/sudoers.lecture'
)
pybee.path.save_text_file(
os.path.join(linux_dest_dir, 'etc', 'sudoers.lecture'),
'Enter your UNIX password below. This is not your Windows password.'
)
'''
exec_command_in_chroot_env(
linux_dest_dir, ['pacman', '-Scc' ],
input='yes\nyes\n'.encode('utf-8')
)
def pack():
print('')
print('tar %s .....' % linux_dest_dir)
p = os.path.join(dist_dir, dist_file_name)
if os.path.isfile(p):
os.unlink(p)
cwd_dir = os.path.dirname(linux_dest_dir)
with working_dir(cwd_dir):
cmd = ' '.join(
['tar', '--ignore-failed-read',
'-czvf', p, '*']
)
pybee.shell.exec(
cmd, shell=True
)
print('finish, dist file is %s' % p)
@click.command()
@click.option('-a','--arch', default='x86_64')
@click.option('-r', '--repo', default='https://mirrors.tuna.tsinghua.edu.cn/manjaro')
@click.option('-w', '--work-dir', default=default_build_dir)
def main(arch, repo, work_dir):
prepare(work_dir, arch)
make_bootstrap(arch, repo)
make_wsl_linux_dist()
pack()
if __name__ == '__main__':
main()