Block another "best" server
[xonotic/xonotic.git] / all
1 #!/bin/sh
2 # vim: filetype=zsh
3
4 set -e
5 if [ -n "$ZSH_VERSION" ]; then
6         setopt SH_WORD_SPLIT
7 fi
8 if [ -z "$ECHO" ]; then
9         if echo "\\\\" | grep .. >/dev/null; then
10                 ECHO=echo
11         else
12                 ECHO=`which echo`
13         fi
14 fi
15
16 # I use this in EVERY shell script ;)
17 LF="
18 "
19 ESC="\e"
20
21 d00=`pwd`
22 while ! [ -f ./all ]; do
23         if [ x"`pwd`" = x"/" ]; then
24                 $ECHO "Cannot find myself."
25                 $ECHO "Please run this script with the working directory inside a Xonotic checkout."
26                 exit 1
27         fi
28         cd ..
29 done
30 export d0=`pwd`
31 SELF="$d0/all"
32
33 # If we are on WINDOWS:
34 case "$0" in
35         all|*/all)
36                 case "`uname`" in
37                         MINGW*|Win*)
38                                 # Windows hates users. So this script has to copy itself elsewhere first...
39                                 cp "$SELF" ../all.xonotic.sh
40                                 export WE_HATE_OUR_USERS=1
41                                 exec ../all.xonotic.sh "$@"
42                                 ;;
43                 esac
44                 ;;
45 esac
46
47 msg()
48 {
49         $ECHO >&2 "$ESC""[1m$*$ESC""[m"
50 }
51
52 self=`git hash-object "$SELF"`
53 checkself()
54 {
55         self_new=`git hash-object "$SELF"`
56         if [ x"$self" != x"$self_new" ]; then
57                 msg "./all has changed."
58                 if [ -z "$XONOTIC_FORBID_RERUN_ALL" ]; then
59                         msg "Rerunning the requested operation to make sure."
60                         export XONOTIC_FORBID_RERUN_ALL=1
61                         exec "$SELF" "$@"
62                 else
63                         msg "Please try $SELF update, and then retry your requested operation."
64                         exit 1
65                 fi
66         fi
67         return 0
68 }
69
70 verbose()
71 {
72         msg "+ $*"
73         "$@"
74 }
75
76 yesno()
77 {
78         yesno=
79         while [ x"$yesno" != x"y" -a x"$yesno" != x"n" ]; do
80                 eval "$2"
81                 $ECHO "$1"
82                 if ! IFS= read -r yesno; then
83                         yesno=n
84                         break
85                 fi
86         done
87         [ x"$yesno" = x"y" ]
88 }
89
90 enter()
91 {
92         $2 cd "$1" || exit 1
93         check_mergeconflict "$1" # defined in git.subr
94 }
95
96 if [ "$#" = 0 ]; then
97         set -- help
98 fi
99 cmd=$1
100 shift
101
102 # project config
103 . "$d0/misc/tools/all/config.subr"
104
105 # shared commands
106 handled=false
107 . "$d0/misc/tools/all/git.subr" "$@"
108
109 # optional modules
110 $handled || . "$d0/misc/tools/all/release.subr" "$@"
111 $handled || . "$d0/misc/tools/all/xonotic.subr" "$@"
112
113 if ! $handled; then
114         if [ x"$cmd" != x"help" ]; then
115                 $ECHO "Run $SELF help for help."
116                 exit 1
117         fi
118 fi