ALT Linux Community general discussions
 help / color / mirror / Atom feed
From: "Денис Смирнов" <mithraen@freesource.info>
To: community@lists.altlinux.org
Subject: Re: [Comm] автомонтирование без DE
Date: Fri, 1 Aug 2014 06:43:38 +0400
Message-ID: <20140801024338.GA17027@mw.mithraen.ru> (raw)
In-Reply-To: <994901406854049@web16j.yandex.ru>


[-- Attachment #1.1: Type: text/plain, Size: 772 bytes --]

On Fri, Aug 01, 2014 at 04:47:29AM +0400, Speccyfighter wrote:

> Выходит так, что оптический привод для отображения
> должен быть хоть где-нибудь указан,
> или в /etc/pmount.allow или в /etc/fstab
> Но здесь это необязательно, и при отсутствии матрицы:

Спасибо! Нашел вторую ошибку. Однако я сумел сделать две детских ошибки в
кусочке кода из 4-х строк :)

В строке 24 замените, пожалуйста:

        $devices{$1} = 1;
на		
        $devices{'/dev/'.$1} = 1;

Исправленное в аттаче.

> ...кстати да, почтовик поменял во вложении концы строк
> с LF на LF+CR (0A 0D). hex-вьювер показал.
> Пришлось конвертером dos2unix по файлу.

Кстати это можно сделать и так:

$ sed -i 's/\r//' <filename>

:)

-- 
С уважением, Денис

http://mithraen.ru/

