forked from tadzik/panda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rebootstrap.pl
executable file
·52 lines (46 loc) · 1.4 KB
/
rebootstrap.pl
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
#!/usr/bin/env perl6
use v6;
BEGIN {
shell 'git submodule init';
shell 'git submodule update';
}
use lib 'ext/File__Find/lib/';
use lib 'ext/Shell__Command/lib';
use Shell::Command;
# Find old state file
my ($prefix, $state-file);
for grep(*.defined, %*ENV<DESTDIR>, %*CUSTOM_LIB<site home>) {
if "$_/panda/state".path.e {
$prefix = $_;
$state-file = "$_/panda/state";
}
}
if not $state-file.defined {
say "No need to rebootstrap, running normal bootstrap";
shell "$*EXECUTABLE_NAME bootstrap.pl";
exit 0;
}
# Save a copy of the old state file to be written *after* bootstrapping again
my $old-state = slurp $state-file;
# Find modules that were installed by request
# (as opposed to just for dependency resolution)
my @modules;
given open($state-file) {
for .lines() -> $line {
my ($name, $state) = split /\s/, $line;
next if $name eq any(<File::Find Shell::Command JSON::Tiny panda>);
if $state eq 'installed' {
@modules.push: $name;
}
}
.close;
}
# Clean old directories, boostrap a fresh panda,
# and reinstall all manually-installed modules
rm_rf "$prefix/lib";
rm_rf "$prefix/panda";
shell "$*EXECUTABLE_NAME bootstrap.pl";
say "==> Reinstalling @modules[]";
shell "$*EXECUTABLE_NAME bin/panda install @modules[]";
# Save the backup state file back to $prefix/panda/
spurt "$state-file.bak", $old-state if $old-state;