forked from gratipay/gratipay.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
payday.sh
executable file
·103 lines (85 loc) · 2.27 KB
/
payday.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/sh
# Fail on error.
# ==============
set -e
# Be somewhere predictable.
# =========================
cd "`dirname $0`"
# --help
# ======
if [ $# = 0 ]; then
echo
echo "Usage: $0 <number> [\"for_real_please\"]"
echo
echo " This is a payday wrapper script for Gittip. It runs payday, logging to a file."
echo " You must pass at least one argument, a small integer indicating which week of "
echo " Gittip you are running (it's only used to decide where to log). If you pass a"
echo " second arg then it must be the string \"for_real_please\", and in that case we"
echo " try to run against the production database. Without that string we run using "
echo " your local.env configuration."
echo
echo " Payday is designed such that you can rerun it if it fails. In particular, it "
echo " will append to the log (not overwrite it)."
echo
exit
fi
# Helpers
# =======
confirm () {
proceed=""
while [ "$proceed" != "y" ]; do
read -p"$1 (y/N) " proceed
if [ "$proceed" == "n" -o "$proceed" == "N" -o "$proceed" == "" ]
then
return 1
fi
done
return 0
}
require () {
if [ ! `which $1` ]; then
echo "The '$1' command was not found."
return 1
fi
return 0
}
start () {
echo "Logging to $LOG."
echo >> $LOG
date -u >> $LOG
}
# Work
# ====
if [ "$2" == "for_real_please" ]; then
LOG="../paydays/gittip-$1.log"
else
LOG="../paydays/test-$1.log"
fi
if [ -f $LOG ]; then
RUN="Rerun"
else
# If the path is bad the next line will fail and we'll exit.
touch $LOG
RUN="Run"
fi
if [ $1 ]; then
require foreman
confirm "$RUN payday #$1?"
if [ $? -eq 0 ]; then
if [ "$2" == "" ]; then
start
foreman run -e local.env ./env/bin/payday >> $LOG 2>&1
else
if [ "$2" == "for_real_please" ]; then
confirm "$RUN payday #$1 FOR REAL?!?!?!??!?!?"
if [ $? -eq 0 ]; then
start
heroku config -s | foreman run -e /dev/stdin \
./env/bin/payday >> $LOG 2>&1
fi
else
echo "Your second arg was $2. Wazzat mean?"
fi
fi
fi
fi