~fauli/g-ctan/2010

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
#!/bin/bash
# Copyright 2008-2010
# Distributed under the terms of the GNU General Public License v3.
# This file is part of the g-CTAN package.

# Author:
# Christian Faulhammer <fauli@gentoo.org>

VERSION=2009.1_pre
COMMONDIR=/usr/share

source /etc/g-ctan/g-ctan.conf

source "${COMMONDIR}"/g-ctan/options
source "${COMMONDIR}"/g-ctan/common
source "${COMMONDIR}"/g-ctan/fetch
source "${COMMONDIR}"/g-ctan/ebuild

get_packages() {
    set_up
    get_package_database
    create_package_list
}

show_available_packages() {
    if [ -e "${TLPDBDIR}"/package.names ]
    then
	sed -e '/^[0-9]*$/d' "${TLPDBDIR}"/package.names | ${G_PAGER}
	exit 0
    else
	failure "No name database found, please execute ${0} --get-packages first."
	exit 40
    fi
}

create_ebuild() {
    check_availability
    if [[ "$?" == "30" ]]
    then
	failure "${PN} is not known to me.  Either get a new package database or correct the package name.  This error can happen for valid package names if there has been no update since the current TeXLive version."
	exit 30
    fi
    message "Creating ebuild for g-ctan/${PN} ..."
    set_up
    fetch_package
    check_version
    G_SRC_URI="${CTANURL}/archive/${PN}.tar.xz -> ${PN}-${PV}.tar.xz"
    add_USE_flags
    prepare_ebuild
}

full_emerge() {
    set_up
    create_ebuild
    emerge_ebuild
}

update() {
    message "Updating ebuild for g-ctan/${PN} ..."
    get_packages
    check_existence installed fatal
    full_emerge
}

update_all() {
    message "Updating all ebuilds created by g-CTAN ..."
    get_packages
    collect_installed
    for package in ${G_INSTALLED}
    do
	PN=${package}
	set_up
	check_existence
	if [[ "$?" == "5" ]]
	then
    	    G_UP_TODATE="${package} ${G_UP_TODATE}"
	else
	    check_availability
	    if [[ "$?" == "30" ]]
	    then
		G_UP_OLD="${package} ${G_UP_OLD}"
		break
	    else
		G_UP_SUCCESS="${package} ${G_UP_SUCCESS}"
		fetch_package
		G_SRC_URI="${CTANURL}/archive/${PN}.tar.xz -> ${PN}-${PV}.tar.xz"
		add_USE_flags
		prepare_ebuild
	    fi
	fi
    done
    message "The following packages were updated: "${G_UP_SUCCESS}
    message "The following packages were already up to date: "${G_UP_TODATE}
    message "The following packages are not in the package database anymore: "${G_UP_OLD}
}

clean_up() {
    message "Determining outdated ebuilds and packages ..."
    get_packages
    collect_installed
    for package in ${G_INSTALLED}
    do
	PN=${package}
	set_up

	check_availability
	if [[ "$?" == "30" ]]
	then
	    G_UP_OLD="${PN} ${G_UP_OLD}"
	    break
	fi

	for i_ebuild in $(ls ${G_OVERLAY_DIR}/g-ctan/${package}/*.ebuild)
	do
	    i_ebuild=$(basename ${i_ebuild})
	    current_PV=$(qatom ${i_ebuild} | awk '{print $3}')
	    if [[ ${current_PV} != ${PV} ]]
	    then
		G_CLEAN="${PN}-${current_PV} ${G_CLEAN}"
	    fi
	done
    done
    
    message "The following ebuilds are outdated: "${G_CLEAN}
    message "The following packages are not in the package database anymore: "${G_UP_OLD}
}

case "${ACTION}" in
    get) get_packages;;
    list) show_available_packages;;
    create) create_ebuild;;
    emerge) full_emerge;;
    update) update;;
    update_all) update_all;;
    clean) clean_up;;
esac