~vcs-imports-ii/gsrc/trunk

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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
# -*- coding: utf-8 -*-
#
#       gsrc
#       
#       Copyright © 2012, 2013, 2014 Brandon Invergo <brandon@invergo.net>
#       
#       This file is part of GSRC.
#
#       GSRC is free software: you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation, either version 3 of the License, or
#       (at your option) any later version.
#
#       GSRC is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with GSRC.  If not, see <http://www.gnu.org/licenses/>.

# This is a convenience script primarily aimed at facilitating the
# discovery of GSRC packages.  Thus, there are functions for searching
# by keyword(s), displaying information on a package, and then getting
# the path to the package so you can easily install it, view its
# source code, etc.  This script is rather simple, so it is
# straight-forward to extend it by wrapping more GSRC functionality
# with it.  Put this script somewhere in your PATH so you can access
# GSRC (and BioSRC) from any directory.

GSRCDIR=@abs_srcdir@
MAKE_ARGS="-s USE_COLOR=y"

print_usage () {
cat <<EOF
Usage: gsrc [info|path|search] [PACKAGE|TERMS]
Install, uninstall and discover info about GSRC packages
    
  info        display info about PACKAGE
  path        display the path to PACKAGE
  search      search for packages relevant to TERMS
  install     install PACKAGE
  uninstall   uninstall PACKAGE
  remove      completely remove PACKAGE
  update      update PACKAGE
    
PACKAGE names may be passed with or without their project dirname (i.e.
both 'pkg/gnu/hello' and 'hello' are fine). 

Searches are performed using extended regular expressions. See the 
'grep' documentation for more information. A list of packages matching 
any of the TERMS will be displayed.

Report bugs to: bug-gsrc@gnu.org
GSRC home page: <http://www.gnu.org/software/gsrc/>
General help using GNU software: <http://www.gnu.org/gethelp/>
EOF
}
#DIRS="gnu,gnustep,gnualpha,gnome,freedesktop,gstreamer,other,bio,local,deps,libs,tools"
DIRS=gnu,gnustep,gnualpha,gnome,freedesktop,gstreamer,other,bio

get_pkg_path () {
    if [ -d $GSRCDIR/$1 ]; then
	pkg_path=$GSRCDIR/$1
    else
	for dir in pkg/{gnu,gnustep,gnualpha,gnome,freedesktop,gstreamer,other,bio}; do
	    p=$GSRCDIR/$dir/$1
	    if [ -d $p ]; then
		pkg_path=$p
		break
	    fi
	done
    fi
    if [[ "x$pkg_path" == "x" ]]; then
	echo "Package '$1' does not exist"
	exit 1
    fi
}

do_install () {
    get_pkg_path $1
    make $MAKE_ARGS -C $pkg_path install
}

do_uninstall () {
    get_pkg_path $1
    make $MAKE_ARGS -C $pkg_path uninstall
}

do_remove () {
    get_pkg_path $1
    do_uninstall $1
    make $MAKE_ARGS -C $pkg_path uninstall-pkg
} 

do_update () {
    get_pkg_path $1
    make $MAKE_ARGS -C $pkg_path update
}

do_info () {
    get_pkg_path $1
    make $MAKE_ARGS -C $pkg_path pkg-info 
}

do_search () {
    terms=""
    for term in $@; do
	terms="$terms -e$term"
    done
    # This is insane and stupid and slow.
    # My kingdom for a grep option that restricts the search to the 
    # first N lines so I can do this:
    # grep -E -q i $terms ${GSRCDIR}/{bio,libs,tools}/*/Makefile
    for pkg in ${GSRCDIR}/pkg/{gnu,gnustep,gnualpha,gnome,freedesktop,gstreamer,other,bio}/*; do
	sed "/GARVERSION/d;/PATCHNUM/d;/HOME_URL/d;/^#/d;/^#####$/q" $pkg/Makefile | \
	    grep -E -q -i $terms && \
	    (make $MAKE_ARGS -C $pkg pkg-info-curt)
    done
}

if [ $# -lt 2 ]; then
    print_usage
    exit 1
fi

case $1 in
    install)
        do_install $2 ;;
    uninstall)
        do_uninstall $2 ;;
    remove)
        do_remove $2 ;;
    update)
        do_update $2 ;;
    info)
	    do_info $2 ;;
    path)
	    get_pkg_path $2
	    echo $pkg_path ;;
    search)
	    shift
	    do_search $@ ;;
    *)
	    print_usage
	    exit 1 ;;
esac
exit 0