diff --git a/.cvsignore b/.cvsignore index e69de29..8b7a788 100644 --- a/.cvsignore +++ b/.cvsignore @@ -0,0 +1 @@ +bwbar-1.2.2.tar.gz diff --git a/bwbar b/bwbar new file mode 100644 index 0000000..4a70017 --- /dev/null +++ b/bwbar @@ -0,0 +1,68 @@ +#!/bin/bash +# +# Starting bwbar as daemon +# Author: Adrian Reber +# +# chkconfig: 2345 50 01 +# +# description: start bwbar as daemon +# processname: bwbar + +# source function library +. /etc/rc.d/init.d/functions + +# Source networking configuration. +[ -r /etc/sysconfig/network ] && . /etc/sysconfig/network + +# Check that networking is up. +[ "${NETWORKING}" = "no" ] && exit 0 + + +if [ -f /etc/sysconfig/bwbar ]; then + . /etc/sysconfig/bwbar +fi + +if [ -z $BWBAR_USER ]; then + exit 0 +fi + +RETVAL=0 + +start() { + echo -n "Starting bwbar: " + daemon --user $BWBAR_USER bwbar $OPTIONS + RETVAL=$? + echo +} + +stop() { + echo -n "Stopping bwbar: " + killproc bwbar + RETVAL=$? + echo +} + +restart() { + stop + start +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + restart + ;; + status) + status bwbar + ;; + *) + echo $"Usage: $0 {start|stop|status|restart}" + exit 1 +esac + +exit $RETVAL diff --git a/bwbar.8 b/bwbar.8 new file mode 100644 index 0000000..7984405 --- /dev/null +++ b/bwbar.8 @@ -0,0 +1,102 @@ +.TH bwbar 8 "Feb. 7, 2002" "Bandwidth Bar" + +.SH NAME +bwbar \- create a textual and graphical readout of current bandwidth usage + +.SH SYNOPSIS +.B bwbar +.RI [ +.B --input|-i +] [ +.B --output|-o +] [ +.B --directory|-d +.I directory +] [ +.B --text-file|-t +.I file +] [ +.B --png-file|-p +.I file +] [ +.B --interval|-t +.I seconds +] [ +.B --width|-x +.I pixels +] [ +.B --height|-y +.I pixels +] [ +.B --border|-b +.I pixels +] [ +.B --kbps|-k +] [ +.B --Mbps|-M +] [ +.B --Gbps|-G +] [ +.B --help|-h +] +.I interface +.I max-Mbps +.br + +.SH DESCRIPTION +This manual page briefly documents the +.B bwbar +program. +.PP +.B bwbar +is a simple daemon which creatse a readout of current bandwidth usage, generally for inclusion on a webpage. The output appear\s in both a text file and a PNG format bargraph in the specified output directory, and is based on data gathered from the spec\ified device and the specified maximum bandwidth. + +.SH OPTIONS +.B +.IP --input|-i +Measure the input bandwidth +.B +.IP --output|-o +Measure output bandwidth (default) +.B +.IP --directory|-d +Specify the output directory +.B +.IP --text-file|-f +Specify the name of the text-format ouput file (defaults to "ubar.txt") +.B +.IP --png-file|-p +Specify the name of the PNG-format output file (defaults to "ubar.png") +.B +.IP --interval|-t +Set the poll interval in seconds (defaults to 15 seconds) +.B +.IP --width|-x +Set the width of the graphical bar (defaults to 600 pixels) +.B +.IP --height|-y +Set the height of the graphical bar (defaults to 4 pixels) +.B +.IP --border|-b +Set the border width of the graphical bar (defaults to 1 pixel) +.B +.IP --kbps|-k +Set the units of bandwidth measure to kilobits/second +.B +.IP --Mbps|-M +Set the units of bandwidth measure to megabits/second (default) +.B +.IP --Gbps|-G +Set the units of bandwidth measure to gigabits/second +.B +.IP --Daemon|-D +Run as daemon +.B +.IP --help|-h +Online help + +.SH AUTHOR +.B bwbar +was written by Peter Anvin . +.PP +This manual page was prepared by Nick Rusnov for the Debian Project. diff --git a/bwbar.daemon.patch b/bwbar.daemon.patch new file mode 100644 index 0000000..5f965eb --- /dev/null +++ b/bwbar.daemon.patch @@ -0,0 +1,55 @@ +--- bwbar.c.orig 2004-07-16 15:05:08.000000000 +0200 ++++ bwbar.c 2004-07-16 15:11:03.000000000 +0200 +@@ -156,6 +156,7 @@ + { "kbps", 0, 0, 'k' }, + { "Mbps", 0, 0, 'M' }, + { "Gbps", 0, 0, 'G' }, ++ { "Daemon", 0, 0, 'D' }, + { "help", 0, 0, 'h' }, + { 0, 0, 0, 0 } + }; +@@ -178,6 +179,7 @@ + " --kbps -k Bandwidth is measured in kbit/s\n" + " --Mbps -M Bandwidth is measured in Mbit/s (default)\n" + " --Gbps -G Bandwidth is measured in Gbit/s\n" ++ " --Daemon -D Run as daemon\n" + " --help -h Display this text\n", + program); + exit(err); +@@ -211,10 +213,11 @@ + int width = 600; /* Bar width */ + int height = 4; /* Bar height */ + int border = 1; /* Bar border */ ++ int daemon_mode = 0; /* run as daemon */ + + program = argv[0]; + +- while ( (opt = getopt_long(argc, argv, "iof:p:t:x:y:b:kMGh", longopts, NULL)) != -1 ) { ++ while ( (opt = getopt_long(argc, argv, "iof:p:t:x:y:b:kMGhD", longopts, NULL)) != -1 ) { + switch ( opt ) { + case 'i': + measure_input = 1; +@@ -252,6 +255,9 @@ + unit = 1.0e+9; + unit_name = "Gbit/s"; + break; ++ case 'D': ++ daemon_mode = 1; ++ break; + case 'h': + usage(0); + break; +@@ -278,7 +284,12 @@ + + first = 1; + lbin = 0; lbout = 0; +- ++ ++ if ( daemon_mode == 1) { ++ if ( fork() != 0) ++ return 0; ++ } ++ + while ( 1 ) { + + /**** Begin code that obtains bandwidth data ****/ diff --git a/bwbar.debian-010_directory_option.patch b/bwbar.debian-010_directory_option.patch new file mode 100644 index 0000000..bb6f20a --- /dev/null +++ b/bwbar.debian-010_directory_option.patch @@ -0,0 +1,65 @@ +--- bwbar.c.orig 2004-07-23 08:03:24.184266598 +0200 ++++ bwbar.c 2004-07-23 08:04:45.377702561 +0200 +@@ -147,6 +147,7 @@ + const struct option longopts[] = { + { "input", 0, 0, 'i' }, + { "output", 0, 0, 'o' }, ++ { "directory", 1, 0, 'd' }, + { "text-file", 1, 0, 'f' }, + { "png-file", 1, 0, 'p' }, + { "interval", 1, 0, 't' }, +@@ -170,6 +171,7 @@ + "Options: (defaults in parenthesis)\n" + " --input -i Measure input bandwidth\n" + " --output -o Measure output bandwidth (default)\n" ++ " --directory -d Output directory\n" + " --text-file -f The name of the text output file (ubar.txt)\n" + " --png-file -p The name of the graphical bar file (ubar.png)\n" + " --interval -t The poll interval in seconds (15)\n" +@@ -207,6 +209,8 @@ + int measure_input = 0; /* Input instead of output */ + char *text_file = "ubar.txt"; /* Text filename */ + char *graphics_file = "ubar.png"; /* Graphics filename */ ++ char *directory = ""; /* Directory name */ ++ char *tmp_char; + char *unit_name = "Mbit/s"; /* Unit name */ + double unit = 1.0e+6; /* Unit multiplier */ + int interval = 15; /* Interval between measurements (s) */ +@@ -217,7 +221,7 @@ + + program = argv[0]; + +- while ( (opt = getopt_long(argc, argv, "iof:p:t:x:y:b:kMGhD", longopts, NULL)) != -1 ) { ++ while ( (opt = getopt_long(argc, argv, "iof:p:t:x:y:b:kMGhDd:", longopts, NULL)) != -1 ) { + switch ( opt ) { + case 'i': + measure_input = 1; +@@ -231,6 +235,9 @@ + case 'p': + graphics_file = optarg; + break; ++ case 'd': ++ directory = optarg; ++ break; + case 't': + interval = atoi(optarg); + break; +@@ -270,6 +277,18 @@ + if ( argc-optind != 2 ) + usage(1); + ++ tmp_char = text_file; ++ text_file = malloc(strlen(text_file) + strlen(directory) + 5); ++ strcpy(text_file, directory); ++ strcat(text_file, "/"); ++ strcat(text_file, tmp_char); ++ ++ tmp_char = graphics_file; ++ graphics_file = malloc(strlen(graphics_file) + strlen(directory) + 5); ++ strcpy(graphics_file, directory); ++ strcat(graphics_file, "/"); ++ strcat(graphics_file, tmp_char); ++ + t_tmp = malloc(strlen(text_file) + 5); + g_tmp = malloc(strlen(graphics_file) + 5); + if ( !t_tmp || !g_tmp ) { diff --git a/bwbar.debian-020_proc_net_2.6.x_fix.patch b/bwbar.debian-020_proc_net_2.6.x_fix.patch new file mode 100644 index 0000000..4de3fc9 --- /dev/null +++ b/bwbar.debian-020_proc_net_2.6.x_fix.patch @@ -0,0 +1,11 @@ +--- bwbar.c 2004-06-01 14:54:12.000000000 -0500 ++++ ../tmp/bwbar-1.2/bwbar.c 2004-05-12 00:58:50.000000000 -0500 +@@ -315,7 +315,7 @@ + + /* Get interface info */ + do { +- if ( fscanf(pnd, " %6[^:]:%u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u", ++ if ( fscanf(pnd, " %8[^:]:%u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u", + ifc.name, + &ifc.r_bytes, &ifc.r_pkt, &ifc.r_err, &ifc.r_drop, + &ifc.r_fifo, &ifc.r_frame, &ifc.r_compr, &ifc.r_mcast, diff --git a/bwbar.spec b/bwbar.spec new file mode 100644 index 0000000..6ec25cc --- /dev/null +++ b/bwbar.spec @@ -0,0 +1,82 @@ +# $Id: hardlink++.spec,v 1.1.1.1 2004/07/13 11:30:47 adrian Exp $ + +Summary: A program that generates a readout of the current bandwidth use +Name: bwbar +Version: 1.2.2 +Release: 0.fdr.2.1 +Epoch: 0 +License: GPL +Group: System Environment/Base +Source0: http://www.kernel.org/pub/software/web/bwbar/bwbar-1.2.2.tar.gz +Source1: bwbar +Source2: bwbar.8 +Patch0: bwbar.daemon.patch +Patch1: bwbar.debian-010_directory_option.patch +Patch2: bwbar.debian-020_proc_net_2.6.x_fix.patch +URL: http://www.kernel.org/pub/software/web/bwbar/ +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) +BuildRequires: libpng-devel + +%description +bwbar is a small program that generates a text and a graphical readout +of the current bandwidth use. It is currently for Linux only. + +It is used, among others, at http://www.kernel.org/. + +%prep +%setup -q +%patch0 -p0 +%patch1 -p0 +%patch2 -p0 + +%build +%configure +%{__make} %{?_smp_mflags} + +%install +%{__rm} -rf $RPM_BUILD_ROOT +%{__mkdir_p} $RPM_BUILD_ROOT%{_bindir} +%{__mkdir_p} $RPM_BUILD_ROOT%{_mandir}/man8 +%{__mkdir_p} $RPM_BUILD_ROOT%{_initrddir} +%{__mkdir_p} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig +%{__install} -m 755 %{name} $RPM_BUILD_ROOT%{_bindir} +%{__install} -m 755 %{SOURCE1} $RPM_BUILD_ROOT%{_initrddir} +%{__install} -m 644 %{SOURCE2} $RPM_BUILD_ROOT%{_mandir}/man8 + +%{__cat} >> $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/bwbar << END +#OPTIONS="-D eth0 100 -d /path/to/outdir" +#BWBAR_USER="please_define_a_user" +END + +%post +if [ "$1" -eq "1" ]; then + /sbin/chkconfig --add %{name} +fi + +%preun +if [ "$1" -eq "0" ]; then + /sbin/service %{name} stop > /dev/null 2>&1 + /sbin/chkconfig --del %{name} +fi + + +%clean +%{__rm} -rf $RPM_BUILD_ROOT + +%files +%defattr(-, root, root, 0755) +%doc README +%{_bindir}/%{name} +%{_mandir}/man8/* +%config(noreplace) %{_initrddir}/%{name} +%config(noreplace) %{_sysconfdir}/sysconfig/%{name} + +%changelog +* Fri Jul 23 2004 Adrian Reber - 0:1.2.2-0.fdr.2 +- changed the daemon patch to use -D and --Daemon +- added a debian patch to specify an output directory +- added another debian patch +- added the man page (also from the debian package) + +* Fri Jul 16 2004 Adrian Reber - 0:1.2.2-0.fdr.1 +- Initial RPM release. diff --git a/sources b/sources index e69de29..97bdd0c 100644 --- a/sources +++ b/sources @@ -0,0 +1 @@ +6dd176df1851e60863d488e86406003d bwbar-1.2.2.tar.gz