diff options
author | Martin Whitaker <mageia@martin-whitaker.me.uk> | 2018-01-09 23:17:35 +0000 |
---|---|---|
committer | Martin Whitaker <mageia@martin-whitaker.me.uk> | 2018-01-09 23:17:35 +0000 |
commit | 63555aa270059488b013e6c802cca64a8d6eebdc (patch) | |
tree | 75c481453e459dc2aea279a86eb89ceedfd0ecf1 /lib/MGA/DrakISO/Utils.pm | |
parent | 71146812d733fdc46abe1d77b7d68f9859cdc124 (diff) | |
download | drakiso-63555aa270059488b013e6c802cca64a8d6eebdc.tar drakiso-63555aa270059488b013e6c802cca64a8d6eebdc.tar.gz drakiso-63555aa270059488b013e6c802cca64a8d6eebdc.tar.bz2 drakiso-63555aa270059488b013e6c802cca64a8d6eebdc.tar.xz drakiso-63555aa270059488b013e6c802cca64a8d6eebdc.zip |
draklive: allow installer GUI to be used and run as normal user.
Read all configuration from the main config file and automatically
generate the auto_inst.cfg.pl file. Run the installer GUI in a nested
X server if any items are not specified in the config file. Use sudo
to run any steps that need root privileges, to avoid running the X
server as root.
Diffstat (limited to 'lib/MGA/DrakISO/Utils.pm')
-rw-r--r-- | lib/MGA/DrakISO/Utils.pm | 60 |
1 files changed, 49 insertions, 11 deletions
diff --git a/lib/MGA/DrakISO/Utils.pm b/lib/MGA/DrakISO/Utils.pm index 85a9892..4e85207 100644 --- a/lib/MGA/DrakISO/Utils.pm +++ b/lib/MGA/DrakISO/Utils.pm @@ -34,12 +34,14 @@ use IO::Select; use Exporter; our @ISA = qw(Exporter); -our @EXPORT = qw(directory_usage run_ copy_or_link mount_system_fs umount_all_in_chroot); +our @EXPORT = qw($sudo directory_usage glob__ run_ run_as_root run_in_root copy_or_link mount mount_system_fs umount_all_in_root); + +our $sudo = $> ? 'sudo' : ''; sub directory_usage { my ($dir, $o_apparent) = @_; my $apparent = $o_apparent && "--apparent-size"; - first(split /\s/, `du -s -B 1 $apparent $dir`); + first(split /\s/, `$sudo du -s -B 1 $apparent $dir`); } #- expand only if the pattern contains '*' @@ -61,6 +63,34 @@ sub run_ { run_program::raw($options, @cmd); } +sub run_as_root { + my (@cmd) = @_; + + if (@cmd > 1) { + unshift @cmd, $sudo if $sudo; + } else { + @cmd[0] = join(' ', $sudo, @cmd[0]); + } + print "@cmd\n" if $::verbose > 2; + system(@cmd) == 0; +} + +sub run_in_root { + my ($root, $arch, @cmd) = @_; + + if (@cmd > 1) { + unshift @cmd, ( 'chroot', $root ); + unshift @cmd, ( 'setarch', $arch ) if $arch; + unshift @cmd, $sudo if $sudo; + } else { + @cmd[0] = join(' ', $sudo, if_($arch, 'setarch', $arch), 'chroot', $root, @cmd[0]); + } + print "@cmd\n" if $::verbose > 2; + local %ENV = %ENV; + $ENV{LC_ALL} = 'C'; + system(@cmd) == 0; +} + sub device_allocate_file { my ($device, $size) = @_; run_('dd', "of=$device", 'count=0', 'bs=1', "seek=" . removeXiBSuffix($size)); @@ -93,20 +123,28 @@ sub copy_or_link { or die "ERROR: couldn't link $src_file to $dst_file\n"; } +sub mount { + my ($dst, $src, $o_options) = @_; + mkdir_p($dst); + system(join(' ', 'sudo mount', $o_options, $src, $dst)) == 0 + or die "ERROR: failed to mount $src on $dst\n"; +} + sub mount_system_fs { - my ($build) = @_; - run_('mount', '-t', 'devtmpfs', '/dev', $build->get_system_root . '/dev'); - run_('mount', '-t', 'proc', '/proc', $build->get_system_root . '/proc'); - run_('mount', '-t', 'sysfs', '/sys', $build->get_system_root . '/sys'); + my ($root) = @_; + mount($root . '/dev', '/dev', '--bind -o ro'); + mount($root . '/proc', 'none', '-t proc'); + mount($root . '/sys', 'none', '-t sysfs'); + mount($root . '/run', 'none', '-t tmpfs'); } -sub umount_all_in_chroot { - my ($build) = @_; - my $system_root = Cwd::abs_path($build->get_system_root); - my @mounts = grep { $_ =~ $system_root } split("\n", cat_('/proc/mounts')); +sub umount_all_in_root { + my ($root) = @_; + $root = Cwd::abs_path($root); + my @mounts = grep { $_ =~ $root } split("\n", cat_('/proc/mounts')); foreach (reverse(@mounts)) { my @field = split(' ' , $_); - fs::mount::umount($field[1]); + system(join(' ', 'sudo umount', $field[1])); } } |