22
33if [ ! -f lib/lib.sh ]
44then
5- echo " Error: lib/lib.sh not found!"
6- echo " make sure you are in the root of the server repo"
7- exit 1
5+ echo " Error: lib/lib.sh not found!"
6+ echo " make sure you are in the root of the server repo"
7+ exit 1
88fi
99
1010source lib/lib.sh
@@ -17,53 +17,53 @@ PROC="$$"
1717
1818# used to kill script from subshell
1919fatal (){
20- echo " $@ " >&2
21- kill -10 $PROC
20+ echo " $@ " >&2
21+ kill -10 $PROC
2222}
2323
2424function handle_error() {
25- if [ " $IGNORE_ERR " == " yes" ] || [ " $IGNORE_ERR " == " 1" ]
26- then
27- return
28- fi
29- echo " got a non zero exit code. Do you want to proceed? [y/N]"
30- read -n 1 -rp " " inp
31- echo " "
32- if ! [[ $inp =~ ^[Yy]$ ]]
33- then
34- fatal " Aborting script..."
35- fi
25+ if [ " $IGNORE_ERR " == " yes" ] || [ " $IGNORE_ERR " == " 1" ]
26+ then
27+ return
28+ fi
29+ echo " got a non zero exit code. Do you want to proceed? [y/N]"
30+ read -n 1 -rp " " inp
31+ echo " "
32+ if ! [[ $inp =~ ^[Yy]$ ]]
33+ then
34+ fatal " Aborting script..."
35+ fi
3636}
3737
3838if [ " $# " == " 0" ] || [ " $1 " == " --help" ] || [ " $1 " == " -h" ]
3939then
40- echo " usage: $( basename " $0 " ) <shell command>"
41- echo " parameters:"
42- echo " --help shows this help"
43- echo " --file edit command tmp in file"
44- echo " description:"
45- echo " it goes one directory up and searches server dirs"
46- echo " if a .git/ lib/ lib/lib.sh and server.cnf is found"
47- echo " it will navigate to the directory and there"
48- echo " it will execute <shell command>"
49- echo " enviroment var:"
50- echo " if any of the shell commands returned a non zero exit code"
51- echo " the user will be asked to abort the script"
52- echo " to ignore this warning set the IGNORE_ERR var to 1"
53- echo " example:"
54- echo " $( basename " $0 " ) ./stop.sh;./update.sh;./start.sh"
55- echo " IGNORE_ERR=1 $( basename " $0 " ) /usr/bin/nonzero.sh"
56- exit 0
40+ echo " usage: $( basename " $0 " ) <shell command>"
41+ echo " parameters:"
42+ echo " --help shows this help"
43+ echo " --file edit command tmp in file"
44+ echo " description:"
45+ echo " it goes one directory up and searches server dirs"
46+ echo " if a .git/ lib/ lib/lib.sh and server.cnf is found"
47+ echo " it will navigate to the directory and there"
48+ echo " it will execute <shell command>"
49+ echo " environment var:"
50+ echo " if any of the shell commands returned a non zero exit code"
51+ echo " the user will be asked to abort the script"
52+ echo " to ignore this warning set the IGNORE_ERR var to 1"
53+ echo " example:"
54+ echo " $( basename " $0 " ) ./stop.sh;./update.sh;./start.sh"
55+ echo " IGNORE_ERR=1 $( basename " $0 " ) /usr/bin/nonzero.sh"
56+ exit 0
5757elif [ " $1 " == " --script" ] || [ " $1 " == " --file" ]
5858then
59- is_file=1
60- if [ ! -f " $tmp_file " ]
61- then
62- echo " #!/bin/bash" > " $tmp_file "
63- fi
64- edit_file " $tmp_file "
65- chmod +x " $tmp_file "
66- fi
59+ is_file=1
60+ if [ ! -f " $tmp_file " ]
61+ then
62+ echo " #!/bin/bash" > " $tmp_file "
63+ fi
64+ edit_file " $tmp_file "
65+ chmod +x " $tmp_file "
66+ fi
6767
6868check_server_dir
6969
@@ -72,40 +72,40 @@ shell_command="$*"
7272echo " Found the following server directorys:"
7373for d in ../* /
7474do
75- (
76- cd " $d " || exit 1
77- check_server_dir > /dev/null 2>&1
78- echo " $d "
79- )
75+ (
76+ cd " $d " || exit 1
77+ check_server_dir > /dev/null 2>&1
78+ echo " $d "
79+ )
8080done
8181
8282echo " "
8383if [ " $is_file " == " 1" ]
8484then
85- echo " script:"
86- cat " $tmp_file "
87- shell_command=" $tmp_file "
85+ echo " script:"
86+ cat " $tmp_file "
87+ shell_command=" $tmp_file "
8888else
89- echo -e " shell_command=\\ 033[1m$shell_command \\ 033[0m"
89+ echo -e " shell_command=\\ 033[1m$shell_command \\ 033[0m"
9090fi
9191echo " Do you want to execute it in all these directorys? [y/N]"
9292read -n 1 -rp " " inp
9393echo " "
9494if ! [[ $inp =~ ^[Yy]$ ]]
9595then
96- echo " Aborting script..."
97- exit
96+ echo " Aborting script..."
97+ exit
9898fi
9999
100100for d in ../* /
101101do
102- (
103- cd " $d " || exit 1
104- check_server_dir > /dev/null 2>&1
105- figlet " $d "
106- echo -e " navigating to: \\ 033[1m$( pwd) \\ 033[0m"
107- echo -e " executing: \\ 033[1m$shell_command \\ 033[0m"
108- bash -c " set -euo pipefail;$shell_command " || handle_error
109- )
102+ (
103+ cd " $d " || exit 1
104+ check_server_dir > /dev/null 2>&1
105+ figlet " $d "
106+ echo -e " navigating to: \\ 033[1m$( pwd) \\ 033[0m"
107+ echo -e " executing: \\ 033[1m$shell_command \\ 033[0m"
108+ bash -c " set -euo pipefail;$shell_command " || handle_error
109+ )
110110done
111111
0 commit comments