#!/usr/bin/perl use warnings; use strict; use Debian::Debhelper::Dh_Lib; use File::Basename; my $alt_var_inst = "debian/n4dvars"; my $path_var_n4d = "/var/lib/n4d/"; my $path_installed_vars = $path_var_n4d."installed_vars/"; my $path_trash_vars = $path_var_n4d."variables-trash/"; my $path_inbox_vars = "var/lib/n4d/variables-inbox/"; my @package_list = getpackages(); if( -f "$alt_var_inst"){ my $first_pkg = $package_list[0]; doit("cp",$alt_var_inst,"debian/$first_pkg.n4dvars"); } my $msg_error = ""; for (my $i = 0 ; $i <= $#package_list ; $i++){ my $pkg = $package_list[$i]; if ( -f "debian/$pkg.lintian-overrides"){ open( FH ,">>debian/$pkg.lintian-overrides"); } else{ open( FH ,">debian/$pkg.lintian-overrides"); } print FH "$pkg: possibly-insecure-handling-of-tmp-files-in-maintainer-script\n"; close(FH); if ( -f "debian/$pkg.n4dvars" ){ doit("mkdir -p debian/$pkg/$path_inbox_vars"); doit("mkdir -p debian/$pkg$path_installed_vars"); open(my $fd,'<',"debian/$pkg.n4dvars"); while(my $line = <$fd>){ $line =~ s/\n*$//; $line =~ s/^\s*(.*?)\s*$/$1/; if( ! -e "$line"){ $msg_error .= " -> Error not exist $line path"; } if( -f "$line" ){ my $varname = basename($line); my $output = `cat $line | python -mjson.tool 2>&1`; if ($? != 0){ chomp($output); $msg_error .= " -> Error on Json: $output on file $line\n"; } doit("cp",$line,"debian/$pkg/$path_inbox_vars/$pkg.n4dvars.$varname"); doit("cp",$line,"debian/$pkg$path_installed_vars$pkg.n4dvars.$varname"); } if( -d "$line" ){ opendir(my $dir,$line); while(my $filename = readdir($dir)){ next if ($filename =~ m/^\./); my $output = `cat "$line/$filename" | python -mjson.tool 2>&1`; if ($? != 0){ chomp($output); $msg_error = " -> Error on Json: $output on file $line/$filename\n"; } doit("cp",$line."/$filename","debian/$pkg/$path_inbox_vars/$pkg.n4dvars.$filename"); doit("cp",$line."/$filename","debian/$pkg$path_installed_vars$pkg.n4dvars.$filename"); } } } install_vars_prerm($package_list[$i]); install_vars_postinst($package_list[$i]); } } if ($msg_error ne ""){ $msg_error = "\n\n**************\n* *\n* JSON ERROR *\n* *\n**************\n$msg_error\n\n"; error($msg_error); } sub install_vars_prerm{ my $pkg = shift; my $cmd = << "END_CMD"; ############################################ # Automatically generated by dn4dh_install # ############################################ case \"\$1\" in remove|purge) if [ -d $path_installed_vars ]; then cp $path_installed_vars$pkg.n4dvars.* $path_trash_vars if [ -e '/tmp/.n4d_pid' ]; then #a=\$(stat -c %i /) AUX_PID=\$(cat /tmp/.n4d_pid) STATUS=\$(ps -p \$AUX_PID -o args= | grep n4d-server || true) if [ "\$STATUS" != "" ]; then n4d-vars emptytrash || true fi fi else echo "" echo "" echo "" echo \'n$pkg package set n4d vars, but someone/something deleted $path_installed_vars.\' echo \'If N4D package isn't installed on your system ignore this message.\' echo \'Otherwise, you can reinstall $pkg and later uninstall.\' echo \'You can also try to look for vars which have been installed; In this case ... good luck!!!!\' echo \'.,__,.........,__,....... ______\' echo \'`·.,¸,.·*¯`·.,¸,.·*¯..|::::::/\:_|/\\\' echo \'`·.,¸,.·*¯`·.,¸,,.·*¯<|::::::( o wo)\' echo \'-.......-""-......--"""u"""""u""""u"' echo "" fi ;; *) ;; esac ################################################ # END Automatically generated by dn4dh_install # ################################################ END_CMD open (FD ,">> debian/$pkg.prerm.debhelper"); print FD $cmd; close(FD); } sub install_vars_postinst{ my $pkg = shift; my $cmd = << "END_CMD"; ############################################ # Automatically generated by dn4dh_install # ############################################ case \"\$1\" in configure) if [ -e '/tmp/.n4d_pid' ]; then #a=\$(stat -c %i /) AUX_PID=\$(cat /tmp/.n4d_pid) STATUS=\$(ps -p \$AUX_PID -o args= | grep n4d-server || true) if [ "\$STATUS" != "" ]; then n4d-vars readinbox || true fi fi ;; *) ;; esac ################################################ # END Automatically generated by dn4dh_install # ################################################ END_CMD open (FD ,">> debian/$pkg.postinst.debhelper"); print FD $cmd; close(FD); } #my $aux = "debian/$pkg.$mant_script.debhelper";