done some rebranding from pkg -> pck
[opensuse:pack-tools.git] / pck
1 #!/bin/bash
2 #pkg - master command by dlovasko@suse.com
3
4 #un/comment for debug/release
5 #set -x
6
7 function pkg_help
8 {
9         echo "master command for packaging utilities"
10         echo "try pck --list for list of subcommands"
11         exit 1
12 }
13
14 function pkg_list
15 {
16         echo "pck subcommand list:"
17         echo "  fastre:unpack sources, build quilt series and apply patches"
18         echo "  clean:tries to find out-of-date projects and report that"
19         echo "  spec:specfile management - get/set tags, merge conflicting specfile, add patch"
20         echo "  getpac:download packages for all or only some products, delete unwanted before checkout"
21         echo "  patchinfo:fixed patchinfo, opens editor every time"
22         echo "  clean:recursive submit request - first submit to devel project and if everything goes well, submit to factory"
23         exit 1
24 }
25
26 #check for 0 args, then print help
27 if [ "$#" = "0" ] 
28 then
29         pkg_help
30 fi
31
32 #run thru all the args, find first one which is subcommand
33 for i in `seq $#`
34 do
35         if echo ${!i} | grep -qv '^-'
36         then
37                 subcommand=${!i}
38                 break
39         fi
40 done
41
42 #i now contains index in $@ of subcommand
43 let k=i-1
44 verbose=no
45
46 #save arguments for subcommand
47 if [ -n "$subcommand" ] 
48 then
49 #FIXME: this breaks escaped arguments - like 'foo "x y"' will end in two arguments 'x' and 'y'
50         subargs=${@:$i:$#}
51 else
52         let k=i
53 fi
54
55 #prepare arguments
56 eval set -- `getopt -a -o v --long verbose -o l --long list  -o h --long 'help' -- "${@:1:$k}"`
57
58 #process arguments for master command
59 while [ -n "$1" ]
60 do
61         case $1 in
62                 -v|--verbose)
63                         verbose=yes
64                         shift
65                 ;;
66                 -l|--list)
67                         pkg_list
68                 ;;
69                 -h|--help)
70                         pkg_help
71                 ;;
72                 --)
73                         break
74                 ;;
75         esac
76 done
77
78 #check if any subcommand
79
80 #echo "'$subargs'"
81 if [ -z "$subargs" ] 
82 then 
83         exit 0
84 fi
85
86 #check if the subcommand exists
87 curpath=$(readlink -f $0)
88 prefix=${curpath%/*}
89
90 if [[ ${prefix} =~ ^/usr ]]
91 then
92     libexecdir="${prefix}/lib/pack-tools/commands/"
93 else
94     libexecdir="${prefix}/commands/"
95 fi
96
97 if [[ ! -e ${libexecdir}/${subcommand} ]]; then
98     echo "ERROR: $subcommand does not exists, try ${0} --list for help"
99     exit 1
100 fi
101
102 exec ${libexecdir}${subargs}