Merge branch 'tizen_2.2'
[adaptation/ap_samsung/system-plugin-slp.git] / mount-generator.pl
1 #!/usr/bin/perl -w
2 #
3 # Generate systemd mount units based on information from fstab file.
4 #
5 # Copyright (C) 2012 Samsung Electronics
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # version 2 as published by the Free Software Foundation.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 #
20 # Author: Ćukasz Stelmach <l.stelmach@samsung.com>
21 #
22 use strict;
23 use Cwd 'abs_path';
24
25 my $out_dir = pop @ARGV;
26 my ($fs_dev, $fs_dir, $fs_type, $fs_opts, $fs_dump, $fs_pass);
27
28 sub name_from_path($) {
29         my $dev=shift;
30         $dev =~ s:/+:-:g;
31
32         if ($dev=~m/^-$/) {
33                 return $dev;
34         }
35
36         $dev =~ s/^-|-$//g;
37         return $dev;
38 }
39
40 while(<>) {
41         chomp;
42         ($fs_dev, $fs_dir, $fs_type, $fs_opts, $fs_dump, $fs_pass)=split;
43         next unless ($fs_dev=~m/mmcblk/);
44         next unless ($fs_type=~m/ext[234]/);
45
46         my $fs_tab=abs_path $ARGV;
47         my $unit_name=$out_dir ."/". name_from_path($fs_dir) . ".mount";
48         my $devname=name_from_path $fs_dev;
49         my ($after,$req,$wants);
50         if ($fs_dir eq "/") {
51             $after = "fsck-root.service resize2fs-root.service";
52             $req = "fsck-root.service";
53             $wants = "resize2fs-root.service";
54         } else {
55             $after = "fsck\@$devname.service resize2fs\@$devname.service";
56             $req = "fsck\@$devname.service";
57             $wants = "resize2fs\@$devname.service";
58         }
59
60         my $unit=<<EOF;
61 # Automaticall generated by mount-generator.pl
62
63 [Unit]
64 # FIXME: Is this required?
65 #SourcePath=$fs_tab
66 DefaultDependencies=no
67 Before=local-fs.target
68 Requires=$req
69 After=local-fs-pre.target $after
70 Wants=$wants
71
72 [Mount]
73 What=$fs_dev
74 Where=$fs_dir
75 Type=$fs_type
76 Options=$fs_opts
77 EOF
78         open (UNIT, ">", $unit_name) || die $!;
79         print UNIT $unit,"\n";
80         close UNIT;
81 }