From: Eric Andersen Date: Wed, 29 Nov 2000 21:39:02 +0000 (-0000) Subject: Finish commit of rpmunpack and add in scripts for undeb and unrpm X-Git-Tag: 0_48~102 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=4bfb6b7b67ff4238fde52e4019efe2284b9f99ef;p=oweals%2Fbusybox.git Finish commit of rpmunpack and add in scripts for undeb and unrpm --- diff --git a/Changelog b/Changelog index 4f6f619bf..d2c1e7d28 100644 --- a/Changelog +++ b/Changelog @@ -2,7 +2,10 @@ * Fixed uname problem causing the kernel version to be mis-detected (causing problems with poweroff, init, - and other things). + and other things). + * kent robotti -- Renamed unrpm to original rpmunpack, so you can use + an included shell script called unrpm as a front end to it. There's + also a shell script called undeb included for debian packages. -Erik Andersen diff --git a/examples/undeb b/examples/undeb new file mode 100644 index 000000000..fa2bcb34c --- /dev/null +++ b/examples/undeb @@ -0,0 +1,49 @@ +#!/bin/sh +# +usage() { +echo "Usage: undeb -c package.deb " +echo " undeb -l package.deb " +echo " undeb -x package.deb /foo/boo " +exit +} + +deb=$2 + +exist() { +if [ "$deb" = "" ]; then +usage +elif [ ! -s "$deb" ]; then +echo "Can't find $deb!" +exit +fi +} + +if [ "$1" = "" ]; then +usage +elif [ "$1" = "-l" ]; then +exist +type more >/dev/null 2>&1 && pager=more +type less >/dev/null 2>&1 && pager=less +trap "" 13 +(ar -p $deb control.tar.gz | gunzip -c | tar -x -O control ; echo -e "\nPress enter to scroll, q to Quit!\n" ; ar -p $deb data.tar.gz | gunzip -c | tar -t -v 2>/dev/null) | $pager +exit +elif [ "$1" = "-c" ]; then +exist +ar -p $deb control.tar.gz | gunzip -c | tar -x -O control +exit +elif [ "$1" = "-x" ]; then +exist +if [ "$3" = "" ]; then +usage +elif [ ! -d "$3" ]; then +echo "No such directory $3!" +exit +fi +ar -p $deb data.tar.gz | gunzip | (cd $3 ; tar -x -v -f -) || exit +echo +echo "Extracted $deb to $3!" +exit +else +usage +fi diff --git a/examples/unrpm b/examples/unrpm new file mode 100644 index 000000000..2cd1aa9c9 --- /dev/null +++ b/examples/unrpm @@ -0,0 +1,43 @@ +#!/bin/sh +# +usage() { +echo "Usage: unrpm -l package.rpm " +echo " unrpm -x package.rpm /foo/boo " +exit +} + +rpm=$2 + +exist() { +if [ "$rpm" = "" ]; then +usage +elif [ ! -s "$rpm" ]; then +echo "Can't find $rpm!" +exit +fi +} + +if [ "$1" = "" ]; then +usage +elif [ "$1" = "-l" ]; then +exist +type more >/dev/null 2>&1 && pager=more +type less >/dev/null 2>&1 && pager=less +(echo -e "\nPress enter to scroll, q to Quit!\n" ; rpmunpack < $rpm | gunzip -c | cpio -tvf --quiet) | $pager +exit +elif [ "$1" = "-x" ]; then +exist +if [ "$3" = "" ]; then +usage +elif [ ! -d "$3" ]; then +echo "No such directory $3!" +exit +fi +rpmunpack < $rpm | gunzip | (cd $3 ; cpio -idmuv) || exit +echo +echo "Extracted $rpm to $3!" +exit +else +usage +fi diff --git a/rpmunpack.c b/rpmunpack.c new file mode 100644 index 000000000..2178a247d --- /dev/null +++ b/rpmunpack.c @@ -0,0 +1,136 @@ +/* + * rpmunpack for busybox + * + * rpmunpack.c - Utility program to unpack an RPM archive + * + * Gero Kuhlmann 1998 + * + * This program is public domain software; you can do whatever you like + * with this source, including modifying and redistributing it. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + +#include "busybox.h" +#include + +/* + * Some general definitions + */ +#define BUFSIZE 512 +#define RPM_MAGIC "\355\253\356\333" +#define GZ_MAGIC_1 '\037' +#define GZ_MAGIC_2 '\213' + +/* + * Global variables + */ +static char buffer[BUFSIZE]; +static char *progname; +static int infile, outfile; + +/* + * Read a specified number of bytes from input file + */ +static void myread(int num) +{ + int err; + + if ((err = read(infile, buffer, num)) != num) { + if (err < 0) + perror(progname); + else + fprintf(stderr, "Unexpected end of input file!\n"); + exit(1); + } +} + +/* + * Main program + */ +int rpmunpack_main(int argc, char **argv) +{ + int len, status = 0; + + /* Get our own program name */ + if ((progname = strrchr(argv[0], '/')) == NULL) + progname = argv[0]; + else + progname++; + + /* Check for command line parameters */ + if (argc>=2 && *argv[1]=='-') { + usage(rpmunpack_usage); + } + + /* Open input file */ + if (argc == 1) + infile = STDIN_FILENO; + else if ((infile = open(argv[1], O_RDONLY)) < 0) { + perror(progname); + exit(1); + } + + /* Read magic ID and output filename */ + myread(4); + if (strncmp(buffer, RPM_MAGIC, 4)) { + fprintf(stderr, "Input file is not in RPM format!\n"); + exit(1); + } + myread(6); /* Skip flags */ + myread(64); + buffer[64] = '\0'; + + /* Open output file */ + strcat(buffer, ".cpio.gz"); + if (infile == STDIN_FILENO) + outfile = STDOUT_FILENO; + else if ((outfile = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) { + perror(progname); + exit(1); + } + + /* + * Now search for the GZIP signature. This is rather awkward, but I don't + * know any other way how to find out the exact starting position of the + * archive within the input file. There are a couple of data structures + * and texts (obviously descriptions, installation shell scripts etc.) + * coming before the archive, but even they start at different offsets + * with different RPM files. However, it looks like the GZIP signature + * never appears before offset 0x200, so we skip these first couple of + * bytes to make the signature scan a little more reliable. + */ + myread(0x200 - 74); + while (status < 2) { + myread(1); + if (status == 0 && buffer[0] == GZ_MAGIC_1) + status++; + else if (status == 1 && buffer[0] == GZ_MAGIC_2) + status++; + else + status = 0; + } + buffer[0] = GZ_MAGIC_1; + buffer[1] = GZ_MAGIC_2; + if (write(outfile, buffer, 2) < 0) { + perror(progname); + exit(1); + } + + /* Now simply copy the GZIP archive into the output file */ + while ((len = read(infile, buffer, BUFSIZE)) > 0) { + if (write(outfile, buffer, len) < 0) { + perror(progname); + exit(1); + } + } + if (len < 0) { + perror(progname); + exit(1); + } + close(outfile); + close(infile); + exit(0); +} diff --git a/scripts/undeb b/scripts/undeb new file mode 100644 index 000000000..fa2bcb34c --- /dev/null +++ b/scripts/undeb @@ -0,0 +1,49 @@ +#!/bin/sh +# +usage() { +echo "Usage: undeb -c package.deb " +echo " undeb -l package.deb " +echo " undeb -x package.deb /foo/boo " +exit +} + +deb=$2 + +exist() { +if [ "$deb" = "" ]; then +usage +elif [ ! -s "$deb" ]; then +echo "Can't find $deb!" +exit +fi +} + +if [ "$1" = "" ]; then +usage +elif [ "$1" = "-l" ]; then +exist +type more >/dev/null 2>&1 && pager=more +type less >/dev/null 2>&1 && pager=less +trap "" 13 +(ar -p $deb control.tar.gz | gunzip -c | tar -x -O control ; echo -e "\nPress enter to scroll, q to Quit!\n" ; ar -p $deb data.tar.gz | gunzip -c | tar -t -v 2>/dev/null) | $pager +exit +elif [ "$1" = "-c" ]; then +exist +ar -p $deb control.tar.gz | gunzip -c | tar -x -O control +exit +elif [ "$1" = "-x" ]; then +exist +if [ "$3" = "" ]; then +usage +elif [ ! -d "$3" ]; then +echo "No such directory $3!" +exit +fi +ar -p $deb data.tar.gz | gunzip | (cd $3 ; tar -x -v -f -) || exit +echo +echo "Extracted $deb to $3!" +exit +else +usage +fi diff --git a/scripts/unrpm b/scripts/unrpm new file mode 100644 index 000000000..2cd1aa9c9 --- /dev/null +++ b/scripts/unrpm @@ -0,0 +1,43 @@ +#!/bin/sh +# +usage() { +echo "Usage: unrpm -l package.rpm " +echo " unrpm -x package.rpm /foo/boo " +exit +} + +rpm=$2 + +exist() { +if [ "$rpm" = "" ]; then +usage +elif [ ! -s "$rpm" ]; then +echo "Can't find $rpm!" +exit +fi +} + +if [ "$1" = "" ]; then +usage +elif [ "$1" = "-l" ]; then +exist +type more >/dev/null 2>&1 && pager=more +type less >/dev/null 2>&1 && pager=less +(echo -e "\nPress enter to scroll, q to Quit!\n" ; rpmunpack < $rpm | gunzip -c | cpio -tvf --quiet) | $pager +exit +elif [ "$1" = "-x" ]; then +exist +if [ "$3" = "" ]; then +usage +elif [ ! -d "$3" ]; then +echo "No such directory $3!" +exit +fi +rpmunpack < $rpm | gunzip | (cd $3 ; cpio -idmuv) || exit +echo +echo "Extracted $rpm to $3!" +exit +else +usage +fi diff --git a/unrpm.c b/unrpm.c deleted file mode 100644 index 26989e8b6..000000000 --- a/unrpm.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Mini unrpm implementation for busybox - * - * rpmunpack.c - Utility program to unpack an RPM archive - * - * Gero Kuhlmann 1998 - * - * This program is public domain software; you can do whatever you like - * with this source, including modifying and redistributing it. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - */ - -#include "busybox.h" -#include -#include -#include -#include -#include - -/* - * Some general definitions - */ -#define BUFSIZE 512 -#define RPM_MAGIC "\355\253\356\333" -#define GZ_MAGIC_1 '\037' -#define GZ_MAGIC_2 '\213' - -/* - * Global variables - */ -static char buffer[BUFSIZE]; -static char *progname; -static int infile, outfile; - -/* - * Read a specified number of bytes from input file - */ -static void myread(int num) -{ - int err; - - if ((err = read(infile, buffer, num)) != num) { - if (err < 0) - perror(progname); - else - fprintf(stderr, "unexpected end of input file\n"); - exit(1); - } -} - -/* - * Main program - */ -int unrpm_main(int argc, char **argv) -{ - int len, status = 0; - - /* Get our own program name */ - if ((progname = strrchr(argv[0], '/')) == NULL) - progname = argv[0]; - else - progname++; - - /* Check for command line parameters */ - if (argc>=2 && *argv[1]=='-') { - usage(unrpm_usage); - } - - /* Open input file */ - if (argc == 1) - infile = STDIN_FILENO; - else if ((infile = open(argv[1], O_RDONLY)) < 0) { - perror(progname); - exit(1); - } - - /* Read magic ID and output filename */ - myread(4); - if (strncmp(buffer, RPM_MAGIC, 4)) { - fprintf(stderr, "input file is not in RPM format\n"); - exit(1); - } - myread(6); /* Skip flags */ - myread(64); - buffer[64] = '\0'; - - /* Open output file */ - strcat(buffer, ".cpio.gz"); - if (infile == STDIN_FILENO) - outfile = STDOUT_FILENO; - else if ((outfile = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) { - perror(progname); - exit(1); - } - - /* - * Now search for the GZIP signature. This is rather awkward, but I don't - * know any other way how to find out the exact starting position of the - * archive within the input file. There are a couple of data structures - * and texts (obviously descriptions, installation shell scripts etc.) - * coming before the archive, but even they start at different offsets - * with different RPM files. However, it looks like the GZIP signature - * never appears before offset 0x200, so we skip these first couple of - * bytes to make the signature scan a little more reliable. - */ - myread(0x200 - 74); - while (status < 2) { - myread(1); - if (status == 0 && buffer[0] == GZ_MAGIC_1) - status++; - else if (status == 1 && buffer[0] == GZ_MAGIC_2) - status++; - else - status = 0; - } - buffer[0] = GZ_MAGIC_1; - buffer[1] = GZ_MAGIC_2; - if (write(outfile, buffer, 2) < 0) { - perror(progname); - exit(1); - } - - /* Now simply copy the GZIP archive into the output file */ - while ((len = read(infile, buffer, BUFSIZE)) > 0) { - if (write(outfile, buffer, len) < 0) { - perror(progname); - exit(1); - } - } - if (len < 0) { - perror(progname); - exit(1); - } - close(outfile); - close(infile); - exit(0); -}