-x was never declared in getopts, so !$opt_x was always true and the block it guards always ran. It now exists and covers both network steps. apt-get update ran after the installs; on an image with empty package lists every install failed. It now runs first. apt-get upgrade had no -y and stopped an unattended run at the prompt. DEBIAN_FRONTEND=noninteractive for the same reason. On 13 the timesyncd.conf was copied but the service never restarted, so it took effect at the next reboot at the earliest - and the ntp package from the install list competed with timesyncd for port 123. ntp is now installed only on the older releases, where the service is called ntpsec since 12. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
133 lines
3.5 KiB
Perl
Executable File
133 lines
3.5 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
use Getopt::Std;getopts('xz');
|
|
|
|
# -x skips everything that talks to the network: apt and the time sync.
|
|
# -z makes zsh root's login shell.
|
|
|
|
$ENV{DEBIAN_FRONTEND}='noninteractive';
|
|
|
|
system("userdel ppb; rm -rf /home/ppb") if (-d "/home/ppb");
|
|
system("userdel mike; rm -rf /home/mike") if (-d "/home/mike");
|
|
|
|
# Before the installs, not after them: on a fresh image the package lists are
|
|
# empty and every install below fails.
|
|
system("/usr/bin/apt-get update") if (!$opt_x);
|
|
|
|
&ai('dnsutils','net-tools','zsh','joe','rsync','curl','fuse','libwww-perl',
|
|
'libterm-readline-perl-perl','libterm-readpassword-perl','libdbd-mysql-perl',
|
|
'libjson-perl','jq','unzip','7zip');
|
|
|
|
if ($opt_z) {
|
|
if (-x "/usr/bin/zsh") {
|
|
system("chsh root -s /usr/bin/zsh");
|
|
}
|
|
}
|
|
|
|
|
|
system("locale-gen C.UTF-8");
|
|
|
|
system("mkdir /db");
|
|
system("mkdir /db/bin");
|
|
system("mkdir /db/backup");
|
|
system("mkdir /db/backup/mysql");
|
|
system("mkdir /db/tmp");
|
|
system("mkdir /db/log");
|
|
system("mkdir /db/lib");
|
|
system("mkdir /db/data");
|
|
system("mkdir /db/etc");
|
|
system("mkdir /db/src");
|
|
system("mkdir /db/upload");
|
|
system("chmod 777 /db/tmp");
|
|
system("chmod 777 /db/log");
|
|
system("chmod 777 /db/upload");
|
|
|
|
system("mkdir -p ~/.joe/colors/");
|
|
system("cp ./files/default.jcf ~/.joe/colors/default.jcf");
|
|
system("cp ./files/joerc4 /root/.joerc");
|
|
system("cp ./files/csh.cshrc /etc");
|
|
system("cp ./files/rc.local.debian /etc/rc.local");
|
|
system("chmod 755 /etc/rc.local");
|
|
system("cp ./files/myuser /db/bin");
|
|
system("cp ./files/mybackup /db/bin");
|
|
system("cp ./files/telemetry /db/bin");
|
|
system("cp ./files/rt /db/bin");
|
|
system("cp ./files/mgsh /db/bin");
|
|
system("cp ./files/locale /etc/default/locale");
|
|
|
|
|
|
system("./loadupd.sh");
|
|
|
|
system("cp ./upd /db/bin");
|
|
|
|
system("./upd https://git.micw.org/mike/dx -i /db/bin");
|
|
|
|
system("cp ./files/zshrc /etc/zsh/zshrc");
|
|
|
|
system("rm /etc/motd; touch /etc/motd");
|
|
|
|
system("mkdir /root/.ssh") if (!-d "/root/.ssh");
|
|
|
|
|
|
&readak("/root/.ssh/authorized_keys");
|
|
&readak("./files/authorized_keys");
|
|
|
|
open(OUT,"> /root/.ssh/authorized_keys");
|
|
for (sort(keys(%K))) {print OUT "$_\n" if (!/^\s*$/);}
|
|
close(OUT);
|
|
|
|
sub readak() {
|
|
my($file)=@_;
|
|
if (-f $file) {open(IN,$file);while(<IN>) {chomp();$K{$_}=$_;}close(IN);}
|
|
}
|
|
|
|
|
|
system("chmod 700 /root/.ssh");
|
|
system("chmod 600 /root/.ssh/authorized_keys");
|
|
|
|
if (!$opt_x) {
|
|
system("/usr/bin/apt-get -y upgrade");
|
|
|
|
if (is_debian_13_or_later()) {
|
|
# timesyncd is what 13 runs; ntpd would only fight it over port 123.
|
|
system("cp ./files/timesyncd.conf /etc/systemd/");
|
|
system("systemctl restart systemd-timesyncd");
|
|
|
|
} else {
|
|
&ai('ntp');
|
|
# Since 12 the package is ntpsec and so is the service name.
|
|
my $svc = (-e "/lib/systemd/system/ntpsec.service"
|
|
|| -e "/usr/lib/systemd/system/ntpsec.service") ? "ntpsec" : "ntp";
|
|
system("service $svc stop");
|
|
system("/usr/sbin/ntpd -gq");
|
|
system("service $svc start");
|
|
}
|
|
}
|
|
|
|
sub ai {
|
|
my @pkgs=@_;
|
|
for (@pkgs) {
|
|
system("/usr/bin/apt-get -y install $_");
|
|
}
|
|
}
|
|
|
|
|
|
sub is_debian_13_or_later {
|
|
return 0 unless -r '/etc/os-release';
|
|
|
|
my %os_release;
|
|
open(my $fh, '<', '/etc/os-release') or return 0;
|
|
while (my $line = <$fh>) {
|
|
chomp $line;
|
|
if ($line =~ /^([A-Z_]+)=(.*)$/) {
|
|
my ($key, $val) = ($1, $2);
|
|
$val =~ s/^"|"$//g;
|
|
$os_release{$key} = $val;
|
|
}
|
|
}
|
|
close($fh);
|
|
|
|
return 0 unless ($os_release{ID} // '') eq 'debian';
|
|
return 0 unless ($os_release{VERSION_ID} // '') =~ /^(\d+)/;
|
|
return $1 >= 13 ? 1 : 0;
|
|
}
|