-
Notifications
You must be signed in to change notification settings - Fork 27
/
devfile-command
executable file
·72 lines (64 loc) · 1.82 KB
/
devfile-command
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
#!/bin/sh
set -e
# possible parameters
CMD_RUN=devrun
CMD_DEBUG=debugrun
usage(){
echo ""
echo "This script only accepts the following parameters:"
echo ""
echo "$CMD_RUN"
echo "$CMD_DEBUG"
echo ""
}
runCommand(){
# test if project directory is empty. If so, nothing to run
# command is also valid whan env variable is empty
# Need to execute commands this way in order for variable substitution to work
if [ -z "$(sh -c "ls -A $ODO_COMMAND_RUN_WORKING_DIR")" ]; then
return
fi
if [ -z "$ODO_COMMAND_RUN" ]; then
echo "ODO_COMMAND_RUN is not set";
else
CMD=""
echo "ODO_COMMAND_RUN is $ODO_COMMAND_RUN";
if [ ! -z $ODO_COMMAND_RUN_WORKING_DIR ]; then
echo "Changing directory to $ODO_COMMAND_RUN_WORKING_DIR";
CMD="cd $ODO_COMMAND_RUN_WORKING_DIR &&"
fi
CMD="$CMD $ODO_COMMAND_RUN"
echo "Executing command $CMD"
# Need to execute commands this way in order for variable substitution to work
sh -c "$CMD"
fi
}
debugCommand(){
if [ -z "$ODO_COMMAND_DEBUG" ]; then
echo "ODO_COMMAND_DEBUG is not set";
else
CMD=""
echo "ODO_COMMAND_DEBUG is $ODO_COMMAND_DEBUG";
if [ ! -z $ODO_COMMAND_DEBUG_WORKING_DIR ]; then
echo "Changing directory to $ODO_COMMAND_DEBUG_WORKING_DIR";
CMD="cd $ODO_COMMAND_DEBUG_WORKING_DIR &&"
fi
CMD="$CMD $ODO_COMMAND_DEBUG"
echo "Executing command $CMD"
# Need to execute commands this way in order for variable substitution to work
sh -c "$CMD"
fi
}
case $1 in
$CMD_RUN)
runCommand
;;
$CMD_DEBUG)
debugCommand
;;
*)
echo "ERROR: unexpected parameter \"$1\""
usage
exit 1
esac
shift