]> Pileus Git - ~andy/sunrise/blob - scripts/review
add missing die
[~andy/sunrise] / scripts / review
1 #!/bin/bash
2 # review - Move a certain revision from sunrise/ to reviewed/
3 # Released into the public domain
4
5 source /etc/init.d/functions.sh
6
7 BLUE=$'\033[34;01m'
8 BOLD=$'\e[0;01m'
9 DARKGREEN=$'\e[32m'
10 GREEN=$'\e[32;01m'
11 LIGHTBLUE=$HILITE
12 RED=$'\033[31;01m'
13 YELLOW=$'\033[33;01m'
14 opt_norepoman=0
15 opt_noupdate=0
16 opt_quiet=0
17 opt_verbose=0
18
19 DIFF="${DIFF:-diff}"
20 DIFF_OPTS="${DIFF_OPTS:--Nur}"
21
22 repoman_check() {
23         if [[ "$opt_norepoman" == "0" ]] ; then
24                 ebegin "Running repoman"
25                 export PORTDIR_OVERLAY="$(pwd)"
26                 repoman
27                 eend $?
28                 return $?
29         fi
30 }
31
32 usage() {
33 cat << EOF
34 ${BOLD}Usage:${NORMAL} ${LIGHTBLUE}$0${NORMAL} [ ${GREEN}options${NORMAL} ] ${BLUE}revision${NORMAL}
35
36 ${GREEN}options${NORMAL}:
37   ${BOLD}--help, -h${NORMAL}       Show help
38   ${BOLD}--norepoman, -p${NORMAL}  Skip repoman check
39   ${BOLD}--noupdate, -d${NORMAL}   Don't update from repository before committing
40   ${BOLD}--quiet, -q${NORMAL}      Don't ask for confirmation
41   ${BOLD}--verbose, -v${NORMAL}    Show detailed information during commit
42 EOF
43         exit ${1:-0}
44 }
45
46 while [[ $# > 0 ]] ; do
47         case "$1" in
48                 --help|-h)
49                         usage ;;
50
51                 --norepoman|-p)
52                         opt_norepoman=1
53                         shift ;;
54
55                 --noupdate|-d)
56                         opt_noupdate=1
57                         shift ;;
58
59                 --quiet|-q)
60                         opt_quiet=1
61                         shift ;;
62
63                 --verbose|-v)
64                         opt_verbose=1
65                         shift ;;
66
67                 -*)
68                         echo "!!! Error: Unknown option ${1}. See: $0 -h"
69                         exit 1 ;;
70
71                 *)
72                         break ;;
73         esac
74 done
75
76 LC_ALL="C" ls -d *-* > profiles/categories
77 if [[ $(git diff profiles/categories) ]]; then
78         git diff profiles/categories | if [[ "$opt_quiet" == "0" ]] ; then less; else cat; fi
79         echo -n "${BOLD}Commit changes?${NORMAL} [${GREEN}Yes${NORMAL}/${RED}No${NORMAL}] "
80         read choice
81         echo
82         case "$choice" in
83                 y*|Y*|"")
84                         git commit -m "Automatic update to categories" profiles/categories || exit 1
85                         ;;
86                 *)
87                         echo "Quitting."
88                         echo
89                         exit ;;
90         esac
91 fi
92
93 egencache --ignore-default-opts --portdir-overlay=. \
94         --repo=sunrise --update-use-local-desc || exit $?
95
96 if [[ $(git diff profiles/use.local.desc) ]]; then
97         git diff profiles/use.local.desc | if [[ "$opt_quiet" == "0" ]] ; then less; else cat; fi
98         echo -n "${BOLD}Commit changes?${NORMAL} [${GREEN}Yes${NORMAL}/${RED}No${NORMAL}] "
99         read choice
100         echo
101         case "$choice" in
102                 y*|Y*|"")
103                         git commit -m "Automatic update to use.local.desc" profiles/use.local.desc || exit 1
104                         ;;
105                 *)
106                         echo "Quitting."
107                         echo
108                         exit ;;
109         esac
110 fi
111
112 ebegin "Updating working copy to latest version from repository"
113 git pull --rebase
114
115 (
116 repoman_check || exit $?
117
118 ebegin "Running portdupe"
119 scripts/portdupe
120 eend $?
121
122 if [[ "$opt_quiet" == "0" ]] ; then
123         git diff reviewed/master master
124 fi
125 ) | if [[ "$opt_quiet" == "0" ]] ; then less; else cat; fi
126
127 if [[ "$opt_quiet" == "0" ]] ; then
128         echo
129         echo -n "${BOLD}Commit changes?${NORMAL} [${GREEN}Yes${NORMAL}/${RED}No${NORMAL}] "
130         read choice
131         echo
132
133         case "$choice" in
134                 y*|Y*|"")
135                         ;;
136
137                 *)
138                         echo "Quitting."
139                         echo
140                         exit ;;
141         esac
142 fi
143
144 ebegin "Pushing changes..."
145 if [[ "$opt_verbose" == "1" ]] ; then
146         git push -v origin master
147         git push -v reviewed master
148 else
149         git push origin master
150         git push reviewed master
151 fi
152 eend ${?}