aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2001-06-26 01:19:34 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2001-06-26 01:19:34 +0000
commitf8736d251e4291e414bd0bdaca2346cd7ef265dd (patch)
tree3c0018fb1226672ebaac9a2043eb078fbc940368
parent6c947d289fde9468092a23ed686632c81f99dcac (diff)
downloadbusybox-w32-f8736d251e4291e414bd0bdaca2346cd7ef265dd.tar.gz
busybox-w32-f8736d251e4291e414bd0bdaca2346cd7ef265dd.tar.bz2
busybox-w32-f8736d251e4291e414bd0bdaca2346cd7ef265dd.zip
rpm2cpio applet by Laurence Anderson
-rw-r--r--Config.h1
-rw-r--r--applets.h3
-rw-r--r--applets/usage.h7
-rw-r--r--archival/rpm2cpio.c92
-rw-r--r--docs/busybox_header.pod11
-rw-r--r--examples/unrpm4
-rw-r--r--include/applets.h3
-rw-r--r--include/usage.h7
-rw-r--r--rpm2cpio.c92
-rw-r--r--scripts/unrpm4
-rw-r--r--tests/testcases3
-rw-r--r--usage.h7
12 files changed, 222 insertions, 12 deletions
diff --git a/Config.h b/Config.h
index bc49ccc77..55792b48d 100644
--- a/Config.h
+++ b/Config.h
@@ -96,6 +96,7 @@
96#define BB_RMDIR 96#define BB_RMDIR
97//#define BB_RMMOD 97//#define BB_RMMOD
98//#define BB_ROUTE 98//#define BB_ROUTE
99//#define BB_RPM2CPIO
99//#define BB_RPMUNPACK 100//#define BB_RPMUNPACK
100#define BB_SED 101#define BB_SED
101//#define BB_SETKEYCODES 102//#define BB_SETKEYCODES
diff --git a/applets.h b/applets.h
index 88aec8ad1..287b29cf2 100644
--- a/applets.h
+++ b/applets.h
@@ -326,6 +326,9 @@
326#ifdef BB_ROUTE 326#ifdef BB_ROUTE
327 APPLET(route, route_main, _BB_DIR_USR_BIN) 327 APPLET(route, route_main, _BB_DIR_USR_BIN)
328#endif 328#endif
329#ifdef BB_RPM2CPIO
330 APPLET(rpm2cpio, rpm2cpio_main, _BB_DIR_USR_BIN)
331#endif
329#ifdef BB_RPMUNPACK 332#ifdef BB_RPMUNPACK
330 APPLET(rpmunpack, rpmunpack_main, _BB_DIR_USR_BIN) 333 APPLET(rpmunpack, rpmunpack_main, _BB_DIR_USR_BIN)
331#endif 334#endif
diff --git a/applets/usage.h b/applets/usage.h
index bf10e114f..a19f0fe22 100644
--- a/applets/usage.h
+++ b/applets/usage.h
@@ -1310,11 +1310,16 @@
1310#define route_full_usage \ 1310#define route_full_usage \
1311 "Edit the kernel's routing tables" 1311 "Edit the kernel's routing tables"
1312 1312
1313#define rpm2cpio_trivial_usage \
1314 "package.rpm"
1315#define rpm2cpio_full_usage \
1316 "Outputs a cpio archive of the rpm file."
1317
1313#define rpmunpack_trivial_usage \ 1318#define rpmunpack_trivial_usage \
1314 "< package.rpm | gunzip | cpio -idmuv" 1319 "< package.rpm | gunzip | cpio -idmuv"
1315#define rpmunpack_full_usage \ 1320#define rpmunpack_full_usage \
1316 "Extracts an rpm archive." 1321 "Extracts an rpm archive."
1317 1322
1318#define sed_trivial_usage \ 1323#define sed_trivial_usage \
1319 "[-nef] pattern [files...]" 1324 "[-nef] pattern [files...]"
1320#define sed_full_usage \ 1325#define sed_full_usage \
diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c
new file mode 100644
index 000000000..8d4ca84dc
--- /dev/null
+++ b/archival/rpm2cpio.c
@@ -0,0 +1,92 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini rpm2cpio implementation for busybox
4 *
5 * Copyright (C) 2001 by Laurence Anderson
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include "busybox.h"
23#include <netinet/in.h> /* For ntohl & htonl function */
24#include <string.h>
25
26#define RPM_MAGIC "\355\253\356\333"
27#define RPM_HEADER_MAGIC "\216\255\350"
28
29typedef unsigned char u8;
30typedef unsigned short u16;
31typedef unsigned int u32;
32
33struct rpm_lead {
34 unsigned char magic[4];
35 u8 major, minor;
36 u16 type;
37 u16 archnum;
38 char name[66];
39 u16 osnum;
40 u16 signature_type;
41 char reserved[16];
42};
43
44struct rpm_header {
45 char magic[3]; /* 3 byte magic: 0x8e 0xad 0xe8 */
46 u8 version; /* 1 byte version number */
47 u32 reserved; /* 4 bytes reserved */
48 u32 entries; /* Number of entries in header (4 bytes) */
49 u32 size; /* Size of store (4 bytes) */
50};
51
52void skip_header(FILE *rpmfile)
53{
54 struct rpm_header header;
55
56 fread(&header, sizeof(struct rpm_header), 1, rpmfile);
57 if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) error_msg_and_die("Invalid RPM header magic"); /* Invalid magic */
58 if (header.version != 1) error_msg_and_die("Unsupported RPM header version"); /* This program only supports v1 headers */
59 header.entries = ntohl(header.entries);
60 header.size = ntohl(header.size);
61 fseek (rpmfile, 16 * header.entries, SEEK_CUR); /* Seek past index entries */
62 fseek (rpmfile, header.size, SEEK_CUR); /* Seek past store */
63}
64
65/* No getopt required */
66extern int rpm2cpio_main(int argc, char **argv)
67{
68 struct rpm_lead lead;
69 int gunzip_pid;
70 FILE *rpmfile, *cpiofile;
71
72 if (argc == 1) {
73 rpmfile = stdin;
74 } else {
75 rpmfile = fopen(argv[1], "r");
76 if (!rpmfile) perror_msg_and_die("Can't open rpm file");
77 }
78
79 fread (&lead, sizeof(struct rpm_lead), 1, rpmfile);
80 if (strncmp((char *) &lead.magic, RPM_MAGIC, 4) != 0) error_msg_and_die("Invalid RPM magic"); /* Just check the magic, the rest is irrelevant */
81 /* Skip the signature header */
82 skip_header(rpmfile);
83 fseek(rpmfile, (8 - (ftell(rpmfile) % 8)) % 8, SEEK_CUR); /* Pad to 8 byte boundary */
84 /* Skip the main header */
85 skip_header(rpmfile);
86
87 cpiofile = gz_open(rpmfile, &gunzip_pid);
88 copyfd(fileno(cpiofile), fileno(stdout));
89 gz_close(gunzip_pid);
90 fclose(rpmfile);
91 return 0;
92}
diff --git a/docs/busybox_header.pod b/docs/busybox_header.pod
index 5b64cd7d7..84a2a5f44 100644
--- a/docs/busybox_header.pod
+++ b/docs/busybox_header.pod
@@ -56,17 +56,18 @@ terse runtime description of their behavior.
56Currently defined functions include: 56Currently defined functions include:
57 57
58adjtimex, ar, basename, busybox, cat, chgrp, chmod, chown, chroot, chvt, clear, 58adjtimex, ar, basename, busybox, cat, chgrp, chmod, chown, chroot, chvt, clear,
59cmp, cp, cut, date, dc, dd, deallocvt, df, dirname, dmesg, dos2unix, dpkg, 59cmp, cp, cpio, cut, date, dc, dd, deallocvt, df, dirname, dmesg, dos2unix, dpkg,
60dpkg-deb, du, dumpkmap, dutmp, echo, expr, false, fbset, fdflush, find, free, 60dpkg-deb, du, dumpkmap, dutmp, echo, expr, false, fbset, fdflush, find, free,
61freeramdisk, fsck.minix, getopt, grep, gunzip, gzip, halt, head, hostid, 61freeramdisk, fsck.minix, getopt, grep, gunzip, gzip, halt, head, hostid,
62hostname, id, ifconfig, init, insmod, kill, killall, klogd, length, ln, 62hostname, id, ifconfig, init, insmod, kill, killall, klogd, length, ln,
63loadacm, loadfont, loadkmap, logger, logname, ls, lsmod, makedevs, md5sum, 63loadacm, loadfont, loadkmap, logger, logname, ls, lsmod, makedevs, md5sum,
64mkdir, mkfifo, mkfs.minix, mknod, mkswap, mktemp, more, mount, mt, mv, nc, 64mkdir, mkfifo, mkfs.minix, mknod, mkswap, mktemp, more, mount, mt, mv, nc,
65nslookup, ping, pivot_root, poweroff, printf, ps, pwd, rdate, readlink, reboot, 65nslookup, ping, pivot_root, poweroff, printf, ps, pwd, rdate, readlink, reboot,
66renice, reset, rm, rmdir, rmmod, route, rpmunpack, sed, setkeycodes, sh, sleep, 66renice, reset, rm, rmdir, rmmod, route, rpm2cpio, rpmunpack, sed, setkeycodes,
67sort, stty, swapoff, swapon, sync, syslogd, tail, tar, tee, telnet, test, tftp, 67sh, sleep, sort, stty, swapoff, swapon, sync, syslogd, tail, tar, tee, telnet,
68touch, tr, true, tty, umount, uname, uniq, unix2dos, update, uptime, usleep, 68test, tftp, touch, tr, true, tty, umount, uname, uniq, unix2dos, update, uptime,
69uudecode, uuencode, watchdog, wc, wget, which, whoami, xargs, yes, zcat, [ 69usleep, uudecode, uuencode, watchdog, wc, wget, which, whoami, xargs, yes, zcat,
70[
70 71
71=over 4 72=over 4
72 73
diff --git a/examples/unrpm b/examples/unrpm
index 9ab37be0a..376286a6f 100644
--- a/examples/unrpm
+++ b/examples/unrpm
@@ -29,7 +29,7 @@ exist
29type more >/dev/null 2>&1 && pager=more 29type more >/dev/null 2>&1 && pager=more
30type less >/dev/null 2>&1 && pager=less 30type less >/dev/null 2>&1 && pager=less
31[ "$pager" = "" ] && echo "No pager found!" && exit 31[ "$pager" = "" ] && echo "No pager found!" && exit
32(echo -e "\nPress enter to scroll, q to Quit!\n" ; rpmunpack < $rpm | gzip -dc | cpio -tv --quiet) | $pager 32(echo -e "\nPress enter to scroll, q to Quit!\n" ; rpm2cpio $rpm | cpio -tv --quiet) | $pager
33exit 33exit
34elif [ "$1" = "-x" ]; then 34elif [ "$1" = "-x" ]; then
35exist 35exist
@@ -39,7 +39,7 @@ elif [ ! -d "$3" ]; then
39echo "No such directory $3!" 39echo "No such directory $3!"
40exit 40exit
41fi 41fi
42rpmunpack < $rpm | gzip -d | (umask 0 ; cd $3 ; cpio -idmuv) || exit 42rpm2cpio $rpm | (umask 0 ; cd $3 ; cpio -idmuv) || exit
43echo 43echo
44echo "Extracted $rpm to $3!" 44echo "Extracted $rpm to $3!"
45exit 45exit
diff --git a/include/applets.h b/include/applets.h
index 88aec8ad1..287b29cf2 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -326,6 +326,9 @@
326#ifdef BB_ROUTE 326#ifdef BB_ROUTE
327 APPLET(route, route_main, _BB_DIR_USR_BIN) 327 APPLET(route, route_main, _BB_DIR_USR_BIN)
328#endif 328#endif
329#ifdef BB_RPM2CPIO
330 APPLET(rpm2cpio, rpm2cpio_main, _BB_DIR_USR_BIN)
331#endif
329#ifdef BB_RPMUNPACK 332#ifdef BB_RPMUNPACK
330 APPLET(rpmunpack, rpmunpack_main, _BB_DIR_USR_BIN) 333 APPLET(rpmunpack, rpmunpack_main, _BB_DIR_USR_BIN)
331#endif 334#endif
diff --git a/include/usage.h b/include/usage.h
index bf10e114f..a19f0fe22 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1310,11 +1310,16 @@
1310#define route_full_usage \ 1310#define route_full_usage \
1311 "Edit the kernel's routing tables" 1311 "Edit the kernel's routing tables"
1312 1312
1313#define rpm2cpio_trivial_usage \
1314 "package.rpm"
1315#define rpm2cpio_full_usage \
1316 "Outputs a cpio archive of the rpm file."
1317
1313#define rpmunpack_trivial_usage \ 1318#define rpmunpack_trivial_usage \
1314 "< package.rpm | gunzip | cpio -idmuv" 1319 "< package.rpm | gunzip | cpio -idmuv"
1315#define rpmunpack_full_usage \ 1320#define rpmunpack_full_usage \
1316 "Extracts an rpm archive." 1321 "Extracts an rpm archive."
1317 1322
1318#define sed_trivial_usage \ 1323#define sed_trivial_usage \
1319 "[-nef] pattern [files...]" 1324 "[-nef] pattern [files...]"
1320#define sed_full_usage \ 1325#define sed_full_usage \
diff --git a/rpm2cpio.c b/rpm2cpio.c
new file mode 100644
index 000000000..8d4ca84dc
--- /dev/null
+++ b/rpm2cpio.c
@@ -0,0 +1,92 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini rpm2cpio implementation for busybox
4 *
5 * Copyright (C) 2001 by Laurence Anderson
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include "busybox.h"
23#include <netinet/in.h> /* For ntohl & htonl function */
24#include <string.h>
25
26#define RPM_MAGIC "\355\253\356\333"
27#define RPM_HEADER_MAGIC "\216\255\350"
28
29typedef unsigned char u8;
30typedef unsigned short u16;
31typedef unsigned int u32;
32
33struct rpm_lead {
34 unsigned char magic[4];
35 u8 major, minor;
36 u16 type;
37 u16 archnum;
38 char name[66];
39 u16 osnum;
40 u16 signature_type;
41 char reserved[16];
42};
43
44struct rpm_header {
45 char magic[3]; /* 3 byte magic: 0x8e 0xad 0xe8 */
46 u8 version; /* 1 byte version number */
47 u32 reserved; /* 4 bytes reserved */
48 u32 entries; /* Number of entries in header (4 bytes) */
49 u32 size; /* Size of store (4 bytes) */
50};
51
52void skip_header(FILE *rpmfile)
53{
54 struct rpm_header header;
55
56 fread(&header, sizeof(struct rpm_header), 1, rpmfile);
57 if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) error_msg_and_die("Invalid RPM header magic"); /* Invalid magic */
58 if (header.version != 1) error_msg_and_die("Unsupported RPM header version"); /* This program only supports v1 headers */
59 header.entries = ntohl(header.entries);
60 header.size = ntohl(header.size);
61 fseek (rpmfile, 16 * header.entries, SEEK_CUR); /* Seek past index entries */
62 fseek (rpmfile, header.size, SEEK_CUR); /* Seek past store */
63}
64
65/* No getopt required */
66extern int rpm2cpio_main(int argc, char **argv)
67{
68 struct rpm_lead lead;
69 int gunzip_pid;
70 FILE *rpmfile, *cpiofile;
71
72 if (argc == 1) {
73 rpmfile = stdin;
74 } else {
75 rpmfile = fopen(argv[1], "r");
76 if (!rpmfile) perror_msg_and_die("Can't open rpm file");
77 }
78
79 fread (&lead, sizeof(struct rpm_lead), 1, rpmfile);
80 if (strncmp((char *) &lead.magic, RPM_MAGIC, 4) != 0) error_msg_and_die("Invalid RPM magic"); /* Just check the magic, the rest is irrelevant */
81 /* Skip the signature header */
82 skip_header(rpmfile);
83 fseek(rpmfile, (8 - (ftell(rpmfile) % 8)) % 8, SEEK_CUR); /* Pad to 8 byte boundary */
84 /* Skip the main header */
85 skip_header(rpmfile);
86
87 cpiofile = gz_open(rpmfile, &gunzip_pid);
88 copyfd(fileno(cpiofile), fileno(stdout));
89 gz_close(gunzip_pid);
90 fclose(rpmfile);
91 return 0;
92}
diff --git a/scripts/unrpm b/scripts/unrpm
index 9ab37be0a..376286a6f 100644
--- a/scripts/unrpm
+++ b/scripts/unrpm
@@ -29,7 +29,7 @@ exist
29type more >/dev/null 2>&1 && pager=more 29type more >/dev/null 2>&1 && pager=more
30type less >/dev/null 2>&1 && pager=less 30type less >/dev/null 2>&1 && pager=less
31[ "$pager" = "" ] && echo "No pager found!" && exit 31[ "$pager" = "" ] && echo "No pager found!" && exit
32(echo -e "\nPress enter to scroll, q to Quit!\n" ; rpmunpack < $rpm | gzip -dc | cpio -tv --quiet) | $pager 32(echo -e "\nPress enter to scroll, q to Quit!\n" ; rpm2cpio $rpm | cpio -tv --quiet) | $pager
33exit 33exit
34elif [ "$1" = "-x" ]; then 34elif [ "$1" = "-x" ]; then
35exist 35exist
@@ -39,7 +39,7 @@ elif [ ! -d "$3" ]; then
39echo "No such directory $3!" 39echo "No such directory $3!"
40exit 40exit
41fi 41fi
42rpmunpack < $rpm | gzip -d | (umask 0 ; cd $3 ; cpio -idmuv) || exit 42rpm2cpio $rpm | (umask 0 ; cd $3 ; cpio -idmuv) || exit
43echo 43echo
44echo "Extracted $rpm to $3!" 44echo "Extracted $rpm to $3!"
45exit 45exit
diff --git a/tests/testcases b/tests/testcases
index a38d31770..4708e54e2 100644
--- a/tests/testcases
+++ b/tests/testcases
@@ -292,6 +292,8 @@ touch F ; rm F
292# XXX: doesn't DNS resolve 292# XXX: doesn't DNS resolve
293route 293route
294 294
295# rpm2cpio
296
295# rpmunpack 297# rpmunpack
296 298
297# sed - we can do some one-liners here, some testing is a little 299# sed - we can do some one-liners here, some testing is a little
@@ -401,3 +403,4 @@ ls -1 ../e* | xargs
401ls -1 ../e* | xargs md5sum 403ls -1 ../e* | xargs md5sum
402 404
403# yes - can't test: interactive (needs ^C) 405# yes - can't test: interactive (needs ^C)
406
diff --git a/usage.h b/usage.h
index bf10e114f..a19f0fe22 100644
--- a/usage.h
+++ b/usage.h
@@ -1310,11 +1310,16 @@
1310#define route_full_usage \ 1310#define route_full_usage \
1311 "Edit the kernel's routing tables" 1311 "Edit the kernel's routing tables"
1312 1312
1313#define rpm2cpio_trivial_usage \
1314 "package.rpm"
1315#define rpm2cpio_full_usage \
1316 "Outputs a cpio archive of the rpm file."
1317
1313#define rpmunpack_trivial_usage \ 1318#define rpmunpack_trivial_usage \
1314 "< package.rpm | gunzip | cpio -idmuv" 1319 "< package.rpm | gunzip | cpio -idmuv"
1315#define rpmunpack_full_usage \ 1320#define rpmunpack_full_usage \
1316 "Extracts an rpm archive." 1321 "Extracts an rpm archive."
1317 1322
1318#define sed_trivial_usage \ 1323#define sed_trivial_usage \
1319 "[-nef] pattern [files...]" 1324 "[-nef] pattern [files...]"
1320#define sed_full_usage \ 1325#define sed_full_usage \