[-- Attachment #1.2: lmount --]
[-- Type: text/plain, Size: 4280 bytes --]

#!/usr/bin/perl
#============================================================================#
# List all block devices that not exists in fstab                            #
#============================================================================#
# (C) Denis Smirnov <mithraen@freesource.info>                               #
#============================================================================#
use strict;
use warnings qw(FATAL all);
use Cwd 'abs_path';
use Text::Table;

my %devices;

# List all USB devices
foreach ( glob("/dev/disk/by-id/usb-*") ) {
    $devices{ abs_path($_) } = 1;
}

# List all removable devices
{
    my @devs = split( "\n", `/bin/lsblk -d -r -o RM,KNAME` );
    foreach (@devs) {
        next unless /^1\s+(.+)$/;
        $devices{'/dev/'.$1} = 1;
    }
}

# List all devices in /etc/pmount.allow
if ( open my $fh, "<", "/etc/pmount.allow" ) {
    while (<$fh>) {
        s/#.*//;
        s/\s+$//;
        next if $_ eq '';
        $_ = abs_path($_) if -l $_;
        $devices{$_} = 1;
    }
    close $fh;
}

# Parse /etc/fstab
my %disks;
my %fstab_dev;
my %fstab_uuid;
my %fstab_label;

sub parse_fstab($) {
    open( my $fh, "<", $_[0] ) || return;
    my @out;
    while (<$fh>) {
        my %h;
        s/#.*//;
        s/\s+$//;
        next if $_ eq '';

        my ( $dev, $uuid, $label ) = ( '', '', '' );
        if (s/^UUID=([^\s"]+)\s+//) {
            $uuid = $1;
            $h{uuid} = $1;
        }
        elsif (s/^UUID="([^"]+)"\s+//) {
            $uuid = $1;
            $h{uuid} = $1;
        }
        elsif (s/^LABEL=([^\s"]+)\s+//) {
            $label = $1;
            $h{label} = $1;
        }
        elsif (s/^LABEL="((?:[^"]|"")+)"\s+//) {
            $label = $1;
            $label =~ s/""/"/g;
            $h{label} = $1;
        }
        elsif (s/^([^\s"]+)\s+//) {
            $dev = $1;
            $h{dev} = $1;
        }
        else {
            next;
        }
        my @fields = split( /\s+/, $_ );
        $h{mountpoint} = shift(@fields);
        $h{fs}         = shift(@fields);
        my @opts = split( ',', shift(@fields) );
        foreach my $opt (@opts) {
            $h{opts}->{$opt} = 1;
        }

        push @out, \%h;
    }
    close $fh;
    return @out;
}

sub parse_line($) {
    my $fields = $_[0];
    my %h;
    while ( $fields =~ s/^\s*([^"]+)="([^\"]*)"\s*// ) {
        $h{$1} = $2;
    }
    my $dev = $h{KNAME};
    if ( $h{TYPE} eq 'disk' ) {
        $disks{$dev} = \%h;
    }
    if ( $h{TYPE} eq 'part' ) {
        my $basedev = $dev;
        $basedev =~ s/\d+$//;
        foreach my $key ( keys %h ) {
            if ( $h{$key} eq '' ) {
                $h{$key} = $disks{$basedev}->{$key};
            }
        }
    }

   return if $h{FSTYPE} eq '';
    return if $h{FSTYPE} eq 'swap';
    return if $h{FSTYPE} eq 'linux_raid_member';
    return if $h{FSTYPE} eq 'LVM2_member';

    # skip LVM partitions
    #    return if $h{TYPE} eq 'lvm';

    # skip FS in fstab
    return if defined $fstab_label{ $h{LABEL} };
    return if defined $fstab_uuid{ $h{UUID} };
    return if defined $fstab_dev{ "/dev/" . $h{KNAME} };

    return \%h;
}

foreach ( parse_fstab "/etc/fstab" ) {
    if ( defined $_->{opts}->{user} ) {
        if ( defined $_->{dev} ) {
            my $dev = $_->{dev};
            $dev = abs_path($dev) if -l $dev;
            $devices{$dev} = 1;
        }
        next;
    }

    if ( defined $_->{dev} ) {
        my $dev = $_->{dev};
        $dev = abs_path($dev) if -l $dev;
        $fstab_dev{$dev} = 1;
    }
    $fstab_label{ $_->{label} } = 1 if defined $_->{label};
    $fstab_uuid{ $_->{uuid} }   = 1 if defined $_->{uuid};
}

my @out;

# Get all info about removable and USB devices
open( my $fh, "-|", '/bin/lsblk', '-o',
    'NAME,FSTYPE,LABEL,MOUNTPOINT,SIZE,RM,KNAME,MODEL,TYPE,UUID', '-P' );

my $tb =
  Text::Table->new( 'NAME', 'MOUNTPOINT', 'LABEL', 'FSTYPE', "SIZE\n&left",
    'MODEL' );

while (<$fh>) {
    my $h = parse_line($_);
    next unless defined $h;
    next unless defined $devices{ "/dev/" . $h->{KNAME} };
    $tb->add(
        $h->{NAME},   $h->{MOUNTPOINT}, $h->{LABEL},
        $h->{FSTYPE}, $h->{SIZE},       $h->{MODEL}
    );

    my $dev = "/dev/" . $h->{KNAME};
    push @out, $dev;
}

print $tb;

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

  reply	other threads:[~2014-08-01  2:43 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-23 16:50 Денис Смирнов
2014-07-23 20:54 ` Michael Shigorin
2014-07-24  8:35   ` Денис Смирнов
2014-07-24  8:57     ` Michael Shigorin
2014-07-24 12:55       ` Владимир Гусев
2014-07-28 23:36       ` Денис Смирнов
2014-07-29  3:55         ` Eugene Prokopiev
2014-07-29 15:10           ` Денис Смирнов
2014-07-24 18:00 ` Speccyfighter
2014-07-24 19:41   ` Фаизов Алишер
2014-07-24 19:49     ` Speccyfighter
2014-07-24 21:21       ` Mikhail Efremov
2014-07-24 23:09         ` Speccyfighter
2014-07-28 23:41           ` Денис Смирнов
2014-07-29 10:48             ` Speccyfighter
2014-07-29 10:52               ` Speccyfighter
2014-07-29 16:16               ` Денис Смирнов
2014-07-29 18:13                 ` Speccyfighter
2014-07-29 19:20                   ` Денис Смирнов
2014-07-29 19:52                     ` Speccyfighter
2014-07-29 19:59                       ` Speccyfighter
2014-07-30  0:52                       ` Денис Смирнов
2014-07-30  3:26                         ` Speccyfighter
2014-07-30 18:11                           ` Денис Смирнов
2014-07-31  2:00                             ` Speccyfighter
2014-07-31 14:06                               ` Денис Смирнов
2014-07-31 14:39                                 ` Speccyfighter
2014-07-31 16:47                                   ` Денис Смирнов
2014-07-31 17:35                                     ` Speccyfighter
2014-07-31 19:05                                       ` Денис Смирнов
2014-08-01  0:47                                         ` Speccyfighter
2014-08-01  2:43                                           ` Денис Смирнов [this message]
2014-08-01 17:13                                             ` Speccyfighter
2014-08-02 14:09                                               ` Денис Смирнов
2014-08-02 18:51                                                 ` Speccyfighter
2014-08-03  3:58                                                   ` Денис Смирнов
2014-08-03 14:22                                                     ` Speccyfighter
2014-08-03 19:46                                                       ` Денис Смирнов
2014-08-03 22:33                                                         ` Speccyfighter
2014-08-04 13:29                                                           ` Денис Смирнов
2014-08-05 15:15                                                             ` Speccyfighter
2014-08-05 18:43                                                               ` Денис Смирнов
2014-08-06 12:55                                                                 ` Speccyfighter
2014-08-06 21:52                                                                   ` Денис Смирнов
2014-08-07  0:24                                                                     ` Speccyfighter
2014-08-07 15:56                                                                         ` Speccyfighter
2014-08-07 16:14                                                                           ` Speccyfighter
2014-08-07 16:55                                                                             ` Денис Смирнов
2014-08-07 17:07                                                                               ` Speccyfighter
2014-08-08  3:28                                                                                 ` Денис Смирнов
2014-08-09 19:50                                                                                   ` Michael Shigorin
2014-08-15  9:52                                                                                     ` Денис Смирнов
2014-08-15 10:22                                                                                       ` Michael Shigorin
2014-08-15 11:26                                                                                         ` Денис Смирнов
2014-08-04 18:35                                                   ` Michael Shigorin
2014-07-30  4:46                         ` Speccyfighter
2014-07-30  5:31                           ` Speccyfighter
2014-07-30 14:41                           ` Денис Смирнов
2014-07-30 16:39                             ` Speccyfighter
2014-07-29 19:27                   ` Speccyfighter
2014-07-29 19:04                 ` Speccyfighter
2014-07-30  0:10                   ` Денис Смирнов
2014-07-30  9:23                 ` Michael Shigorin
2014-07-30 14:39                   ` Денис Смирнов
2014-07-30  9:38                 ` Sergey
2014-07-30 11:16                   ` Sergey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140801024338.GA17027@mw.mithraen.ru \
    --to=mithraen@freesource.info \
    --cc=community@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git