Blame SOURCES/BZ-1278333-yum-shell-support-exit-status.patch

d2a170
diff -up yum-3.4.3/docs/yum.conf.5.orig yum-3.4.3/docs/yum.conf.5
d2a170
--- yum-3.4.3/docs/yum.conf.5.orig	2017-11-24 20:52:02.648462776 +0100
d2a170
+++ yum-3.4.3/docs/yum.conf.5	2017-11-24 20:52:18.483380945 +0100
d2a170
@@ -1016,6 +1016,15 @@ If set to False, 'yum update' will fail
d2a170
 names (package, group, rpm file). It will also fail if the provided name is a package
d2a170
 which is available, but not installed. Boolean (1, 0, True, False, yes, no). Defaults to True.
d2a170
 
d2a170
+.IP
d2a170
+\fBshell_exit_status\fR
d2a170
+Determines the exit status that should be returned by `yum shell' when it
d2a170
+terminates after reading the `exit' command or EOF.
d2a170
+Possible values are: 0, ?.
d2a170
+If ? is set, the exit status is that of the last command executed before `exit'
d2a170
+(bash-like behavior).
d2a170
+Defaults to 0.
d2a170
+
d2a170
 .SH "[repository] OPTIONS"
d2a170
 .LP 
d2a170
 The repository section(s) take the following form:
d2a170
diff -up yum-3.4.3/docs/yum-shell.8.orig yum-3.4.3/docs/yum-shell.8
d2a170
--- yum-3.4.3/docs/yum-shell.8.orig	2011-06-28 22:27:22.000000000 +0200
d2a170
+++ yum-3.4.3/docs/yum-shell.8	2017-11-24 20:52:18.483380945 +0100
d2a170
@@ -31,6 +31,12 @@ information. There are a few additional
d2a170
      reset: reset (zero-out) the transaction 
d2a170
      solve: run the dependency solver on the transaction
d2a170
      run: run the transaction 
d2a170
+.IP
d2a170
+.IP "\fBexit\fP"
d2a170
+     Causes the shell to exit, setting the exit status as specified by the
d2a170
+     \fBshell_exit_status\fR option in \fIyum.conf(5)\fR.
d2a170
+     This command is also triggered when EOF is read (usually the C-d keystroke
d2a170
+     or end of script).
d2a170
 
d2a170
 .PP 
d2a170
 .SH "Examples"
d2a170
diff -up yum-3.4.3/shell.py.orig yum-3.4.3/shell.py
d2a170
--- yum-3.4.3/shell.py.orig	2017-11-24 20:52:02.580463129 +0100
d2a170
+++ yum-3.4.3/shell.py	2017-11-24 20:52:18.483380945 +0100
d2a170
@@ -126,6 +126,7 @@ class YumShell(cmd.Cmd):
d2a170
 
d2a170
         :param line: the next line of input
d2a170
         """
d2a170
+        self.result = 0
d2a170
         if len(line) > 0 and line.strip()[0] == '#':
d2a170
             pass
d2a170
         else:
d2a170
@@ -150,7 +151,8 @@ class YumShell(cmd.Cmd):
d2a170
             except Errors.YumBaseError:
d2a170
                 pass
d2a170
             else:
d2a170
-                self.base.doCommands()
d2a170
+                result, _ = self.base.doCommands()
d2a170
+                self.result = result
d2a170
     
d2a170
     def emptyline(self):
d2a170
         """Do nothing on an empty line of input."""
d2a170
@@ -211,13 +213,14 @@ class YumShell(cmd.Cmd):
d2a170
             self.base.shellUsage()
d2a170
         
d2a170
         self.verbose_logger.info(msg)
d2a170
+        self.result = 0
d2a170
         
d2a170
     def do_EOF(self, line):
d2a170
         """Exit the shell when EOF is reached.
d2a170
 
d2a170
         :param line: unused
d2a170
         """
d2a170
-        self.resultmsgs = ['Leaving Shell']
d2a170
+        self.do_exit(line)
d2a170
         return True
d2a170
     
d2a170
     def do_quit(self, line):
d2a170
@@ -225,7 +228,7 @@ class YumShell(cmd.Cmd):
d2a170
 
d2a170
         :param line: unused
d2a170
         """
d2a170
-        self.resultmsgs = ['Leaving Shell']
d2a170
+        self.do_exit(line)
d2a170
         return True
d2a170
     
d2a170
     def do_exit(self, line):
d2a170
@@ -233,6 +236,9 @@ class YumShell(cmd.Cmd):
d2a170
 
d2a170
         :param line: unused
d2a170
         """
d2a170
+        # Make sure we don't go onto the next stage in yummain (result == 2)
d2a170
+        if self.base.conf.shell_exit_status == '0' or self.result == 2:
d2a170
+            self.result = 0
d2a170
         self.resultmsgs = ['Leaving Shell']
d2a170
         return True
d2a170
     
d2a170
@@ -254,6 +260,7 @@ class YumShell(cmd.Cmd):
d2a170
         :param line: the remainder of the line, containing the name of
d2a170
            a subcommand.  If no subcommand is given, run the list subcommand.
d2a170
         """
d2a170
+        self.result = 0
d2a170
         (cmd, args, line) = self.parseline(line)
d2a170
         if cmd in ['list', None]:
d2a170
             self.verbose_logger.log(logginglevels.INFO_2,
d2a170
@@ -267,11 +274,13 @@ class YumShell(cmd.Cmd):
d2a170
                 (code, msgs) = self.base.buildTransaction()
d2a170
             except Errors.YumBaseError, e:
d2a170
                 self.logger.critical('Error building transaction: %s', e)
d2a170
+                self.result = 1
d2a170
                 return False
d2a170
                 
d2a170
             if code == 1:
d2a170
                 for msg in msgs:
d2a170
                     self.logger.critical('Error: %s', msg)
d2a170
+                self.result = 1
d2a170
             else:
d2a170
                 self.verbose_logger.log(logginglevels.INFO_2,
d2a170
                     'Success resolving dependencies')
d2a170
@@ -292,6 +301,7 @@ class YumShell(cmd.Cmd):
d2a170
            value is given, print the current value.  If a value is
d2a170
            supplied, set the option to the given value.
d2a170
         """
d2a170
+        self.result = 0
d2a170
         (cmd, args, line) = self.parseline(line)
d2a170
         # logs
d2a170
         if cmd in ['debuglevel', 'errorlevel']:
d2a170
@@ -305,6 +315,7 @@ class YumShell(cmd.Cmd):
d2a170
                     val = int(val)
d2a170
                 except ValueError:
d2a170
                     self.logger.critical('Value %s for %s cannot be made to an int', val, cmd)
d2a170
+                    self.result = 1
d2a170
                     return
d2a170
                 setattr(self.base.conf, cmd, val)
d2a170
                 if cmd == 'debuglevel':
d2a170
@@ -321,6 +332,7 @@ class YumShell(cmd.Cmd):
d2a170
                 value = opts[0]
d2a170
                 if value.lower() not in BOOLEAN_STATES:
d2a170
                     self.logger.critical('Value %s for %s is not a Boolean', value, cmd)
d2a170
+                    self.result = 1
d2a170
                     return False
d2a170
                 value = BOOLEAN_STATES[value.lower()]
d2a170
                 setattr(self.base.conf, cmd, value)
d2a170
@@ -363,6 +375,7 @@ class YumShell(cmd.Cmd):
d2a170
            a subcommand and other parameters if required.  If no
d2a170
            subcommand is given, run the list subcommand.
d2a170
         """
d2a170
+        self.result = 0
d2a170
         (cmd, args, line) = self.parseline(line)
d2a170
         if cmd in ['list', None]:
d2a170
             # Munge things to run the repolist command
d2a170
@@ -380,7 +393,8 @@ class YumShell(cmd.Cmd):
d2a170
             except Errors.YumBaseError:
d2a170
                 pass
d2a170
             else:
d2a170
-                self.base.doCommands()
d2a170
+                result, _ = self.base.doCommands()
d2a170
+                self.result = result
d2a170
 
d2a170
         elif cmd == 'enable':
d2a170
             repos = self._shlex_split(args)
d2a170
@@ -392,8 +406,10 @@ class YumShell(cmd.Cmd):
d2a170
                     changed = self.base.repos.enableRepo(repo)
d2a170
                 except Errors.ConfigError, e:
d2a170
                     self.logger.critical(e)
d2a170
+                    self.result = 1
d2a170
                 except Errors.RepoError, e:
d2a170
                     self.logger.critical(e)
d2a170
+                    self.result = 1
d2a170
                     
d2a170
                 else:
d2a170
                     for repo in changed:
d2a170
@@ -402,6 +418,7 @@ class YumShell(cmd.Cmd):
d2a170
                         except Errors.RepoError, e:
d2a170
                             self.logger.critical('Disabling Repository')
d2a170
                             self.base.repos.disableRepo(repo)
d2a170
+                            self.result = 1
d2a170
                             return False
d2a170
                             
d2a170
                     self.base.up = None
d2a170
@@ -413,8 +430,10 @@ class YumShell(cmd.Cmd):
d2a170
                     offrepos = self.base.repos.disableRepo(repo)
d2a170
                 except Errors.ConfigError, e:
d2a170
                     self.logger.critical(e)
d2a170
+                    self.result = 1
d2a170
                 except Errors.RepoError, e:
d2a170
                     self.logger.critical(e)
d2a170
+                    self.result = 1
d2a170
 
d2a170
                 else:
d2a170
                     # close the repos, too
d2a170
@@ -432,36 +451,45 @@ class YumShell(cmd.Cmd):
d2a170
         print cmd
d2a170
         print args
d2a170
         print line
d2a170
+        self.result = 0
d2a170
         
d2a170
     def do_run(self, line):
d2a170
         """Run the transaction.
d2a170
 
d2a170
         :param line: unused
d2a170
         """
d2a170
+        self.result = 0
d2a170
         if len(self.base.tsInfo) > 0:
d2a170
             try:
d2a170
                 (code, msgs) = self.base.buildTransaction()
d2a170
                 if code == 1:
d2a170
                     for msg in msgs:
d2a170
                         self.logger.critical('Error: %s', msg)
d2a170
+                    self.result = 1
d2a170
                     return False
d2a170
 
d2a170
                 returnval = self.base.doTransaction()
d2a170
             except Errors.YumBaseError, e:
d2a170
                 self.logger.critical('Error: %s', e)
d2a170
+                self.result = 1
d2a170
             except KeyboardInterrupt, e:
d2a170
                 self.logger.critical('\n\nExiting on user cancel')
d2a170
+                self.result = 1
d2a170
             except IOError, e:
d2a170
                 if e.errno == 32:
d2a170
                     self.logger.critical('\n\nExiting on Broken Pipe')
d2a170
+                self.result = 1
d2a170
             else:
d2a170
                 if returnval not in [0,1,-1]:
d2a170
                     self.verbose_logger.info('Transaction encountered a serious error.')
d2a170
+                    self.result = 1
d2a170
                 else:
d2a170
                     if returnval == 1:
d2a170
                         self.verbose_logger.info('There were non-fatal errors in the transaction')
d2a170
+                        self.result = 1
d2a170
                     elif returnval == -1:
d2a170
                         self.verbose_logger.info("Transaction didn't start")
d2a170
+                        self.result = 1
d2a170
                     self.verbose_logger.log(logginglevels.INFO_2,
d2a170
                         'Finished Transaction')
d2a170
                 self.base.closeRpmDB()
d2a170
diff -up yum-3.4.3/yum/config.py.orig yum-3.4.3/yum/config.py
d2a170
--- yum-3.4.3/yum/config.py.orig	2017-11-24 20:52:02.648462776 +0100
d2a170
+++ yum-3.4.3/yum/config.py	2017-11-24 20:52:18.484380940 +0100
d2a170
@@ -931,6 +931,8 @@ class YumConf(StartupConf):
d2a170
 
d2a170
     usr_w_check = BoolOption(True)
d2a170
 
d2a170
+    shell_exit_status = SelectionOption('0', ('0', '?'))
d2a170
+
d2a170
     _reposlist = []
d2a170
 
d2a170
     def dump(self):