Skip to content

Commit fa98061

Browse files
author
Andrey Ponomarenko
committed
Initial prototype v1.0
1 parent a4ae613 commit fa98061

File tree

7 files changed

+4355
-0
lines changed

7 files changed

+4355
-0
lines changed

INSTALL

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
Copyright (C) 2011-2012 ROSA Laboratory.
3+
All rights reserved.
4+
5+
6+
RELEASE INFORMATION
7+
8+
Project: Package Changes Analyzer (pkgdiff)
9+
Version: 1.0
10+
Date: 2012-01-29
11+
12+
13+
This INSTALL.txt file explains how to install and setup environment
14+
for this tool in your computer.
15+
16+
17+
Content:
18+
19+
1. Requirements for Linux and FreeBSD
20+
2. Configuring and Installing for Linux and FreeBSD
21+
3. Running the Tool
22+
23+
24+
1. REQUIREMENTS FOR LINUX AND FREEBSD
25+
=====================================
26+
27+
1. Perl 5 (5.8-5.14)
28+
2. GNU Binutils (readelf)
29+
3. GNU Wdiff
30+
4. GNU Awk
31+
32+
33+
1.1 Analysis of RPM packages
34+
35+
RPM (rpm, rpm2cpio)
36+
37+
1.2 Analysis of DEB packages
38+
39+
DPKG (dpkg, dpkg-deb)
40+
41+
1.3 Suggestions
42+
43+
ABI Compliance Checker (>=1.96)
44+
45+
46+
47+
2. CONFIGURING AND INSTALLING FOR LINUX AND FREEBSD
48+
===================================================
49+
50+
This command will install an pkgdiff program in the
51+
PREFIX/bin system directory and private modules into the PREFIX/share:
52+
53+
sudo perl Makefile.pl -install --prefix=PREFIX [/usr, /usr/local, ...]
54+
55+
2.1 Update
56+
57+
sudo perl Makefile.pl -update --prefix=PREFIX
58+
59+
2.2 Remove
60+
61+
sudo perl Makefile.pl -remove --prefix=PREFIX
62+
63+
64+
65+
3. RUNNING THE TOOL
66+
===================
67+
68+
1. pkgdiff -old OLD.rpm -new NEW.rpm
69+
2. For advanced usage, see output of --help option
70+
71+
72+
73+
Enjoy!

LICENSE

+339
Large diffs are not rendered by default.

Makefile.pl

