summaryrefslogtreecommitdiff
blob: 7f94d97f1fbc848fa3a3965726875c8e476238fb (plain)
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
#!/bin/bash

# Copyright 2007-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id: emacs-updater,v 1.3 2008/03/08 06:53:06 ulm Exp $

# Authors:
# Christian Faulhammer <opfer@gentoo.org>
# Ulrich Mueller <ulm@gentoo.org>

VERSION=0.6
SITELISP=/usr/share/emacs/site-lisp
TMPFILE="$(mktemp /tmp/emacs-updater.XXXXXX)"

cat <<-EOF

Emacs updater version ${VERSION}
Written by the Gentoo Emacs team http://www.gentoo.org/proj/en/lisp/emacs/
Find packages that are installed in the wrong location

EOF

usage() {
    sed -e 's/^X//' <<-EOF
	Usage: ${0##*/} [OPTION]...
	X  -n, --nocolour   disable colour in output
	X  -p, --pretend    don't actually emerge packages
	X  -h, --help       display this help and exit
	EOF
    exit ${1}
}

# Read in all command-line options and force English output
OPTIONS=$(LC_ALL=C getopt -o hpn --long help,pretend,nocolour \
     -n 'emacs-updater' -- "$@")
[ $? -eq 0 ] || usage 1

eval set -- "${OPTIONS}"

while true
do
    case "${1}" in
	-h|--help)      usage 0 ;;
	-p|--pretend)   PRETEND="true"; shift 1 ;;
	-n|--nocolour)  NOCOLOUR="true"; shift 1 ;;
	--)             shift; break ;;
    esac
done

# Only set colours if output is not redirected or the --no-colour
# option is not set
if [ -t 1 ] && [ -z "${NOCOLOUR}" ] ; then
    RED=$(tput -S <<<$'setaf 1\nbold')
    GREEN=$(tput -S <<<$'setaf 2\nbold')
    YELLOW=$(tput -S <<<$'setaf 3\nbold')
    BLUE=$(tput -S <<<$'setaf 4\nbold')
    MAGENTA=$(tput -S <<<$'setaf 5\nbold')
    CYAN=$(tput -S <<<$'setaf 6\nbold')
    BOLD=$(tput bold)
    NORMAL=$(tput sgr0)
fi

message() {
    local OUTPUT=$@
    echo "${GREEN}*${NORMAL}${BOLD} ${OUTPUT}${NORMAL}"
}

warning() {
    local OUTPUT=$@
    echo "${YELLOW}*${NORMAL}${BOLD} ${OUTPUT}${NORMAL}"
}

failure() {
    local OUTPUT=$@
    echo "${RED}*${NORMAL}${BOLD} ${OUTPUT}${NORMAL}" 
}

if ! [ -x /usr/bin/qfile ]; then
    echo
    failure "Please emerge app-portage/portage-utils to use this tool"
    exit 1
fi

for sf in "${ROOT}${SITELISP}"/[0-9][0-9]*-gentoo.el
do
    [ "${sf##*/}" = 00site-gentoo.el ] && continue
    message "Processing ${sf##*/} ..."
    qfile -qCR "${sf}" >> "${TMPFILE}"
done
echo

if [ ! -s "${TMPFILE}" ]; then
    warning "No packages to update, quitting."
    exit 2
fi

NO_OF_PACKAGES=$(sed -n '$=' "${TMPFILE}")

[ ${NO_OF_PACKAGES} -eq 1 ] && s= || s=s
message "${NO_OF_PACKAGES} package${s} with site files in the wrong location:"
cat "${TMPFILE}"

if [ "${PRETEND}" ]; then
    exit 3
fi

echo
echo -n "${BOLD}Remerge packages?${NORMAL} [${GREEN}Yes${NORMAL}/${RED}No${NORMAL}] "
read choice
echo
case "${choice}" in
    y*|Y*|"")
	;;
    *)
	warning "Quitting."
	exit 10 ;;
esac

emerge --oneshot --ask --verbose $(cat "${TMPFILE}")

warning "If a package is being rebuilt over and over again,"
warning "please report it on http://bugs.gentoo.org/"