Implements full path for hash checks of binaries
[releng-anteater.git] / utils / get-patch.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2017 Luke Hinds <lhinds@redhat.com>, Red Hat
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 GERRITUSER="lukehinds"
12 REPO_DIR="/home/luke/repos/opnfv"
13 FORMATED_DIR=$(echo $REPO_DIR |sed 's./.\\/.g')
14
15 help (){
16 echo ""
17 echo -e "A script to generate a patchset file to allow local anteater tests"
18 echo -e "in the same manner as OPNFV security audit gate checks.\n"
19 echo -e "Please insure GERRITUSER and REPO_DIR are set within the script\n"
20 echo -e "You will also need to pass the following arguments.\n"
21 echo -e "--project <project>\n"
22 echo -e "for example:"
23 echo -e "--project releng\n"
24 echo -e "    * note that the project name has to be the same as the git"
25 echo -e "      repository name for the project\n"
26 echo -e "--patch <patch_number>\n"
27 echo -e "for example:"
28 echo -e "--patch 39741\n"
29 echo -e "    * note that the patchset can be retrieved from the URL,"
30 echo -e "      e.g https://gerrit.opnfv.org/gerrit/#/c/39741/\n"
31 echo -e "The above would create the patch set as /tmp/patchset_39741\n"
32 echo -e "You will then be able to run anteater as follows:"
33 echo -e "$ anteater --project sandbox --patchset /tmp/patchset_39741"
34 exit
35 }
36
37 # GetOpts
38
39 usage() {
40     echo "Usage: $0 [--project <project>] [--patch <patch_number>] [--help>]" 1>&2; exit 1;
41 }
42
43 for arg in "$@"; do
44   shift
45   case "$arg" in
46     "--project") set -- "$@" "-p" ;;
47     "--patch") set -- "$@" "-n" ;;
48     "--help") set -- "$@" "-h" ;;
49     *)        set -- "$@" "$arg"
50   esac
51 done
52
53
54 while getopts ":p:n:h" arg; do
55     case "${arg}" in
56         p)
57             p=${OPTARG}
58             ;;
59         n)
60             n=${OPTARG}
61             ;;
62         h)
63             help
64             ;;
65         *)
66             usage
67             ;;
68     esac
69 done
70 shift $((OPTIND-1))
71
72
73 if [ -z "${p}" ] || [ -z "${n}" ]; then
74     usage
75 fi
76
77 ssh -p 29418 ${GERRITUSER}@gerrit.opnfv.org gerrit query \
78     --current-patch-set ${n} \
79     --files|grep file:|sed 's/file:\s\/COMMIT_MSG//;s/file://'| \
80     sed '/^\s*$/d'| \
81     sed -e "s/^/${FORMATED_DIR}\/${p}\//"| tr -d " \t\r" \
82     > /tmp/patchset_${n}
83
84 echo -e "Patchset created as /tmp/patchset_${n}"
85 echo -e "You can now run: $ anteater --project ${p} --patchset /tmp/patchset_${n}"