Fix rtd merge job to handle new tag uploaded
[releng/global-jjb.git] / shell / sudo-logs.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2019 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 echo "---> sudo-logs.sh"
12
13 set -eu -o pipefail -o noglob
14
15 # Copy/Generate 'sudo' log and copy to archive directory
16 function copy_log()
17 {
18     case $os in
19         fedora|centos|redhat|ubuntu|debian)
20             if ! sudo cp $sudo_log /tmp; then
21                 echo "Unable to archive 'sudo' logs ($sudo_log)"
22                 return
23             fi
24             ;;
25         suse)
26             # Do I need 'sudo' to run 'journalctl'?
27             journalctl | grep sudo > $sudo_log
28             ;;
29         *)  echo "Unexpected 'operatingsystem': $os"
30             exit 1
31             ;;
32     esac
33     sudo_log=$(basename $sudo_log)
34     sudo chown jenkins:jenkins /tmp/$sudo_log
35     chmod 0644 /tmp/$sudo_log
36     mkdir -p $WORKSPACE/archives/sudo
37     mv /tmp/$sudo_log $WORKSPACE/archives/sudo/$sudo_log
38
39 }    # End copy_log()
40
41 echo "Archiving 'sudo' log.."
42 os=$(facter operatingsystem | tr '[:upper:]' '[:lower:]')
43 case $os in
44     fedora|centos|redhat) sudo_log=/var/log/secure   ;;
45     ubuntu|debian)        sudo_log=/var/log/auth.log ;;
46     suse)                 sudo_log=/tmp/sudo.log     ;;
47     *)  echo "Unexpected 'operatingsystem': $os"
48         exit 1
49         ;;
50 esac
51
52 copy_log