Merge branch 'martin-t/server.cfg' into 'master'
[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 case "$0" in
23         /*/all)
24                 export d0=${0%/all}
25                 ;;
26         */all)
27                 export d0=$d00/${0%/all}
28                 ;;
29         *)
30                 $ECHO "Cannot find myself."
31                 $ECHO "Please run this script with the working directory inside a Xonotic checkout."
32                 ;;
33 esac
34 cd "$d0"
35 d0=`pwd`
36 SELF="$d0/all"
37
38 # If we are on WINDOWS:
39 case "$0" in
40         all|*/all)
41                 case "`uname`" in
42                         MINGW*|Win*)
43                                 # Windows hates users. So this script has to copy itself elsewhere first...
44                                 cp "$SELF" ../all.xonotic.sh
45                                 export WE_HATE_OUR_USERS=1
46                                 exec ../all.xonotic.sh "$@"
47                                 ;;
48                 esac
49                 ;;
50 esac
51
52 msg()
53 {
54         $ECHO >&2 "$ESC""[1m$*$ESC""[m"
55 }
56
57 self=`git hash-object "$SELF"`
58 checkself()
59 {
60         self_new=`git hash-object "$SELF"`
61         if [ x"$self" != x"$self_new" ]; then
62                 msg "./all has changed."
63                 if [ -z "$XONOTIC_FORBID_RERUN_ALL" ]; then
64                         msg "Rerunning the requested operation to make sure."
65                         export XONOTIC_FORBID_RERUN_ALL=1
66                         exec "$SELF" "$@"
67                 else
68                         msg "Please try $SELF update, and then retry your requested operation."
69                         exit 1
70                 fi
71         fi
72         return 0
73 }
74
75 verbose()
76 {
77         msg "+ $*"
78         "$@"
79 }
80
81 yesno()
82 {
83         yesno=
84         while [ x"$yesno" != x"y" -a x"$yesno" != x"n" ]; do
85                 eval "$2"
86                 $ECHO "$1"
87                 if ! IFS= read -r yesno; then
88                         yesno=n
89                         break
90                 fi
91         done
92         [ x"$yesno" = x"y" ]
93 }
94
95 enter()
96 {
97         $2 cd "$1" || exit 1
98         check_mergeconflict "$1" # defined in git.subr
99 }
100
101 if [ "$#" = 0 ]; then
102         set -- help
103 fi
104 cmd=$1
105 shift
106
107 # project config
108 . "$d0/misc/tools/all/config.subr"
109
110 # shared commands
111 handled=false
112 . "$d0/misc/tools/all/git.subr" "$@"
113
114 # optional modules
115 $handled || . "$d0/misc/tools/all/release.subr" "$@"
116 $handled || . "$d0/misc/tools/all/xonotic.subr" "$@"
117
118 if ! $handled; then
119         if [ x"$cmd" != x"help" ]; then
120                 $ECHO "Run $SELF help for help."
121                 exit 1
122         fi
123 fi