client/rhel/rhn-client-tools/man/en/spacewalk-channel.8 | 106 ++++++++++++++
client/rhel/rhn-client-tools/rhn-client-tools.spec | 2
client/rhel/rhn-client-tools/src/bin/Makefile | 2
client/rhel/rhn-client-tools/src/bin/spacewalk-channel.py | 97 ++++++++++++
4 files changed, 207 insertions(+)
New commits:
commit b10e27cf76498584190a2291779bf779fa8e61ba
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Tue Nov 24 17:05:59 2009 +0100
216808 - create new script spacewalk-channel
This script allows you to subscribe to and unsubscribe from channel from command line
diff --git a/client/rhel/rhn-client-tools/man/en/spacewalk-channel.8
b/client/rhel/rhn-client-tools/man/en/spacewalk-channel.8
new file mode 100644
index 0000000..668c3d6
--- /dev/null
+++ b/client/rhel/rhn-client-tools/man/en/spacewalk-channel.8
@@ -0,0 +1,106 @@
+.\" Copyright 2009 Red Hat, Inc.
+.\"
+.\" This man page is free documentation; you can redistribute it and/or modify
+.\" it under the terms of the GNU General Public License as published by
+.\" the Free Software Foundation; either version 2 of the License, or
+.\" (at your option) any later version.
+.\"
+.\" 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. See the
+.\" GNU General Public License for more details.
+.\"
+.\" You should have received a copy of the GNU General Public License
+.\" along with this man page; if not, write to the Free Software
+.\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+.\"
+.TH SPACEWALK-CHANNEL 8 "2009 November 24" "Linux" "Red Hat,
Inc."
+
+.SH NAME
+spacewalk-channel \- Subscribe to or unsubscribe system from channel.
+
+.SH SYNOPSIS
+
+spacewalk-channel [\fIoptions\fP]
+
+.SH DESCRIPTION
+.PP
+\fVspacewalk-channel\fR enable you to subscribe to and unsubscribe from
+specified channels via the command line so a visit to the Red Hat Network
+(or Spacewalk) website isn't required.
+
+.SH OPTIONS
+
+.IP "\fB-l, --list\fP"
+Print list of channel you are currently subscribed to.
+.br
+.IP "\fB-a, --add\fP"
+You are subscribing system to given channel. You have to specify --user and --password.
+.br
+.IP "\fB-r, --remove\fP"
+You are unsubscribing system to given channel. You have to specify --user and
--password.
+.br
+.IP "\fB-u, --username\fP"
+The username to register the system with under Red Hat Network, RHN Satellite or
Spacewalk.
+.br
+.IP "\fB-p, --password\fP"
+The password associated with the username specified with the \fB--username\fR
+option. This is an unencrypted password.
+.br
+.IP "\fB-c, --channel\fP"
+Label of channel you want to subscribe to or unsubscribe from. Can be specified multiple
+times.
+.br
+.IP "\fB-v, --verbose\fP"
+Print out successfull action.
+.br
+.IP "\fB-h, --help\fP"
+Show a help message and exit.
+
+.SH "EXAMPLES"
+
+Subscribe to two channels:
+
+.RS
+.nf
+spacewalk-channel --add -c rhn-tools-rhel-i386-server-5 -c rhel-i386-server-vt-5 --user
user --password foobar
+.fi
+.RE
+
+Unsubscribe from channel:
+
+.RS
+.nf
+spacewalk-channel --remove -c rhn-tools-rhel-i386-server-5 -c rhel-i386-server-vt-5
--user user --password foobar
+.fi
+.RE
+
+List subscribed channels:
+
+.RS
+.nf
+spacewalk-channel --list
+.fi
+.RE
+
+.SH "SEE ALSO"
+
+.PP
+\fBrhnplugin\fP(8), \fBrhn_register\fP(8), \fBup2date\fP(5).
+
+.SH AUTHORS
+.PP
+Miroslav Suchý <msuchy(a)redhat.com>
+
+.SH "BUGS"
+.PP
+Report bugs to <
http://bugzilla.redhat.com>.
+
+.SH COPYRIGHT
+
+.PP
+Copyright \(co 2009 Red Hat, Inc.
+
+.PP
+This is free software; see the source for copying conditions. There is
+NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/client/rhel/rhn-client-tools/rhn-client-tools.spec
b/client/rhel/rhn-client-tools/rhn-client-tools.spec
index 1f5a71c..176f234 100644
--- a/client/rhel/rhn-client-tools/rhn-client-tools.spec
+++ b/client/rhel/rhn-client-tools/rhn-client-tools.spec
@@ -189,6 +189,8 @@ rm -rf $RPM_BUILD_ROOT
%{_bindir}/rhn_register
%{_sbindir}/rhn_register
%{_sbindir}/rhnreg_ks
+%{_sbindir}/spacewalk-channel
+%{_sbindir}/rhn-channel
%{_datadir}/rhn/up2date_client/rhnreg.*
%{_datadir}/rhn/up2date_client/tui.*
diff --git a/client/rhel/rhn-client-tools/src/bin/Makefile
b/client/rhel/rhn-client-tools/src/bin/Makefile
index 15b8888..7a1e73e 100644
--- a/client/rhel/rhn-client-tools/src/bin/Makefile
+++ b/client/rhel/rhn-client-tools/src/bin/Makefile
@@ -28,8 +28,10 @@ install:: all $(DIRS)
$(INSTALL_BIN) rhn_register.py $(SBIN_DIR)/rhn_register
$(INSTALL_BIN) rhn-profile-sync.py $(SBIN_DIR)/rhn-profile-sync
$(INSTALL_BIN) rhn_check.py $(SBIN_DIR)/rhn_check
+ $(INSTALL_BIN) spacewalk-channel.py $(SBIN_DIR)/spacewalk-channel
ln -sf consolehelper $(BIN_DIR)/rhn_register
+ ln -s spacewalk-channel $(SBIN_DIR)/rhn-channel
# OTHER targets for internal use
pychecker::
diff --git a/client/rhel/rhn-client-tools/src/bin/spacewalk-channel.py
b/client/rhel/rhn-client-tools/src/bin/spacewalk-channel.py
new file mode 100644
index 0000000..da1d082
--- /dev/null
+++ b/client/rhel/rhn-client-tools/src/bin/spacewalk-channel.py
@@ -0,0 +1,97 @@
+#!/usr/bin/python
+#
+# Copyright (c) 2009 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+import os
+import socket
+import sys
+from optparse import Option, OptionParser
+
+def systemExit(code, msgs=None):
+ "Exit with a code and optional message(s). Saved a few lines of code."
+ if msgs:
+ if type(msgs) not in [type([]), type(())]:
+ msgs = (msgs, )
+ for msg in msgs:
+ sys.stderr.write(str(msg)+'\n')
+ sys.exit(code)
+
+# quick check to see if you are a super-user.
+if os.getuid() != 0:
+ systemExit(8, 'ERROR: must be root to execute\n')
+
+_LIBPATH = "/usr/share/rhn"
+# add to the path if need be
+if _LIBPATH not in sys.path:
+ sys.path.append(_LIBPATH)
+
+from up2date_client.rhnChannel import subscribeChannels, unsubscribeChannels,
getChannels
+from up2date_client import up2dateAuth, config, up2dateErrors
+
+def processCommandline():
+ "process the commandline, setting the OPTIONS object"
+ optionsTable = [
+ Option('-c', '--channel', action='append',
+ help='name of channel you want to (un)subscribe'),
+ Option('-a', '--add', action='store_true',
+ help='subscribe to channel'),
+ Option('-r', '--remove', action='store_true',
+ help='unsubscribe from channel'),
+ Option('-l', '--list', action='store_true',
+ help='list channels'),
+ Option('-v', '--verbose', action='store_true',
+ help='verbose output'),
+ Option('-u', '--user', action='store',
+ help='your user name'),
+ Option('-p', '--password', action='store',
+ help='your password'),
+ ]
+ optionParser = OptionParser(option_list=optionsTable)
+ global OPTIONS
+ OPTIONS, args = optionParser.parse_args()
+
+ # we take no extra commandline arguments that are not linked to an option
+ if args:
+ systemExit(1, "ERROR: these arguments make no sense in this context (try
--help)")
+ if not OPTIONS.user and not OPTIONS.list:
+ systemExit(2, "ERROR: username is required")
+ if not OPTIONS.password and not OPTIONS.list:
+ systemExit(3, "ERROR: password is required")
+
+def main():
+ if OPTIONS.add:
+ subscribeChannels(OPTIONS.channel, OPTIONS.user, OPTIONS.password)
+ if OPTIONS.verbose:
+ print "Channel(s): %s successfully added" % ',
'.join(OPTIONS.channel)
+ elif OPTIONS.remove:
+ unsubscribeChannels(OPTIONS.channel, OPTIONS.user, OPTIONS.password)
+ if OPTIONS.verbose:
+ print "Channel(s): %s successfully removed" % ',
'.join(OPTIONS.channel)
+ elif OPTIONS.list:
+ channels = map(lambda x: x['label'], getChannels().channels())
+ channels.sort()
+ print '\n'.join(channels)
+ else:
+ s = rhnserver.RhnServer()
+ print s.up2date.listall(up2dateAuth.getSystemId())
+ systemExit(3, "ERROR: you may want to specify --add, --remove or
--list")
+
+try:
+ processCommandline()
+ main()
+except KeyboardInterrupt:
+ systemExit(0, "\nUser interrupted process.")
+except up2dateErrors.RhnServerException, e:
+ # do not print traceback, it will scare people
+ systemExit(1, e)