Only check diskspace availability if needs more than zero
[pacman-ng.git] / scripts / pacman-db-upgrade.sh.in
blob4e6194fa572d4d58e824ffed517a0e16aaa7b4e5
1 #!@BASH_SHELL@ -e
3 # pacman-db-upgrade - upgrade the local pacman db to a newer format
4 # @configure_input@
6 # Copyright (c) 2010 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 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 || ! -d $dbroot/local ]]; then
87 die "$(gettext "%s does not exist or is not a directory.")" "$dbroot"
90 if [[ ! -w $dbroot ]]; then
91 die "$(gettext "You must have correct permissions to upgrade the database.")"
94 # strip any trailing slash from our dbroot
95 dbroot="${dbroot%/}"
96 # form the path to our lockfile location
97 lockfile="${dbroot}/db.lck"
99 # make sure pacman isn't running
100 if [[ -f $lockfile ]]; then
101 die "$(gettext "Pacman lock file was found. Cannot run while pacman is running.")"
103 # do not let pacman run while we do this
104 touch "$lockfile"
106 # pacman-3.4 to 3.5 upgrade - merge depends into desc
107 if [[ $(find "$dbroot"/local -name depends) ]]; then
108 msg "$(gettext "Pre-3.5 database format detected - upgrading...")"
109 for i in "$dbroot"/local/*; do
110 if [[ -f "$i"/depends ]]; then
111 cat "$i"/depends >> "$i"/desc
112 rm "$i"/depends
114 done
115 msg "$(gettext "Done.")"
118 # remove the lock file
119 rm -f "$lockfile"
121 # vim: set ts=2 sw=2 noet: