File: postinst

package info (click to toggle)
kernel-package 13.014%2Bnmu1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,804 kB
  • ctags: 603
  • sloc: perl: 2,972; sh: 689; makefile: 204
file content (167 lines) | stat: -rwxr-xr-x 5,490 bytes parent folder | download
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/perl
#                              -*- Mode: Cperl -*-
# debian.postinst ---
# Author           : Manoj Srivastava ( srivasta@pilgrim.umass.edu )
# Created On       : Sat Apr 27 05:42:43 1996
# Created On Node  : melkor.pilgrim.umass.edu
# Last Modified By : Manoj Srivastava
# Last Modified On : Mon Apr 13 14:24:21 2009
# Last Machine Used: anzu.internal.golden-gryphon.com
# Update Count     : 46
# Status           : Unknown, Use with caution!
# HISTORY          :
# Description      :
#
#
#
#  arch-tag: 1c716174-2f0a-476d-a626-a1322e62503a
#

$| = 1;

# Predefined values:
my $version           = "=V";
my $move_image        = '';     # target machine defined
my $kimage            = "=K";   # Should be empty, mostly
my $image_dir         = "=D";   # where the image is located
my $clobber_modules   = '';     # target machine defined
my $postinst_hook     = '';     #Normally we do not
my $postrm_hook       = '';     #Normally we do not
my $preinst_hook      = '';     #Normally we do not
my $prerm_hook        = '';     #Normally we do not
my $ignore_depmod_err = '';     # normally we do not
my $relink_src_link   = 'YES';  # There is no harm in checking the link
my $relink_build_link = 'YES';  # There is no harm in checking the link
my $force_build_link  = '';     # There is no harm in checking the link
my $arch              = "=A";   #  should be same as dpkg --print-architecture
my $kernel_arch       = "=B";
my $package_name       = "=ST-headers-$version";
my $kernel_pkg_version = "=KPV";

# Ignore all invocations uxcept when called on to configure.
exit 0 unless ( $ARGV[0] && $ARGV[0] =~ /configure/ );

#known variables
my $image_dest     = "/";
my $realimageloc   = "/$image_dir/";
my $have_conffile  = "";
my $silent_modules = '';
my $modules_base   = '/lib/modules';
my $CONF_LOC       = '/etc/kernel-img.conf';

# remove multiple leading slashes; make sure there is at least one.
$realimageloc =~ s|^/*|/|o;
$realimageloc =~ s|/+|/|o;

my $header_preinst_hook  = '';
my $header_postinst_hook = '';
my $header_prerm_hook    = '';
my $header_postrm_hook   = '';

chdir '/usr/src' or die "Could not chdir to /usr/src:$!";

if ( -r "$CONF_LOC" && -f "$CONF_LOC" ) {
  if ( open( CONF, "$CONF_LOC" ) ) {
    while (<CONF>) {
      chomp;
      s/\#.*$//g;
      next if /^\s*$/;

      $header_preinst_hook = "$1" if m/^\s*header_preinst_hook\s*=\s*(\S+)/i;
      $header_postinst_hook = "$1"
        if m/^\s*header_postinst_hook\s*=\s*(\S+)/i;
      $header_prerm_hook = "$1" if m/^\s*header_prerm_hook\s*=\s*(\S+)/i;
      $header_postinst_hook = "$1"
        if m/^\s*header_postinst_hook\s*=\s*(\S+)/i;

    } ## end while (<CONF>)
    close CONF;
    $have_conffile = "Yes";
  } ## end if ( open( CONF, "$CONF_LOC"...))
} ## end if ( -r "$CONF_LOC" &&...)

sub exec_script {
  my $type   = shift;
  my $script = shift;
  print STDERR "Running $type hook script $script.\n";
  system("$script $version $realimageloc$kimage-$version")
    && print STDERR "User $type hook script [$script] ";
  if ($?) {
    if ( $? == -1 ) {
      print STDERR "failed to execute: $!\n";
    }
    elsif ( $? & 127 ) {
      printf STDERR "died with signal %d, %s coredump\n",
        ( $? & 127 ), ( $? & 128 ) ? 'with' : 'without';
    }
    else {
      printf STDERR "exited with value %d\n", $? >> 8;
    }
    exit $? >> 8;
  } ## end if ($?)
} ## end sub exec_script

sub run_hook {
  my $type   = shift;
  my $script = shift;
  if ( $script =~ m,^/, ) {

    # Full path provided for the hook script
    if ( -x "$script" ) {
      &exec_script( $type, $script );
    }
    else {
      die "The provided $type hook script [$script] could not be run.\n";
    }
  } ## end if ( $script =~ m,^/, )
  else {
    # Look for it in a safe path
    for my $path ( '/bin', '/sbin', '/usr/bin', '/usr/sbin' ) {
      if ( -x "$path/$script" ) {
        &exec_script( $type, "$path/$script" );
        return 0;
      }
    } ## end for my $path ( '/bin', ...)

    # No luck
    print STDERR "Could not find $type hook script [$script].\n";
    die "Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'\n";
  } ## end else [ if ( $script =~ m,^/, )]
} ## end sub run_hook

# Set up the env variable containing our arguments
my $out;
for (@ARGV) {
  s,','\\'',g;
  $out .= " '$_'";
}
$ENV{'DEB_MAINT_PARAMS'}       = "$out";
$ENV{'KERNEL_PACKAGE_VERSION'} = "$kernel_pkg_version";

## Run user hook script here, if any
if ( -d "/etc/kernel/header_postinst.d" ) {
  print STDERR "Examining /etc/kernel/header_postinst.d.\n";
  system( "run-parts --verbose --exit-on-error --arg=$version "
      . "--arg=$realimageloc$kimage-$version "
      . "/etc/kernel/header_postinst.d" )
    && die "Failed to process /etc/kernel/header_postinst.d";
} ## end if ( -d "/etc/kernel/header_postinst.d")

if ( -d "/etc/kernel/header_postinst.d/$version" ) {
  print STDERR "Examining /etc/kernel/header_postinst.d/$version.\n";
  system( "run-parts --verbose --exit-on-error --arg=$version "
      . "--arg=$realimageloc$kimage-$version "
      . "/etc/kernel/header_postinst.d/$version" )
    && die "Failed to process /etc/kernel/header_postinst.d/$version";
} ## end if ( -d "/etc/kernel/header_postinst.d/$version")

if ( -x "$header_postinst_hook" ) {
  system( "$header_postinst_hook", $package, $version )
    && warn "User hook script $header_postinst_hook failed";

  #&run_hook("postinst", $header_postinst_hook);
} ## end if ( -x "$header_postinst_hook")

exit 0;

__END__