forked from appmgr/appmgr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp
executable file
·95 lines (81 loc) · 1.57 KB
/
app
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
#!/bin/bash -e
usage_text() {
echo "usage: $usage_app [-C <path>] [-h] [-D] <command>"
echo ""
echo "Available porcelain commands:"
grep_path "/app-.*$" "$APPMGR_HOME/bin" | \
sed "s,^.*/app-, ," | \
sort -n
echo ""
echo "Available plumbing commands:"
grep_path "/app-.*$" "$APPMGR_HOME/lib/appmgr" | \
sed "s,^.*/app-, ," | \
sort -n
}
PRG="$0"
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
APPMGR_HOME=`dirname "$PRG"`
APPMGR_HOME=`cd "$APPMGR_HOME" && pwd`
. $APPMGR_HOME/share/appmgr/common
echo_debug=no
newpath=""
while getopts ":hC:D" opt
do
case $opt in
h)
show_help
;;
C)
newpath="$OPTARG"
eval OPTIND=$((OPTIND-2))
shift
shift
;;
D)
echo_debug=yes
eval OPTIND=$((OPTIND-1))
shift
;;
*)
break
;;
esac
done
if [ $# -eq 0 ]
then
usage
fi
if [[ $newpath != "" ]]
then
if [[ ! -d $newpath ]]
then
echo "No such directory: $newpath" 2>&1
exit 1
fi
cd "$newpath"
fi
command=$1; shift
bin=`grep_path "/app-$command$" "$APPMGR_HOME/bin"`
if [ ! -x "$bin" ]
then
bin=`grep_path "/app-$command$" "$APPMGR_HOME/lib/appmgr"`
if [ ! -x "$bin" ]
then
echo "Unknown command: $command" 2>&1
exit 1
fi
fi
PATH=$APPMGR_HOME/bin:$PATH
# TODO: this is probably a good place to clean up the environment
exec env \
"APPMGR_HOME=$APPMGR_HOME" \
"echo_debug=$echo_debug" \
"$bin" "$@"