-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_iso.perl
174 lines (141 loc) · 5.83 KB
/
gen_iso.perl
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/perl
use strict;
use warnings;
sub update_iso_directory {
my ($directory_path) = @_;
chdir($directory_path);
system('git', 'checkout', '.');
system('git', 'pull');
}
sub run_docker_container {
system('docker', 'run', '-itd', '--privileged', '--name', 'bio', 'bioarchlinux/bioarchlinux', '/bin/bash');
}
sub system_setup {
system('docker', 'exec', '-i', 'bio', 'sh', '-c', 'ln -sf /usr/share/zoneinfo/GMT /etc/localtime');
system('docker', 'exec', '-i', 'bio', 'sh', '-c', 'pacman -Syu --noconfirm');
system('docker', 'exec', '-i', 'bio', 'sh', '-c', 'pacman -S archiso rsync --noconfirm');
}
sub transfer_docker {
my ($path) = @_;
system('docker', 'cp', $path, 'bio:/root/');
}
sub prepare_files {
my ($src_path) = @_;
# Download bio mirrorlist file
system('docker', 'exec', '-i', 'bio', 'sh', '-c', "cd /root/bio/airootfs/etc/pacman.d && curl -L -o mirrorlist.bio https://raw.githubusercontent.com/BioArchLinux/mirror/main/mirrorlist.bio");
# Download mirrorlist file
system('curl', '-L', '-o', $src_path . 'mirrorlist' , 'https://gitlab.archlinux.org/archlinux/packaging/packages/pacman-mirrorlist/-/raw/main/mirrorlist');
# Uncomment Worldwide mirrors
my @mirrorlist_lines = ();
open(my $fh, '<', $src_path . 'mirrorlist') or die "Can't open mirrorlist file: $!";
while (my $line = <$fh>) {
if ($line =~ /^## Worldwide/) {
push @mirrorlist_lines, $line;
push @mirrorlist_lines, <$fh>, <$fh>, <$fh>;
} else {
push @mirrorlist_lines, $line;
}
}
close($fh);
open($fh, '>', $src_path . '/mirrorlist') or die "Can't write mirrorlist file: $!";
print $fh @mirrorlist_lines;
close($fh);
# transfer mirrorlist
system('docker', 'cp', $src_path . '/mirrorlist' , "bio:/root/bio/airootfs/etc/pacman.d/");
# clean mirrorlist
system('rm', $src_path . '/mirrorlist');
# Download keyring files
system('docker', 'exec', '-i', 'bio', 'sh', '-c', "cd /root/bio/airootfs/usr/share/pacman/keyrings && curl -L -o bioarchlinux-trusted https://raw.githubusercontent.com/BioArchLinux/keyring/main/bioarchlinux-trusted");
system('docker', 'exec', '-i', 'bio', 'sh', '-c', "cd /root/bio/airootfs/usr/share/pacman/keyrings && curl -L -o bioarchlinux.gpg https://raw.githubusercontent.com/BioArchLinux/keyring/main/bioarchlinux.gpg");
# Copy pacman.conf file
system('docker', 'exec', '-i', 'bio', 'sh', '-c', "cp ${src_path}/bio/pacman.conf ${src_path}/bio/airootfs/etc/");
}
sub copy_template_files {
my ($src, $dst) = @_;
system('docker', 'exec', '-i', 'bio', 'sh', '-c', "rsync -a --links --ignore-existing $src/ $dst/");
}
sub use_mkarchiso {
my ($subdir, $iso_name, $dest_dir) = @_;
my $iso_filename = "${iso_name}-" . `date "+%Y.%m.%d"` . "-x86_64.iso";
$iso_filename =~ s/[^\x20-\x7E]//g;
chomp($iso_filename);
system('docker', 'exec', '-i', 'bio', 'sh', '-c', "cd /root/$subdir && mkarchiso -C pacman.conf -v .");
system('docker', 'cp', "bio:/root/" . ${subdir} . "/out/". ${iso_filename}, $dest_dir);
}
sub use_mkarchiso_bt {
my ($subdir, $iso_name, $dest_dir) = @_;
my $iso_filename = "${iso_name}-bootstrap-" . `date "+%Y.%m.%d"` . "-x86_64.tar.gz";
$iso_filename =~ s/[^\x20-\x7E]//g;
chomp($iso_filename);
system('docker', 'exec', '-i', 'bio', 'sh', '-c', "cd /root/$subdir && mkarchiso -C pacman.conf -m bootstrap -v .");
system('docker', 'cp', "bio:/root/" . ${subdir} . "/out/". ${iso_filename}, $dest_dir);
}
sub gpg_sign {
my ($file_path) = @_;
$file_path =~ s/[^\x20-\x7E]//g;
chomp($file_path);
system('gpg', '--output', $file_path . '.sig', '--detach-sig', $file_path);
}
sub sum_sign {
my ($file_path) = @_;
$file_path =~ s/[^\x20-\x7E]//g;
chomp($file_path);
my @sum_commands = qw(b2sum cksum md5sum sha1sum sha224sum sha256sum sha384sum sha512sum sum);
foreach my $cmd (@sum_commands) {
my $sum_file = "$file_path.$cmd";
system("$cmd $file_path > \"$sum_file\"");
}
}
sub clean_system {
system('docker', 'stop', 'bio');
system('docker', 'rm', 'bio');
system('docker', 'rmi', '--force', 'bioarchlinux/bioarchlinux');
}
sub remove_files {
my ($directory_path) = @_;
unlink glob $directory_path . '/*';
}
sub move_files {
my ($src_path, $dst_path) = @_;
my @file_types = qw(b2sum cksum md5sum sha1sum sha224sum sha256sum sha384sum sha512sum sum sig iso tar.gz);
foreach my $type (@file_types) {
my @files = glob("$src_path/*.$type");
foreach my $file (@files) {
system('mv', $file, $dst_path);
}
}
}
### Main Function ###
my $abpath = '/usr/share/lilac/iso';
my $cdpath = '/usr/share/lilac/Repo/iso';
# Update
update_iso_directory( $abpath );
# Run
run_docker_container();
# System
system_setup();
# transfer
transfer_docker( $abpath . '/bio' );
transfer_docker( $abpath . '/bio-wayfire' );
# Call prepare_files function before copying templates
prepare_files( $abpath );
# Copy template files
copy_template_files( '/root/bio', '/root/bio-wayfire');
# Use mkarchiso
use_mkarchiso('bio', 'bioarchlinux', $abpath);
use_mkarchiso('bio-wayfire', 'bioarchlinux-wayfire', $abpath);
#use_mkarchiso_bt('bio', 'bioarchlinux', $abpath);
# GPG Sign
gpg_sign( $abpath . '/bioarchlinux-' . `date "+%Y.%m.%d"` . '-x86_64.iso');
gpg_sign( $abpath . '/bioarchlinux-wayfire-' . `date "+%Y.%m.%d"` . '-x86_64.iso');
#gpg_sign( $abpath . '/bioarchlinux-bootstrap-' . `date "+%Y.%m.%d"` . '-x86_64.tar.gz');
# Sum sign
sum_sign( $abpath . '/bioarchlinux-' . `date "+%Y.%m.%d"` . '-x86_64.iso');
sum_sign( $abpath . '/bioarchlinux-wayfire-' . `date "+%Y.%m.%d"` . '-x86_64.iso');
#sum_sign( $abpath . '/bioarchlinux-bootstrap-' . `date "+%Y.%m.%d"` . '-x86_64.tar.gz');
# Clean system
clean_system();
# Remove
remove_files( $cdpath );
# Move
move_files( $abpath, $cdpath );