+262
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
#!/usr/bin/perl
2+
###########################################################################
3+
# Makefile for pkgdiff
4+
# Install/remove the tool for GNU/Linux and FreeBSD
5+
#
6+
# Copyright (C) 2011-2012 ROSA Laboratory.
7+
#
8+
# Written by Andrey Ponomarenko
9+
#
10+
# This program is free software: you can redistribute it and/or modify
11+
# it under the terms of the GNU General Public License or the GNU Lesser
12+
# General Public License as published by the Free Software Foundation.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# and the GNU Lesser General Public License along with this program.
21+
# If not, see <http://www.gnu.org/licenses/>.
22+
###########################################################################
23+
use Getopt::Long;
24+
Getopt::Long::Configure ("posix_default", "no_ignore_case");
25+
use File::Path qw(mkpath rmtree);
26+
use File::Copy qw(copy);
27+
use File::Basename qw(dirname);
28+
use Cwd qw(abs_path);
29+
use File::Find;
30+
use Config;
31+
use strict;
32+
33+
my $TOOL_SNAME = "pkgdiff";
34+
my $ARCHIVE_DIR = abs_path(dirname($0));
35+
36+
my $HELP_MSG = "
37+
NAME:
38+
Makefile for pkgdiff
39+
40+
DESCRIPTION:
41+
Install $TOOL_SNAME command and private modules.
42+
43+
USAGE:
44+
sudo perl $0 -install -prefix=/usr
45+
sudo perl $0 -update -prefix=/usr
46+
sudo perl $0 -remove -prefix=/usr
47+
48+
OPTIONS:
49+
-h|-help
50+
Print this help.
51+
52+
--prefix=PREFIX
53+
Install files in PREFIX [/usr/local].
54+
55+
-install
56+
Command to install the tool.
57+
58+
-update
59+
Command to update existing installation.
60+
61+
-remove
62+
Command to remove the tool.
63+
64+
EXTRA OPTIONS:
65+
--destdir=DESTDIR
66+
This option is for maintainers to build
67+
RPM or DEB packages inside the build root.
68+
The environment variable DESTDIR is also
69+
supported.
70+
\n";
71+
72+
if(not @ARGV) {
73+
print $HELP_MSG;
74+
exit(0);
75+
}
76+
77+
my ($PREFIX, $DESTDIR, $Help, $Install, $Update, $Remove);
78+
79+
GetOptions(
80+
"h|help!" => \$Help,
81+
"prefix=s" => \$PREFIX,
82+
"destdir=s" => \$DESTDIR,
83+
"install!" => \$Install,
84+
"update!" => \$Update,
85+
"remove!" => \$Remove
86+
) or exit(1);
87+
88+
sub scenario()
89+
{
90+
if($Help) {
91+
print $HELP_MSG;
92+
exit(0);
93+
}
94+
if(not $Install and not $Update and not $Remove) {
95+
print STDERR "ERROR: command is not selected (-install, -update or -remove)\n";
96+
exit(1);
97+
}
98+
if($PREFIX ne "/") {
99+
$PREFIX=~s/[\/]+\Z//g;
100+
}
101+
if(not $PREFIX)
102+
{ # default prefix
103+
$PREFIX = "/usr/local";
104+
}
105+
if(my $Var = $ENV{"DESTDIR"})
106+
{
107+
print "Using DESTDIR environment variable\n";
108+
$DESTDIR = $Var;
109+
}
110+
if($DESTDIR)
111+
{
112+
if($DESTDIR ne "/") {
113+
$DESTDIR=~s/[\/]+\Z//g;
114+
}
115+
if($DESTDIR!~/\A\//) {
116+
print STDERR "ERROR: destdir is not absolute path\n";
117+
exit(1);
118+
}
119+
if(not -d $DESTDIR) {
120+
print STDERR "ERROR: you should create destdir directory first\n";
121+
exit(1);
122+
}
123+
$PREFIX = $DESTDIR.$PREFIX;
124+
if(not -d $PREFIX) {
125+
print STDERR "ERROR: you should create installation directory first (destdir + prefix):\n mkdir -p $PREFIX\n";
126+
exit(1);
127+
}
128+
}
129+
else
130+
{
131+
if($PREFIX!~/\A\//) {
132+
print STDERR "ERROR: prefix is not absolute path\n";
133+
exit(1);
134+
}
135+
if(not -d $PREFIX) {
136+
print STDERR "ERROR: you should create prefix directory first\n";
137+
exit(1);
138+
}
139+
}
140+
141+
print "INSTALL PREFIX: $PREFIX\n";
142+
143+
# paths
144+
my $EXE_PATH = "$PREFIX/bin";
145+
my $MODULES_PATH = "$PREFIX/share/$TOOL_SNAME";
146+
my $REL_PATH = "../share/$TOOL_SNAME";
147+
148+
if(not -w $PREFIX) {
149+
print STDERR "ERROR: you should be root\n";
150+
exit(1);
151+
}
152+
if($Remove or $Update)
153+
{
154+
# remove executable
155+
print "-- Removing $EXE_PATH/$TOOL_SNAME\n";
156+
unlink($EXE_PATH."/".$TOOL_SNAME);
157+
158+
# remove modules
159+
print "-- Removing $MODULES_PATH\n";
160+
rmtree($MODULES_PATH);
161+
}
162+
if($Install or $Update)
163+
{
164+
if(-e $EXE_PATH."/".$TOOL_SNAME or -e $MODULES_PATH)
165+
{ # check installed
166+
if(not $Remove) {
167+
print STDERR "ERROR: you should remove old version first (`sudo perl $0 -remove --prefix=$PREFIX`)\n";
168+
exit(1);
169+
}
170+
}
171+
172+
# configure
173+
my $Content = readFile($ARCHIVE_DIR."/".$TOOL_SNAME.".pl");
174+
if($DESTDIR) { # relative path
175+
$Content=~s/MODULES_INSTALL_PATH/$REL_PATH/;
176+
}
177+
else { # absolute path
178+
$Content=~s/MODULES_INSTALL_PATH/$MODULES_PATH/;
179+
}
180+
181+
# copy executable
182+
print "-- Installing $EXE_PATH/$TOOL_SNAME\n";
183+
mkpath($EXE_PATH);
184+
writeFile($EXE_PATH."/".$TOOL_SNAME, $Content);
185+
chmod(0755, $EXE_PATH."/".$TOOL_SNAME);
186+
187+
# copy modules
188+
if(-d $ARCHIVE_DIR."/modules")
189+
{
190+
print "-- Installing $MODULES_PATH\n";
191+
mkpath($MODULES_PATH);
192+
copyDir($ARCHIVE_DIR."/modules", $MODULES_PATH);
193+
my $TOOLS_PATH = $MODULES_PATH."/modules/Internals/Tools";
194+
my @Tools = listDir($TOOLS_PATH);
195+
foreach my $Tool (@Tools) {
196+
chmod(0755, $TOOLS_PATH."/".$Tool);
197+
}
198+
199+
}
200+
201+
# check PATH
202+
if($ENV{"PATH"}!~/(\A|:)\Q$EXE_PATH\E(\Z|:)/) {
203+
print "WARNING: your PATH variable doesn't include \'$EXE_PATH\'\n";
204+
}
205+
}
206+
exit(0);
207+
}
208+
209+
sub listDir($)
210+
{
211+
my $Path = $_[0];
212+
return () if(not $Path or not -d $Path);
213+
opendir(my $DH, $Path);
214+
return () if(not $DH);
215+
my @Contents = grep { $_ ne "." && $_ ne ".." } readdir($DH);
216+
return @Contents;
217+
}
218+
219+
sub copyDir($$)
220+
{
221+
my ($From, $To) = @_;
222+
my %Files;
223+
find(\&wanted, $From);
224+
sub wanted {
225+
$Files{$File::Find::dir."/$_"} = 1 if($_ ne ".");
226+
}
227+
foreach my $Path (sort keys(%Files))
228+
{
229+
my $Inst = $Path;
230+
$Inst=~s/\A\Q$ARCHIVE_DIR\E/$To/;
231+
if(-d $Path)
232+
{ # directories
233+
mkpath($Inst);
234+
}
235+
else
236+
{ # files
237+
copy($Path, $Inst);
238+
}
239+
}
240+
}
241+
242+
sub readFile($)
243+
{
244+
my $Path = $_[0];
245+
return "" if(not $Path or not -f $Path);
246+
open(FILE, $Path) || die ("can't open file \'$Path\': $!\n");
247+
local $/ = undef;
248+
my $Content = <FILE>;
249+
close(FILE);
250+
return $Content;
251+
}
252+
253+
sub writeFile($$)
254+
{
255+
my ($Path, $Content) = @_;
256+
return if(not $Path);
257+
open(FILE, ">".$Path) || die ("can't open file \'$Path\': $!\n");
258+
print FILE $Content;
259+
close(FILE);
260+
}
261+
262+
scenario();

0 commit comments

Comments
 (0)