repo-add: simplify usage message
[pacman-ng.git] / scripts / pacman-db-upgrade.sh.in
blob17d8beb4428b27a8bc45c6bca2775ee06736da0e
1 #!@BASH_SHELL@ -e
3 # pacman-db-upgrade - upgrade the local pacman db to a newer format
4 # @configure_input@
6 # Copyright (c) 2010-2011 Pacman Development Team <pacman-dev@archlinux.org>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # gettext initialization
23 export TEXTDOMAIN='pacman'
24 export TEXTDOMAINDIR='@localedir@'
26 myver='@PACKAGE_VERSION@'
28 eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
29 dbroot="${DBPath:-@localstatedir@/lib/pacman/}"
31 msg() {
32 local mesg=$1; shift
33 printf "==> ${mesg}\n" "$@" >&2
36 error () {
37 local mesg=$1; shift
38 printf "==> ERROR: ${mesg}\n" "$@" >&2
40 usage() {
41 printf "pacman-db-upgrade (pacman) %s\n\n" "$myver"
42 printf "$(gettext "Usage: %s [pacman_db_root]")\n\n" "$0"
45 version() {
46 printf "pacman-db-upgrade (pacman) %s\n" "$myver"
47 printf "$(gettext "\
48 Copyright (c) 2010-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
49 This is free software; see the source for copying conditions.\n\
50 There is NO WARRANTY, to the extent permitted by law.\n")"
53 die() {
54 error "$@"
55 exit 1
58 die_r() {
59 rm -f "$lockfile"
60 die "$@"
63 # PROGRAM START
65 # determine whether we have gettext; make it a no-op if we do not
66 if ! type gettext &>/dev/null; then
67 gettext() {
68 echo "$@"
72 if [[ $1 = "-h" || $1 = "--help" ]]; then
73 usage
74 exit 0
77 if [[ $1 = "-V" || $1 = "--version" ]]; then
78 version
79 exit 0
82 if [[ -n $1 ]]; then
83 dbroot="$1"
86 if [[ ! -d $dbroot ]]; then
87 die "$(gettext "%s does not exist or is not a directory.")" "$dbroot"
90 if [[ ! -d $dbroot/local ]]; then
91 die "$(gettext "%s is not a pacman database directory.")" "$dbroot"
94 if [[ ! -w $dbroot ]]; then
95 die "$(gettext "You must have correct permissions to upgrade the database.")"
98 # strip any trailing slash from our dbroot
99 dbroot="${dbroot%/}"
100 # form the path to our lockfile location
101 lockfile="${dbroot}/db.lck"
103 # make sure pacman isn't running
104 if [[ -f $lockfile ]]; then
105 die "$(gettext "Pacman lock file was found. Cannot run while pacman is running.")"
107 # do not let pacman run while we do this
108 touch "$lockfile"
110 # pacman-3.4 to 3.5 upgrade - merge depends into desc
111 if [[ $(find "$dbroot"/local -name depends) ]]; then
112 msg "$(gettext "Pre-3.5 database format detected - upgrading...")"
113 for i in "$dbroot"/local/*; do
114 if [[ -f "$i"/depends ]]; then
115 cat "$i"/depends >> "$i"/desc
116 rm "$i"/depends
118 done
119 msg "$(gettext "Done.")"
122 # remove the lock file
123 rm -f "$lockfile"
125 # vim: set ts=2 sw=2 noet: