summaryrefslogtreecommitdiff
path: root/scripts/update-grub
blob: 7143f8aa058eed45fd5899d05e36476c3f0f9115 (plain)
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
#!/usr/bin/env perl
use v5.40.0;
use strict;
use warnings;

use Getopt::Long;

use AlgaOS::UpdateGrub;

my $help;
my $recovery  = 1;
my $root      = 1;
my $live      = 0;
my $protect   = 1;
my $user_list = ['admin'];
my $target_device;
my $chroot;
my $new_pass;

Getopt::Long::Configure( "bundling", "no_ignore_case" );
GetOptions(
    'help|h'          => \$help,
    'recovery!'       => \$recovery,
    'root!'           => \$root,
    'live'            => \$live,
    'protect!'        => \$protect,
    'new-pass'        => \$new_pass,
    'user=s@'         => $user_list,
    'target-device=s' => \$target_device,
    'chroot=s'        => \$chroot,
);

if ( $< ne 0 ) {
    die 'Must be root';
    exit -1;
}

if ($help) {
    show_help();
    exit 0;
}

if ( $live && !$chroot ) {
    say STDERR
'--live without --chroot is non sense, do not continue if you do not know what you are doing';
    show_help();
    exit -1;
}

if ( $root && !$protect && $recovery ) {
    say STDERR
'Not having password in grub and having recovery and root makes your data very easily accesible without even using an external device, giving you 10 seconds to think about it, press ctrl+c to interrupt if unsure';
    sleep 10;
}

my $probable_root = `findmnt -n -o SOURCE /`;
if ( !$live && !$target_device && $probable_root =~ /(?:loop|rootfs)/ ) {
    say STDERR
'You are not in the destination install, you need --target-device, also if you do not know what you are doing do not continue';
    show_help();
    exit -1;
}

say $live;
AlgaOS::UpdateGrub->new(
    search_recovery                 => $recovery,
    search_root                     => $root,
    search_live_cd_rootfs           => $live,
    wants_pass_in_sensitive_options => $protect,
    user_list                       => $user_list,
    (
        defined $new_pass ? ( change_to_pass => $new_pass )
        : ()
    ),
    (
        defined $chroot ? ( root_dir => $chroot )
        : ()
    ),
    (
        defined $target_device ? ( target_device => $target_device )
        : ()
    ),
)->run;

sub show_help {
    say STDERR
"IF YOU DO NOT KNOW WHAT YOU ARE DOING DO NOT DIRECTLY RUN THIS COMMAND AND ASK FOR HELP INSTEAD.

update-grub [--help|-h] [--norecovery] [--noroot] [--user foo --user bar] [--live] [--noprotect] [--new-pass <new password for grub sensitive fields>] [--target-device <path to disk>] [--chroot <New root to put grub on>]

--help: Shows this help
--norecovery: Disables creation of grub entry for recovery (Voids your warranty)
--noroot: Disables creation of grub entry for root (Voids your warranty)
--user: Can be specified multiple times to send the list of allowable users to log in grub, \"admin\" will always be among them.
--live: Creates a grub that tries to boot a live system. (Not recommended for final users, voids your warranty)
--new-pass: Changes your grub password, be sure to remember it.
--target-device: Selects the harddisk to use to search for AlgaOS, update-grub will make its best guess if not sent. (Example: /dev/sda)
--noprotect: Disables password in grub dangerous options
--chroot: Writes the grub to other root. (Not covered by warranty, used for livecd)
";
}