download callback: show decimal places in rate if we have room
[pacman-ng.git] / scripts / pacman-db-upgrade.sh.in
blob3e0d702dc661a5b14a6a0b16579d1c39026bc65a
1 #!/bin/bash -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-scripts'
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 m4_include(library/output_format.sh)
33 usage() {
34 printf "pacman-db-upgrade (pacman) %s\n\n" "$myver"
35 printf "$(gettext "Usage: %s [pacman_db_root]")\n\n" "$0"
38 version() {
39 printf "pacman-db-upgrade (pacman) %s\n" "$myver"
40 printf "$(gettext "\
41 Copyright (c) 2010-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
42 This is free software; see the source for copying conditions.\n\
43 There is NO WARRANTY, to the extent permitted by law.\n")"
46 die() {
47 error "$@"
48 exit 1
51 die_r() {
52 rm -f "$lockfile"
53 die "$@"
56 # PROGRAM START
58 # determine whether we have gettext; make it a no-op if we do not
59 if ! type gettext &>/dev/null; then
60 gettext() {
61 echo "$@"
65 if [[ $1 = "-h" || $1 = "--help" ]]; then
66 usage
67 exit 0
70 if [[ $1 = "-V" || $1 = "--version" ]]; then
71 version
72 exit 0
75 if [[ -n $1 ]]; then
76 dbroot="$1"
79 if [[ ! -d $dbroot ]]; then
80 die "$(gettext "%s does not exist or is not a directory.")" "$dbroot"
83 if [[ ! -d $dbroot/local ]]; then
84 die "$(gettext "%s is not a pacman database directory.")" "$dbroot"
87 if [[ ! -w $dbroot ]]; then
88 die "$(gettext "You must have correct permissions to upgrade the database.")"
91 # strip any trailing slash from our dbroot
92 dbroot="${dbroot%/}"
93 # form the path to our lockfile location
94 lockfile="${dbroot}/db.lck"
96 # make sure pacman isn't running
97 if [[ -f $lockfile ]]; then
98 die "$(gettext "Pacman lock file was found. Cannot run while pacman is running.")"
100 # do not let pacman run while we do this
101 touch "$lockfile"
103 # pacman-3.4 to 3.5 upgrade - merge depends into desc
104 if [[ $(find "$dbroot"/local -name depends) ]]; then
105 msg "$(gettext "Pre-3.5 database format detected - upgrading...")"
106 for i in "$dbroot"/local/*; do
107 if [[ -f "$i"/depends ]]; then
108 cat "$i"/depends >> "$i"/desc
109 rm "$i"/depends
111 done
112 msg "$(gettext "Done.")"
115 # remove the lock file
116 rm -f "$lockfile"
118 # vim: set ts=2 sw=2 noet: