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

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