Merge branch 'xav/repo-add'
This commit is contained in:
commit
93ca155b48
8 changed files with 484 additions and 201 deletions
|
@ -144,7 +144,7 @@ Options
|
||||||
|
|
||||||
*UseDelta*::
|
*UseDelta*::
|
||||||
Download delta files instead of complete packages if possible. Requires
|
Download delta files instead of complete packages if possible. Requires
|
||||||
the xdelta program to be installed.
|
the xdelta3 program to be installed.
|
||||||
|
|
||||||
*TotalDownload*::
|
*TotalDownload*::
|
||||||
When downloading, display the amount downloaded, download rate, ETA,
|
When downloading, display the amount downloaded, download rate, ETA,
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdint.h> /* intmax_t */
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
|
@ -215,13 +216,13 @@ off_t _alpm_shortest_delta_path(alpm_list_t *deltas,
|
||||||
return(bestsize);
|
return(bestsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "started delta shortest-path search\n");
|
_alpm_log(PM_LOG_DEBUG, "started delta shortest-path search for '%s'\n", to);
|
||||||
|
|
||||||
vertices = delta_graph_init(deltas);
|
vertices = delta_graph_init(deltas);
|
||||||
|
|
||||||
bestsize = delta_vert(vertices, to, &bestpath);
|
bestsize = delta_vert(vertices, to, &bestpath);
|
||||||
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "delta shortest-path search complete\n");
|
_alpm_log(PM_LOG_DEBUG, "delta shortest-path search complete : '%jd'\n", (intmax_t)bestsize);
|
||||||
|
|
||||||
alpm_list_free_inner(vertices, _alpm_graph_free);
|
alpm_list_free_inner(vertices, _alpm_graph_free);
|
||||||
alpm_list_free(vertices);
|
alpm_list_free(vertices);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdint.h> /* intmax_t */
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
@ -387,8 +388,8 @@ static int compute_download_size(pmpkg_t *newpkg)
|
||||||
size = alpm_pkg_get_size(newpkg);
|
size = alpm_pkg_get_size(newpkg);
|
||||||
}
|
}
|
||||||
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "setting download size %lld for pkg %s\n",
|
_alpm_log(PM_LOG_DEBUG, "setting download size %jd for pkg %s\n",
|
||||||
(long long)size, alpm_pkg_get_name(newpkg));
|
(intmax_t)size, alpm_pkg_get_name(newpkg));
|
||||||
|
|
||||||
newpkg->download_size = size;
|
newpkg->download_size = size;
|
||||||
return(0);
|
return(0);
|
||||||
|
@ -679,6 +680,12 @@ off_t SYMEXPORT alpm_pkg_download_size(pmpkg_t *newpkg)
|
||||||
return(newpkg->download_size);
|
return(newpkg->download_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int endswith(char *filename, char *extension)
|
||||||
|
{
|
||||||
|
char *s = filename + strlen(filename) - strlen(extension);
|
||||||
|
return (strcmp(s, extension) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
/** Applies delta files to create an upgraded package file.
|
/** Applies delta files to create an upgraded package file.
|
||||||
*
|
*
|
||||||
* All intermediate files are deleted, leaving only the starting and
|
* All intermediate files are deleted, leaving only the starting and
|
||||||
|
@ -724,16 +731,18 @@ static int apply_deltas(pmtrans_t *trans)
|
||||||
CALLOC(to, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, 1));
|
CALLOC(to, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, 1));
|
||||||
snprintf(to, len, "%s/%s", cachedir, d->to);
|
snprintf(to, len, "%s/%s", cachedir, d->to);
|
||||||
|
|
||||||
/* an example of the patch command: (using /cache for cachedir)
|
|
||||||
* xdelta patch /path/to/pacman_3.0.0-1_to_3.0.1-1-i686.delta \
|
|
||||||
* /path/to/pacman-3.0.0-1-i686.pkg.tar.gz \
|
|
||||||
* /cache/pacman-3.0.1-1-i686.pkg.tar.gz
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* build the patch command */
|
/* build the patch command */
|
||||||
snprintf(command, PATH_MAX, "xdelta patch %s %s %s", delta, from, to);
|
/* compression command */
|
||||||
|
char *compress = "cat";
|
||||||
|
if(endswith(to, ".gz")) {
|
||||||
|
compress = "gzip -n";
|
||||||
|
} else if(endswith(to, ".bz2")) {
|
||||||
|
compress = "bzip";
|
||||||
|
}
|
||||||
|
/* -R for disabling external recompression, -c for sending to stdout */
|
||||||
|
snprintf(command, PATH_MAX, "xdelta3 -d -q -R -c -s %s %s | %s > %s", from, delta, compress, to);
|
||||||
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("command: %s\n"), command);
|
_alpm_log(PM_LOG_DEBUG, "command: %s\n", command);
|
||||||
|
|
||||||
EVENT(trans, PM_TRANS_EVT_DELTA_PATCH_START, d->to, d->delta);
|
EVENT(trans, PM_TRANS_EVT_DELTA_PATCH_START, d->to, d->delta);
|
||||||
|
|
||||||
|
@ -847,29 +856,31 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
|
||||||
|
|
||||||
fname = alpm_pkg_get_filename(spkg);
|
fname = alpm_pkg_get_filename(spkg);
|
||||||
ASSERT(fname != NULL, RET_ERR(PM_ERR_PKG_INVALID_NAME, -1));
|
ASSERT(fname != NULL, RET_ERR(PM_ERR_PKG_INVALID_NAME, -1));
|
||||||
if(spkg->download_size != 0) {
|
alpm_list_t *delta_path = spkg->delta_path;
|
||||||
alpm_list_t *delta_path = spkg->delta_path;
|
if(delta_path) {
|
||||||
if(delta_path) {
|
/* using deltas */
|
||||||
alpm_list_t *dlts = NULL;
|
alpm_list_t *dlts = NULL;
|
||||||
|
|
||||||
for(dlts = delta_path; dlts; dlts = dlts->next) {
|
for(dlts = delta_path; dlts; dlts = dlts->next) {
|
||||||
pmdelta_t *d = dlts->data;
|
pmdelta_t *d = dlts->data;
|
||||||
|
|
||||||
if(d->download_size != 0) {
|
if(d->download_size != 0) {
|
||||||
/* add the delta filename to the download list if
|
/* add the delta filename to the download list if needed */
|
||||||
* it's not in the cache */
|
files = alpm_list_add(files, strdup(d->delta));
|
||||||
files = alpm_list_add(files, strdup(d->delta));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* keep a list of the delta files for md5sums */
|
|
||||||
deltas = alpm_list_add(deltas, d);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
/* keep a list of all the delta files for md5sums */
|
||||||
/* not using deltas, so add the file to the download list */
|
deltas = alpm_list_add(deltas, d);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/* not using deltas */
|
||||||
|
if(spkg->download_size != 0) {
|
||||||
|
/* add the filename to the download list if needed */
|
||||||
files = alpm_list_add(files, strdup(fname));
|
files = alpm_list_add(files, strdup(fname));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -890,37 +901,34 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
|
||||||
handle->totaldlcb(0);
|
handle->totaldlcb(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(handle->usedelta) {
|
/* if we have deltas to work with */
|
||||||
|
if(handle->usedelta && deltas) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
errors = 0;
|
||||||
|
/* Check integrity of deltas */
|
||||||
|
EVENT(trans, PM_TRANS_EVT_DELTA_INTEGRITY_START, NULL, NULL);
|
||||||
|
|
||||||
/* only output if there are deltas to work with */
|
for(i = deltas; i; i = i->next) {
|
||||||
if(deltas) {
|
pmdelta_t *d = alpm_list_getdata(i);
|
||||||
errors = 0;
|
const char *filename = alpm_delta_get_filename(d);
|
||||||
/* Check integrity of deltas */
|
const char *md5sum = alpm_delta_get_md5sum(d);
|
||||||
EVENT(trans, PM_TRANS_EVT_DELTA_INTEGRITY_START, NULL, NULL);
|
|
||||||
|
|
||||||
for(i = deltas; i; i = i->next) {
|
if(test_md5sum(trans, filename, md5sum) != 0) {
|
||||||
pmdelta_t *d = alpm_list_getdata(i);
|
errors++;
|
||||||
const char *filename = alpm_delta_get_filename(d);
|
*data = alpm_list_add(*data, strdup(filename));
|
||||||
const char *md5sum = alpm_delta_get_md5sum(d);
|
|
||||||
|
|
||||||
if(test_md5sum(trans, filename, md5sum) != 0) {
|
|
||||||
errors++;
|
|
||||||
*data = alpm_list_add(*data, strdup(filename));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(errors) {
|
|
||||||
pm_errno = PM_ERR_DLT_INVALID;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
EVENT(trans, PM_TRANS_EVT_DELTA_INTEGRITY_DONE, NULL, NULL);
|
|
||||||
|
|
||||||
/* Use the deltas to generate the packages */
|
|
||||||
EVENT(trans, PM_TRANS_EVT_DELTA_PATCHES_START, NULL, NULL);
|
|
||||||
ret = apply_deltas(trans);
|
|
||||||
EVENT(trans, PM_TRANS_EVT_DELTA_PATCHES_DONE, NULL, NULL);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if(errors) {
|
||||||
|
pm_errno = PM_ERR_DLT_INVALID;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
EVENT(trans, PM_TRANS_EVT_DELTA_INTEGRITY_DONE, NULL, NULL);
|
||||||
|
|
||||||
|
/* Use the deltas to generate the packages */
|
||||||
|
EVENT(trans, PM_TRANS_EVT_DELTA_PATCHES_START, NULL, NULL);
|
||||||
|
ret = apply_deltas(trans);
|
||||||
|
EVENT(trans, PM_TRANS_EVT_DELTA_PATCHES_DONE, NULL, NULL);
|
||||||
|
|
||||||
if(ret) {
|
if(ret) {
|
||||||
pm_errno = PM_ERR_DLT_PATCHFAILED;
|
pm_errno = PM_ERR_DLT_PATCHFAILED;
|
||||||
goto error;
|
goto error;
|
||||||
|
|
1
scripts/.gitignore
vendored
1
scripts/.gitignore
vendored
|
@ -3,3 +3,4 @@ pacman-optimize
|
||||||
rankmirrors
|
rankmirrors
|
||||||
repo-add
|
repo-add
|
||||||
repo-remove
|
repo-remove
|
||||||
|
pkgdelta
|
||||||
|
|
|
@ -8,12 +8,14 @@ bin_SCRIPTS = \
|
||||||
OURSCRIPTS = \
|
OURSCRIPTS = \
|
||||||
makepkg \
|
makepkg \
|
||||||
pacman-optimize \
|
pacman-optimize \
|
||||||
|
pkgdelta \
|
||||||
rankmirrors \
|
rankmirrors \
|
||||||
repo-add
|
repo-add
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
makepkg.sh.in \
|
makepkg.sh.in \
|
||||||
pacman-optimize.sh.in \
|
pacman-optimize.sh.in \
|
||||||
|
pkgdelta.sh.in \
|
||||||
rankmirrors.py.in \
|
rankmirrors.py.in \
|
||||||
repo-add.sh.in
|
repo-add.sh.in
|
||||||
|
|
||||||
|
@ -58,6 +60,7 @@ $(OURSCRIPTS): Makefile
|
||||||
|
|
||||||
makepkg: $(srcdir)/makepkg.sh.in
|
makepkg: $(srcdir)/makepkg.sh.in
|
||||||
pacman-optimize: $(srcdir)/pacman-optimize.sh.in
|
pacman-optimize: $(srcdir)/pacman-optimize.sh.in
|
||||||
|
pkgdelta: $(srcdir)/pkgdelta.sh.in
|
||||||
rankmirrors: $(srcdir)/rankmirrors.py.in
|
rankmirrors: $(srcdir)/rankmirrors.py.in
|
||||||
repo-add: $(srcdir)/repo-add.sh.in
|
repo-add: $(srcdir)/repo-add.sh.in
|
||||||
repo-remove: $(srcdir)/repo-add.sh.in
|
repo-remove: $(srcdir)/repo-add.sh.in
|
||||||
|
|
|
@ -974,25 +974,34 @@ create_package() {
|
||||||
# tar it up
|
# tar it up
|
||||||
msg2 "$(gettext "Compressing package...")"
|
msg2 "$(gettext "Compressing package...")"
|
||||||
|
|
||||||
local TAR_OPT
|
|
||||||
case "$PKGEXT" in
|
case "$PKGEXT" in
|
||||||
*tar.gz) TAR_OPT="z" ;;
|
*tar.gz) EXT=${PKGEXT%.gz} ;;
|
||||||
*tar.bz2) TAR_OPT="j" ;;
|
*tar.bz2) EXT=${PKGEXT%.bz2} ;;
|
||||||
*) warning "$(gettext "'%s' is not a valid archive extension.")" \
|
*) warning "$(gettext "'%s' is not a valid archive extension.")" \
|
||||||
"$PKGEXT" ;;
|
"$PKGEXT" ; EXT=$PKGEXT ;;
|
||||||
esac
|
esac
|
||||||
|
local pkg_file="$PKGDEST/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}${EXT}"
|
||||||
|
|
||||||
local pkg_file="$PKGDEST/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
|
local ret=0
|
||||||
|
|
||||||
# when fileglobbing, we want * in an empty directory to expand to
|
# when fileglobbing, we want * in an empty directory to expand to
|
||||||
# the null string rather than itself
|
# the null string rather than itself
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
bsdtar -cf - $comp_files * > "$pkg_file" || ret=$?
|
||||||
|
shopt -u nullglob
|
||||||
|
|
||||||
if ! bsdtar -c${TAR_OPT}f "$pkg_file" $comp_files *; then
|
if [ $ret -eq 0 ]; then
|
||||||
|
case "$PKGEXT" in
|
||||||
|
*tar.gz) gzip -f -n "$pkg_file" ;;
|
||||||
|
*tar.bz2) bzip2 -f "$pkg_file" ;;
|
||||||
|
esac
|
||||||
|
ret=$?
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $ret -ne 0 ]; then
|
||||||
error "$(gettext "Failed to create package file.")"
|
error "$(gettext "Failed to create package file.")"
|
||||||
exit 1 # TODO: error code
|
exit 1 # TODO: error code
|
||||||
fi
|
fi
|
||||||
shopt -u nullglob
|
|
||||||
}
|
}
|
||||||
|
|
||||||
create_srcpackage() {
|
create_srcpackage() {
|
||||||
|
|
165
scripts/pkgdelta.sh.in
Normal file
165
scripts/pkgdelta.sh.in
Normal file
|
@ -0,0 +1,165 @@
|
||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# pkgdelta - create delta files for use with pacman and repo-add
|
||||||
|
# @configure_input@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2009 Xavier Chantry <shiningxc@gmail.com>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
# bash options
|
||||||
|
set -o nounset
|
||||||
|
set -o errexit
|
||||||
|
|
||||||
|
# gettext initialization
|
||||||
|
export TEXTDOMAIN='pacman'
|
||||||
|
export TEXTDOMAINDIR='@localedir@'
|
||||||
|
|
||||||
|
myver='@PACKAGE_VERSION@'
|
||||||
|
|
||||||
|
QUIET=0
|
||||||
|
|
||||||
|
# ensure we have a sane umask set
|
||||||
|
umask 0022
|
||||||
|
|
||||||
|
msg() {
|
||||||
|
[ $QUIET -ne 0 ] && return
|
||||||
|
local mesg=$1; shift
|
||||||
|
printf "==> ${mesg}\n" "$@" >&1
|
||||||
|
}
|
||||||
|
|
||||||
|
warning() {
|
||||||
|
local mesg=$1; shift
|
||||||
|
printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
local mesg=$1; shift
|
||||||
|
printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
# print usage instructions
|
||||||
|
usage() {
|
||||||
|
printf "pkgdelta (pacman) %s\n\n" "$myver"
|
||||||
|
printf "$(gettext "Usage: pkgdelta [-q] <package1> <package2>\n")"
|
||||||
|
printf "$(gettext "\
|
||||||
|
pkgdelta will create a delta file between two packages\n\
|
||||||
|
This delta file can then be added to a database using repo-add.\n\n")"
|
||||||
|
echo "$(gettext "Example: pkgdelta pacman-3.0.0.pkg.tar.gz pacman-3.0.1.pkg.tar.gz")"
|
||||||
|
}
|
||||||
|
|
||||||
|
version() {
|
||||||
|
printf "pkgdelta (pacman) %s\n\n" "$myver"
|
||||||
|
printf "$(gettext "\
|
||||||
|
Copyright (c) 2009 Xavier Chantry <shiningxc@gmail.com>.\n\n\
|
||||||
|
This is free software; see the source for copying conditions.\n\
|
||||||
|
There is NO WARRANTY, to the extent permitted by law.\n")"
|
||||||
|
}
|
||||||
|
|
||||||
|
read_pkginfo()
|
||||||
|
{
|
||||||
|
pkgname= pkgver= arch=
|
||||||
|
local OLDIFS=$IFS
|
||||||
|
# IFS (field separator) is only the newline character
|
||||||
|
IFS="
|
||||||
|
"
|
||||||
|
local line var val
|
||||||
|
for line in $(bsdtar -xOf "$1" .PKGINFO 2>/dev/null |
|
||||||
|
grep -v "^#" | sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do
|
||||||
|
eval "$line"
|
||||||
|
if [ -n "$pkgname" -a -n "$pkgver" -a -n "$arch" ]; then
|
||||||
|
IFS=$OLDIFS
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
IFS=$OLDIFS
|
||||||
|
error "$(gettext "Invalid package '%s'")" "$1"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# $oldfile $oldmd5 $newfile $newmd5 $deltafile $deltamd5 $deltasize
|
||||||
|
create_xdelta()
|
||||||
|
{
|
||||||
|
local oldfile=$1
|
||||||
|
local newfile=$2
|
||||||
|
local \
|
||||||
|
oldname oldver oldarch \
|
||||||
|
newname newver newarch \
|
||||||
|
deltafile
|
||||||
|
|
||||||
|
read_pkginfo "$oldfile" || return 1
|
||||||
|
oldname="$pkgname"
|
||||||
|
oldver="$pkgver"
|
||||||
|
oldarch="$arch"
|
||||||
|
read_pkginfo "$newfile" || return 1
|
||||||
|
newname="$pkgname"
|
||||||
|
newver="$pkgver"
|
||||||
|
newarch="$arch"
|
||||||
|
|
||||||
|
if [ "$oldname" != "$newname" ]; then
|
||||||
|
error "$(gettext "The package names don't match : '%s' and '%s'")" "$oldname" "$newname"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$oldarch" != "$newarch" ]; then
|
||||||
|
error "$(gettext "The package architectures don't match : '%s' and '%s'")" "$oldarch" "$newarch"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$oldver" == "$newver" ]; then
|
||||||
|
error "$(gettext "Both packages have the same version : '%s'")" "$newver"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
msg "$(gettext "Generating delta from version %s to version %s")" "$oldver" "$newver"
|
||||||
|
deltafile="$(dirname $newfile)/$pkgname-${oldver}_to_${newver}-$arch.delta"
|
||||||
|
local ret=0
|
||||||
|
|
||||||
|
xdelta3 -q -f -s "$oldfile" "$newfile" "$deltafile" || ret=$?
|
||||||
|
if [ $ret -ne 0 ]; then
|
||||||
|
error "$(gettext "Delta could not be created.")"
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
msg "$(gettext "Generated delta : '%s'")" "$deltafile"
|
||||||
|
[ $QUIET -eq 1 ] && echo "$deltafile"
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
-q|--quiet) QUIET=1; shift ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ $# -ne 2 ]; then
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$1" ]; then
|
||||||
|
error "$(gettext "File '%s' does not exist")" "$1"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$2" ]; then
|
||||||
|
error "$(gettext "File '%s' does not exist")" "$2"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! "$(type -p xdelta3)" ]; then
|
||||||
|
error "$(gettext "Cannot find the xdelta3 binary! Is xdelta3 installed?")"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
create_xdelta "$1" "$2"
|
|
@ -28,7 +28,10 @@ myver='@PACKAGE_VERSION@'
|
||||||
confdir='@sysconfdir@'
|
confdir='@sysconfdir@'
|
||||||
|
|
||||||
QUIET=0
|
QUIET=0
|
||||||
REPO_DB_FILE=""
|
REPO_DB_FILE=
|
||||||
|
LOCKFILE=
|
||||||
|
CLEAN_LOCK=0
|
||||||
|
startdir="$PWD"
|
||||||
|
|
||||||
# ensure we have a sane umask set
|
# ensure we have a sane umask set
|
||||||
umask 0022
|
umask 0022
|
||||||
|
@ -57,8 +60,8 @@ error() {
|
||||||
# print usage instructions
|
# print usage instructions
|
||||||
usage() {
|
usage() {
|
||||||
printf "repo-add, repo-remove (pacman) %s\n\n" "$myver"
|
printf "repo-add, repo-remove (pacman) %s\n\n" "$myver"
|
||||||
printf "$(gettext "Usage: repo-add [-q] <path-to-db> <package> ...\n")"
|
printf "$(gettext "Usage: repo-add [-q] <path-to-db> <package|delta> ...\n")"
|
||||||
printf "$(gettext "Usage: repo-remove [-q] <path-to-db> <packagename> ...\n\n")"
|
printf "$(gettext "Usage: repo-remove [-q] <path-to-db> <packagename|delta> ...\n\n")"
|
||||||
printf "$(gettext "\
|
printf "$(gettext "\
|
||||||
repo-add will update a package database by reading a package file.\n\
|
repo-add will update a package database by reading a package file.\n\
|
||||||
Multiple packages to add can be specified on the command line.\n\n")"
|
Multiple packages to add can be specified on the command line.\n\n")"
|
||||||
|
@ -93,36 +96,86 @@ write_list_entry() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# write a delta entry to the pacman database
|
find_pkgentry()
|
||||||
# arg1 - path to delta
|
{
|
||||||
|
local pkgname=$1
|
||||||
|
local pkgentry
|
||||||
|
for pkgentry in $tmpdir/$pkgname*; do
|
||||||
|
name=${pkgentry##*/}
|
||||||
|
if [ "${name%-*-*}" = "$pkgname" ]; then
|
||||||
|
echo $pkgentry
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get the package name from the delta filename
|
||||||
|
get_delta_pkgname() {
|
||||||
|
local tmp
|
||||||
|
|
||||||
|
tmp=${1##*/}
|
||||||
|
echo ${tmp%-*-*_to*}
|
||||||
|
}
|
||||||
|
|
||||||
|
# write a delta entry
|
||||||
|
# arg1 - path to delta file
|
||||||
db_write_delta()
|
db_write_delta()
|
||||||
{
|
{
|
||||||
# blank out all variables
|
deltafile="$1"
|
||||||
local deltafile="$1"
|
pkgname="$(get_delta_pkgname $deltafile)"
|
||||||
local filename=$(basename "$deltafile")
|
|
||||||
local deltavars pkgname fromver tover arch csize md5sum
|
|
||||||
|
|
||||||
# format of the delta filename:
|
pkgentry=$(find_pkgentry $pkgname)
|
||||||
# (package)-(fromver)_to_(tover)-(arch).delta
|
if [ -z "$pkgentry" ]; then
|
||||||
deltavars=( $(echo "$filename" | sed -e 's/\(.*\)-\(.*-.*\)_to_\(.*-.*\)-\(.*\).delta/\1 \2 \3 \4/') )
|
return 1
|
||||||
pkgname=${deltavars[0]}
|
fi
|
||||||
fromver=${deltavars[1]}
|
deltas="$pkgentry/deltas"
|
||||||
tover=${deltavars[2]}
|
# create deltas file if it does not already exist
|
||||||
arch=${deltavars[3]}
|
if [ ! -f "$deltas" ]; then
|
||||||
|
msg2 "$(gettext "Creating 'deltas' db entry...")"
|
||||||
# get md5sum and size of delta
|
echo -e "%DELTAS%" >>$deltas
|
||||||
|
fi
|
||||||
|
# get md5sum and compressed size of package
|
||||||
md5sum="$(openssl dgst -md5 "$deltafile" | awk '{print $NF}')"
|
md5sum="$(openssl dgst -md5 "$deltafile" | awk '{print $NF}')"
|
||||||
csize=$(@SIZECMD@ "$deltafile")
|
csize=$(@SIZECMD@ "$deltafile")
|
||||||
|
|
||||||
# ensure variables were found
|
oldfile=$(xdelta3 printhdr $deltafile | grep "XDELTA filename (source)" | sed 's/.*: *//')
|
||||||
if [ -z "$pkgname" -o -z "$fromver" -o -z "$tover" -o -z "$arch" ]; then
|
newfile=$(xdelta3 printhdr $deltafile | grep "XDELTA filename (output)" | sed 's/.*: *//')
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# add the entry for this delta file
|
if grep -q "$oldfile.*$newfile" $deltas; then
|
||||||
echo -e "$fromver $tover $csize $filename $md5sum" >>deltas
|
warning "$(gettext "An entry for '%s' already existed")" "$deltafile"
|
||||||
|
sed -i.backup "/$oldfile.*$newfile/d" $deltas && rm -f $deltas.backup
|
||||||
|
msg2 "$(gettext "Removing existing entry '%s'...")" "$deltafile"
|
||||||
|
fi
|
||||||
|
echo ${deltafile##*/} $md5sum $csize $oldfile $newfile >> $deltas
|
||||||
|
|
||||||
|
return 0
|
||||||
} # end db_write_delta
|
} # end db_write_delta
|
||||||
|
|
||||||
|
# remove a delta entry
|
||||||
|
# arg1 - path to delta file
|
||||||
|
db_remove_delta()
|
||||||
|
{
|
||||||
|
deltafile="$1"
|
||||||
|
filename=${deltafile##*/}
|
||||||
|
pkgname="$(get_delta_pkgname $deltafile)"
|
||||||
|
|
||||||
|
pkgentry=$(find_pkgentry $pkgname)
|
||||||
|
if [ -z "$pkgentry" ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
deltas="$pkgentry/deltas"
|
||||||
|
if [ ! -f "$deltas" ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if grep -q "$filename" $deltas; then
|
||||||
|
sed -i.backup "/$filename/d" $deltas && rm -f $deltas.backup
|
||||||
|
msg2 "$(gettext "Removing existing entry '%s'...")" "$filename"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 1
|
||||||
|
} # end db_remove_delta
|
||||||
|
|
||||||
# write an entry to the pacman database
|
# write an entry to the pacman database
|
||||||
# arg1 - path to package
|
# arg1 - path to package
|
||||||
|
@ -130,10 +183,8 @@ db_write_entry()
|
||||||
{
|
{
|
||||||
# blank out all variables
|
# blank out all variables
|
||||||
local pkgfile="$1"
|
local pkgfile="$1"
|
||||||
local pkgname pkgver pkgdesc url builddate packager csize size \
|
local pkgname pkgver pkgdesc csize size md5sum url arch builddate packager force \
|
||||||
group depend backup license replaces provides conflict force \
|
_groups _licenses _replaces _depends _conflicts _provides _optdepends
|
||||||
_groups _depends _backups _licenses _replaces _provides _conflicts \
|
|
||||||
startdir optdepend _optdepends md5sum
|
|
||||||
|
|
||||||
local OLDIFS="$IFS"
|
local OLDIFS="$IFS"
|
||||||
# IFS (field separator) is only the newline character
|
# IFS (field separator) is only the newline character
|
||||||
|
@ -150,12 +201,11 @@ db_write_entry()
|
||||||
declare $var="$val"
|
declare $var="$val"
|
||||||
case "$var" in
|
case "$var" in
|
||||||
group) _groups="$_groups$group\n" ;;
|
group) _groups="$_groups$group\n" ;;
|
||||||
depend) _depends="$_depends$depend\n" ;;
|
|
||||||
backup) _backups="$_backups$backup\n" ;;
|
|
||||||
license) _licenses="$_licenses$license\n" ;;
|
license) _licenses="$_licenses$license\n" ;;
|
||||||
replaces) _replaces="$_replaces$replaces\n" ;;
|
replaces) _replaces="$_replaces$replaces\n" ;;
|
||||||
provides) _provides="$_provides$provides\n" ;;
|
depend) _depends="$_depends$depend\n" ;;
|
||||||
conflict) _conflicts="$_conflicts$conflict\n" ;;
|
conflict) _conflicts="$_conflicts$conflict\n" ;;
|
||||||
|
provides) _provides="$_provides$provides\n" ;;
|
||||||
optdepend) _optdepends="$_optdepends$optdepend\n" ;;
|
optdepend) _optdepends="$_optdepends$optdepend\n" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
@ -172,8 +222,7 @@ db_write_entry()
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
startdir=$(pwd)
|
cd "$tmpdir"
|
||||||
pushd "$gstmpdir" 2>&1 >/dev/null
|
|
||||||
|
|
||||||
if [ -d "$pkgname-$pkgver" ]; then
|
if [ -d "$pkgname-$pkgver" ]; then
|
||||||
warning "$(gettext "An entry for '%s' already existed")" "$pkgname-$pkgver"
|
warning "$(gettext "An entry for '%s' already existed")" "$pkgname-$pkgver"
|
||||||
|
@ -186,6 +235,9 @@ db_write_entry()
|
||||||
mkdir "$pkgname-$pkgver"
|
mkdir "$pkgname-$pkgver"
|
||||||
cd "$pkgname-$pkgver"
|
cd "$pkgname-$pkgver"
|
||||||
|
|
||||||
|
# restore an eventual deltas file
|
||||||
|
[ -f "../$pkgname.deltas" ] && mv "../$pkgname.deltas" deltas
|
||||||
|
|
||||||
# create desc entry
|
# create desc entry
|
||||||
msg2 "$(gettext "Creating 'desc' db entry...")"
|
msg2 "$(gettext "Creating 'desc' db entry...")"
|
||||||
echo -e "%FILENAME%\n$(basename "$1")\n" >>desc
|
echo -e "%FILENAME%\n$(basename "$1")\n" >>desc
|
||||||
|
@ -210,45 +262,14 @@ db_write_entry()
|
||||||
|
|
||||||
# create depends entry
|
# create depends entry
|
||||||
msg2 "$(gettext "Creating 'depends' db entry...")"
|
msg2 "$(gettext "Creating 'depends' db entry...")"
|
||||||
|
# create the file even if it will remain empty
|
||||||
|
touch "depends"
|
||||||
write_list_entry "DEPENDS" "$_depends" "depends"
|
write_list_entry "DEPENDS" "$_depends" "depends"
|
||||||
write_list_entry "CONFLICTS" "$_conflicts" "depends"
|
write_list_entry "CONFLICTS" "$_conflicts" "depends"
|
||||||
write_list_entry "PROVIDES" "$_provides" "depends"
|
write_list_entry "PROVIDES" "$_provides" "depends"
|
||||||
write_list_entry "OPTDEPENDS" "$_optdepends" "depends"
|
write_list_entry "OPTDEPENDS" "$_optdepends" "depends"
|
||||||
|
|
||||||
# create deltas entry if there are delta files
|
cd "$startdir"
|
||||||
# Xav : why should deltas be in $startdir?
|
|
||||||
for delta in $startdir/$pkgname-*-*_to_*-*-$arch.delta; do
|
|
||||||
# This for loop also pulls in all files that start with the current package
|
|
||||||
# name and are followed by a -whatever. For instance, running this loop for
|
|
||||||
# gcc would also grab gcc-libs. To guard against this, compare the package
|
|
||||||
# name of the delta to the current package name.
|
|
||||||
local filename=$(basename "$delta")
|
|
||||||
local dpkgname="$(echo "$filename" | sed -e 's/\(.*\)-.*-.*_to_.*-.*-.*.delta/\1/')"
|
|
||||||
if [ "$pkgname" = "$dpkgname" -a -f "$delta" ]; then
|
|
||||||
# create deltas file if it does not already exist
|
|
||||||
if [ ! -f "deltas" ]; then
|
|
||||||
msg2 "$(gettext "Creating 'deltas' db entry...")"
|
|
||||||
echo -e "%DELTAS%" >>deltas
|
|
||||||
fi
|
|
||||||
|
|
||||||
# write this delta entry
|
|
||||||
if db_write_delta "$delta"; then
|
|
||||||
msg2 "$(gettext "Added delta '%s'")" "$(basename "$delta")"
|
|
||||||
else
|
|
||||||
warning "$(gettext "Could not add delta '%s'")" "$(basename "$delta")"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
# add the final newline
|
|
||||||
[ -f "deltas" ] && echo -e "" >>deltas
|
|
||||||
|
|
||||||
popd 2>&1 >/dev/null
|
|
||||||
|
|
||||||
# preserve the modification time
|
|
||||||
# Xav : what for?
|
|
||||||
pkgdir="$gstmpdir/$pkgname-$pkgver"
|
|
||||||
touch -r "$pkgfile" "$pkgdir/desc" "$pkgdir/depends"
|
|
||||||
[ -f "$pkgdir/deltas" ] && touch -r "$pkgfile" "$pkgdir/deltas"
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
} # end db_write_entry
|
} # end db_write_entry
|
||||||
|
@ -256,20 +277,122 @@ db_write_entry()
|
||||||
# remove existing entries from the DB
|
# remove existing entries from the DB
|
||||||
# arg1 - package name
|
# arg1 - package name
|
||||||
db_remove_entry() {
|
db_remove_entry() {
|
||||||
pushd "$gstmpdir" 2>&1 >/dev/null
|
local pkgname=$1
|
||||||
|
local notfound=1
|
||||||
# remove any other package in the DB with same name
|
local pkgentry=$(find_pkgentry $pkgname)
|
||||||
local existing
|
while [ -n "$pkgentry" ]; do
|
||||||
for existing in *; do
|
notfound=0
|
||||||
if [ "${existing%-*-*}" = "$1" ]; then
|
if [ -f "$pkgentry/deltas" ]; then
|
||||||
msg2 "$(gettext "Removing existing package '%s'...")" "$existing"
|
mv "$pkgentry/deltas" "$tmpdir/$pkgname.deltas"
|
||||||
rm -rf "$existing"
|
|
||||||
fi
|
fi
|
||||||
|
msg2 "$(gettext "Removing existing entry '%s'...")" \
|
||||||
|
"$(basename $pkgentry)"
|
||||||
|
rm -rf $pkgentry
|
||||||
|
pkgentry=$(find_pkgentry $pkgname)
|
||||||
done
|
done
|
||||||
|
return $notfound
|
||||||
popd 2>&1 >/dev/null
|
|
||||||
} # end db_remove_entry
|
} # end db_remove_entry
|
||||||
|
|
||||||
|
check_repo_db()
|
||||||
|
{
|
||||||
|
# check lock file
|
||||||
|
if ( set -o noclobber; echo "$$" > "$LOCKFILE") 2> /dev/null; then
|
||||||
|
CLEAN_LOCK=1
|
||||||
|
else
|
||||||
|
error "$(gettext "Failed to acquire lockfile: %s.")" "$LOCKFILE"
|
||||||
|
[ -f "$LOCKFILE" ] && error "$(gettext "Held by %s")" "$(cat $LOCKFILE)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "$REPO_DB_FILE" ]; then
|
||||||
|
if ! (bsdtar -tf "$REPO_DB_FILE" | grep -q "/desc"); then
|
||||||
|
error "$(gettext "Repository file '%s' is not a proper pacman database.")" "$REPO_DB_FILE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
msg "$(gettext "Extracting database to a temporary location...")"
|
||||||
|
bsdtar -xf "$REPO_DB_FILE" -C "$tmpdir"
|
||||||
|
else
|
||||||
|
if [ "$cmd" == "repo-remove" ]; then
|
||||||
|
error "$(gettext "Repository file '%s' was not found.")" "$REPO_DB_FILE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
add()
|
||||||
|
{
|
||||||
|
if [ ! -f "$1" ]; then
|
||||||
|
error "$(gettext "File '%s' not found.")" "$1"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${1##*.}" == "delta" ]; then
|
||||||
|
deltafile=$1
|
||||||
|
msg "$(gettext "Adding delta '%s'")" "$deltafile"
|
||||||
|
if [ ! "$(type -p xdelta3)" ]; then
|
||||||
|
error "$(gettext "Cannot find the xdelta3 binary! Is xdelta3 installed?")"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if db_write_delta "$deltafile"; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
pkgfile=$1
|
||||||
|
if ! bsdtar -tf "$pkgfile" .PKGINFO 2>&1 >/dev/null; then
|
||||||
|
error "$(gettext "'%s' is not a package file, skipping")" "$pkgfile"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
msg "$(gettext "Adding package '%s'")" "$pkgfile"
|
||||||
|
|
||||||
|
db_write_entry "$pkgfile"
|
||||||
|
}
|
||||||
|
|
||||||
|
remove()
|
||||||
|
{
|
||||||
|
if [ "${1##*.}" == "delta" ]; then
|
||||||
|
deltafile=$1
|
||||||
|
msg "$(gettext "Searching for delta '%s'...")" "$deltafile"
|
||||||
|
if db_remove_delta "$deltafile"; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
error "$(gettext "Delta matching '%s' not found.")" "$deltafile"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
pkgname=$1
|
||||||
|
msg "$(gettext "Searching for package '%s'...")" "$pkgname"
|
||||||
|
|
||||||
|
if db_remove_entry "$pkgname"; then
|
||||||
|
rm -f "$tmpdir/$pkgname.deltas"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
error "$(gettext "Package matching '%s' not found.")" "$pkgname"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
trap_exit()
|
||||||
|
{
|
||||||
|
echo
|
||||||
|
error "$@"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
clean_up() {
|
||||||
|
local exit_code=$?
|
||||||
|
|
||||||
|
cd "$startdir"
|
||||||
|
[ -d "$tmpdir" ] && rm -rf "$tmpdir"
|
||||||
|
[ $CLEAN_LOCK -eq 1 -a -f "$LOCKFILE" ] && rm -f "$LOCKFILE"
|
||||||
|
|
||||||
|
exit $exit_code
|
||||||
|
}
|
||||||
|
|
||||||
# PROGRAM START
|
# PROGRAM START
|
||||||
|
|
||||||
# determine whether we have gettext; make it a no-op if we do not
|
# determine whether we have gettext; make it a no-op if we do not
|
||||||
|
@ -279,17 +402,10 @@ if [ ! $(type -t gettext) ]; then
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check for help flags
|
case "$1" in
|
||||||
if [ "$1" = "-h" -o "$1" = "--help" ]; then
|
-h|--help) usage; exit 0;;
|
||||||
usage
|
-V|--version) version; exit 0;;
|
||||||
exit 0
|
esac
|
||||||
fi
|
|
||||||
|
|
||||||
# check for version flags
|
|
||||||
if [ "$1" = "-V" -o "$1" = "--version" ]; then
|
|
||||||
version
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check for correct number of args
|
# check for correct number of args
|
||||||
if [ $# -lt 2 ]; then
|
if [ $# -lt 2 ]; then
|
||||||
|
@ -297,11 +413,6 @@ if [ $# -lt 2 ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# main routine
|
|
||||||
gstmpdir=$(mktemp -d /tmp/repo-tools.XXXXXXXXXX) || (\
|
|
||||||
error "$(gettext "Cannot create temp directory for database building.")"; \
|
|
||||||
exit 1)
|
|
||||||
|
|
||||||
# figure out what program we are
|
# figure out what program we are
|
||||||
cmd="$(basename $0)"
|
cmd="$(basename $0)"
|
||||||
if [ "$cmd" != "repo-add" -a "$cmd" != "repo-remove" ]; then
|
if [ "$cmd" != "repo-add" -a "$cmd" != "repo-remove" ]; then
|
||||||
|
@ -309,55 +420,42 @@ if [ "$cmd" != "repo-add" -a "$cmd" != "repo-remove" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
tmpdir=$(mktemp -d /tmp/repo-tools.XXXXXXXXXX) || (\
|
||||||
|
error "$(gettext "Cannot create temp directory for database building.")"; \
|
||||||
|
exit 1)
|
||||||
|
|
||||||
|
trap 'clean_up' EXIT
|
||||||
|
trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
|
||||||
|
trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
|
||||||
|
trap 'trap_exit "$(gettext "An unknown error has occured. Exiting...")"' ERR
|
||||||
|
|
||||||
success=0
|
success=0
|
||||||
# parse arguments
|
# parse arguments
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
if [ "$arg" == "--force" -o "$arg" == "-f" ]; then
|
case "$arg" in
|
||||||
warning "$(gettext "the -f and --force options are no longer recognized")"
|
-q|--quiet) QUIET=1;;
|
||||||
msg2 "$(gettext "use options=(force) in the PKGBUILD instead")"
|
|
||||||
elif [ "$arg" == "--quiet" -o "$arg" == "-q" ]; then
|
|
||||||
QUIET=1
|
|
||||||
elif [ -z "$REPO_DB_FILE" ]; then
|
|
||||||
REPO_DB_FILE="$arg"
|
|
||||||
if [ -f "$REPO_DB_FILE" ]; then
|
|
||||||
if ! (bsdtar -tf "$REPO_DB_FILE" | grep -q "/desc"); then
|
|
||||||
error "$(gettext "Repository file '%s' is not a proper pacman database.")" "$REPO_DB_FILE"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
msg "$(gettext "Extracting database to a temporary location...")"
|
|
||||||
bsdtar -xf "$REPO_DB_FILE" -C "$gstmpdir"
|
|
||||||
elif [ "$cmd" == "repo-remove" ]; then
|
|
||||||
error "$(gettext "Repository file '%s' was not found.")" "$REPO_DB_FILE"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [ "$cmd" == "repo-add" ]; then
|
|
||||||
if [ -f "$arg" ]; then
|
|
||||||
if ! bsdtar -tf "$arg" .PKGINFO 2>&1 >/dev/null; then
|
|
||||||
error "$(gettext "'%s' is not a package file, skipping")" "$arg"
|
|
||||||
else
|
|
||||||
msg "$(gettext "Adding package '%s'")" "$arg"
|
|
||||||
|
|
||||||
if db_write_entry "$arg"; then
|
-f|--force)
|
||||||
success=1
|
warning "$(gettext "the -f and --force options are no longer recognized")"
|
||||||
fi
|
msg2 "$(gettext "use options=(force) in the PKGBUILD instead")"
|
||||||
fi
|
;;
|
||||||
else
|
|
||||||
error "$(gettext "Package '%s' not found.")" "$arg"
|
|
||||||
fi
|
|
||||||
elif [ "$cmd" == "repo-remove" ]; then
|
|
||||||
msg "$(gettext "Searching for package '%s'...")" "$arg"
|
|
||||||
|
|
||||||
if db_remove_entry "$arg"; then
|
*)
|
||||||
success=1
|
if [ -z "$REPO_DB_FILE" ]; then
|
||||||
|
REPO_DB_FILE="$arg"
|
||||||
|
LOCKFILE="$REPO_DB_FILE.lck"
|
||||||
|
check_repo_db
|
||||||
else
|
else
|
||||||
error "$(gettext "Package matching '%s' not found.")" "$arg"
|
case "$cmd" in
|
||||||
|
repo-add) add $arg && success=1 ;;
|
||||||
|
repo-remove) remove $arg && success=1 ;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
fi
|
;;
|
||||||
fi
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# if all operations were a success, re-zip database
|
# if at least one operation was a success, re-zip database
|
||||||
if [ $success -eq 1 ]; then
|
if [ $success -eq 1 ]; then
|
||||||
msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE"
|
msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE"
|
||||||
|
|
||||||
|
@ -370,22 +468,20 @@ if [ $success -eq 1 ]; then
|
||||||
|
|
||||||
filename=$(basename "$REPO_DB_FILE")
|
filename=$(basename "$REPO_DB_FILE")
|
||||||
|
|
||||||
pushd "$gstmpdir" 2>&1 >/dev/null
|
cd "$tmpdir"
|
||||||
if [ -n "$(ls)" ]; then
|
if [ -n "$(ls)" ]; then
|
||||||
bsdtar -c${TAR_OPT}f "$filename" *
|
bsdtar -c${TAR_OPT}f "$filename" *
|
||||||
else
|
else
|
||||||
# the database will be moved to .old below, and there will be no new one to replace it
|
# the database will be moved to .old below, and there will be no new one to replace it
|
||||||
error "$(gettext "All packages have been removed from the database. Deleting '%s'.")" "$REPO_DB_FILE"
|
error "$(gettext "All packages have been removed from the database. Deleting '%s'.")" "$REPO_DB_FILE"
|
||||||
fi
|
fi
|
||||||
popd 2>&1 >/dev/null
|
cd "$startdir"
|
||||||
|
|
||||||
[ -f "$REPO_DB_FILE" ] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
|
[ -f "$REPO_DB_FILE" ] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
|
||||||
[ -f "$gstmpdir/$filename" ] && mv "$gstmpdir/$filename" "$REPO_DB_FILE"
|
[ -f "$tmpdir/$filename" ] && mv "$tmpdir/$filename" "$REPO_DB_FILE"
|
||||||
else
|
else
|
||||||
msg "$(gettext "No packages modified, nothing to do.")"
|
msg "$(gettext "No packages modified, nothing to do.")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# remove the temp directory used to unzip
|
exit 0
|
||||||
[ -d "$gstmpdir" ] && rm -rf "$gstmpdir"
|
|
||||||
|
|
||||||
# vim: set ts=2 sw=2 noet:
|
# vim: set ts=2 sw=2 noet:
|
||||||
|
|
Loading…
Add table
Reference in a new issue