+order until the package is found. As a special case, `site-name' can be
+`nil', in which case `directory-on-site' is treated as a local directory."
+ :tag "Package repository"
+ :type '(repeat (choice (list :tag "Local" (const :tag "Local" nil) directory )
+ (list :tag "Remote" host-name directory) ))
+ :group 'package-get)
+
+;;;###autoload
+(defcustom package-get-download-sites
+ '(
+ ;; North America
+ ("Pre-Releases" "ftp.xemacs.org" "pub/xemacs/beta/experimental/packages")
+ ("xemacs.org" "ftp.xemacs.org" "pub/xemacs/packages")
+ ("crc.ca (Canada)" "ftp.crc.ca" "pub/packages/editors/xemacs/packages")
+ ("ualberta.ca (Canada)" "sunsite.ualberta.ca" "pub/Mirror/xemacs/packages")
+ ("uiuc.edu (United States)" "uiarchive.uiuc.edu" "pub/packages/xemacs/packages")
+ ("unc.edu (United States)" "metalab.unc.edu" "pub/packages/editors/xemacs/packages")
+ ("utk.edu (United States)" "ftp.sunsite.utk.edu" "pub/xemacs/packages")
+
+ ;; South America
+ ("unicamp.br (Brazil)" "ftp.unicamp.br" "pub/xemacs/packages")
+
+ ;; Europe
+ ("tuwien.ac.at (Austria)" "gd.tuwien.ac.at" "editors/xemacs/packages")
+ ("auc.dk (Denmark)" "sunsite.auc.dk" "pub/emacs/xemacs/packages")
+ ("doc.ic.ac.uk (England)" "sunsite.doc.ic.ac.uk" "packages/xemacs/packages")
+ ("funet.fi (Finland)" "ftp.funet.fi" "pub/mirrors/ftp.xemacs.org/pub/tux/xemacs/packages")
+ ("cenatls.cena.dgac.fr (France)" "ftp.cenatls.cena.dgac.fr" "Emacs/xemacs/packages")
+ ("pasteur.fr (France)" "ftp.pasteur.fr" "pub/computing/xemacs/packages")
+ ("tu-darmstadt.de (Germany)" "ftp.tu-darmstadt.de" "pub/editors/xemacs/packages")
+ ("kfki.hu (Hungary)" "ftp.kfki.hu" "pub/packages/xemacs/packages")
+ ("eunet.ie (Ireland)" "ftp.eunet.ie" "mirrors/ftp.xemacs.org/pub/xemacs/packages")
+ ("uniroma2.it (Italy)" "ftp.uniroma2.it" "unix/misc/dist/XEMACS/packages")
+ ("uio.no (Norway)" "sunsite.uio.no" "pub/xemacs/packages")
+ ("icm.edu.pl (Poland)" "ftp.icm.edu.pl" "pub/unix/editors/xemacs/packages")
+ ("srcc.msu.su (Russia)" "ftp.srcc.msu.su" "mirror/ftp.xemacs.org/packages")
+ ("sunet.se (Sweden)" "ftp.sunet.se" "pub/gnu/xemacs/packages")
+ ("cnlab-switch.ch (Switzerland)" "sunsite.cnlab-switch.ch" "mirror/xemacs/packages")
+
+ ;; Asia
+ ("aist.go.jp (Japan)" "ring.aist.go.jp" "pub/text/xemacs/packages")
+ ("asahi-net.or.jp (Japan)" "ring.asahi-net.or.jp" "pub/text/xemacs/packages")
+ ("dti.ad.jp (Japan)" "ftp.dti.ad.jp" "pub/unix/editor/xemacs/packages")
+ ("jaist.ac.jp (Japan)" "ftp.jaist.ac.jp" "pub/GNU/xemacs/packages")
+ ("nucba.ac.jp (Japan)" "mirror.nucba.ac.jp" "mirror/xemacs/packages")
+ ("sut.ac.jp (Japan)" "sunsite.sut.ac.jp" "pub/archives/packages/xemacs/packages")
+ ("tsukuba.ac.jp (Japan)" "ftp.netlab.is.tsukuba.ac.jp" "pub/GNU/xemacs/packages")
+ ("kreonet.re.kr (Korea)" "ftp.kreonet.re.kr" "pub/tools/emacs/xemacs/packages")
+ ("nctu.edu.tw (Taiwan)" "coda.nctu.edu.tw" "Editors/xemacs/packages")
+
+ ;; Africa
+ ("sun.ac.za (South Africa)" "ftp.sun.ac.za" "xemacs/packages")
+
+ ;; Middle East
+ ("isu.net.sa (Saudi Arabia)" "ftp.isu.net.sa" "pub/mirrors/ftp.xemacs.org/packages")
+
+ ;; Australia
+ ("aarnet.edu.au (Australia)" "mirror.aarnet.edu.au" "pub/xemacs/packages")
+ )
+ "*List of remote sites available for downloading packages.
+List format is '(site-description site-name directory-on-site).
+SITE-DESCRIPTION is a textual description of the site. SITE-NAME
+is the internet address of the download site. DIRECTORY-ON-SITE
+is the directory on the site in which packages may be found.
+This variable is used to initialize `package-get-remote', the
+variable actually used to specify package download sites."
+ :tag "Package download sites"
+ :type '(repeat (list (string :tag "Name") host-name directory))
+ :group 'package-get)
+
+(defcustom package-get-remove-copy t
+ "*After copying and installing a package, if this is t, then remove the
+copy. Otherwise, keep it around."
+ :type 'boolean
+ :group 'package-get)
+
+;; #### it may make sense for this to be a list of names.
+;; #### also, should we rename "*base*" to "*index*" or "*db*"?
+;; "base" is a pretty poor name.
+(defcustom package-get-base-filename "package-index.LATEST.pgp"
+ "*Name of the default package-get database file.
+This may either be a relative path, in which case it is interpreted
+with respect to `package-get-remote', or an absolute path."
+ :type 'file
+ :group 'package-get)
+
+(defvar package-get-user-index-filename
+ (paths-construct-path (list user-init-directory package-get-base-filename))
+ "Name for the user-specific location of the package-get database file.")
+
+(defcustom package-get-always-update nil
+ "*If Non-nil always make sure we are using the latest package index (base).
+Otherwise respect the `force-current' argument of `package-get-require-base'."
+ :type 'boolean
+ :group 'package-get)
+
+(defcustom package-get-require-signed-base-updates t
+ "*If set to a non-nil value, require explicit user confirmation for updates
+to the package-get database which cannot have their signature verified via PGP.
+When nil, updates which are not PGP signed are allowed without confirmation."
+ :type 'boolean
+ :group 'package-get)
+
+(defvar package-get-was-current nil
+ "Non-nil we did our best to fetch a current database.")
+
+
+;Shouldn't this be in package-ui?
+;;;###autoload
+(defun package-get-download-menu ()
+ "Build the `Add Download Site' menu."
+ (mapcar (lambda (site)
+ (vector (car site)
+ `(if (member (quote ,(cdr site))
+ package-get-remote)
+ (setq package-get-remote
+ (delete (quote ,(cdr site))
+ package-get-remote))
+ (package-ui-add-site (quote ,(cdr site))))
+ :style 'toggle
+ :selected `(member (quote ,(cdr site))
+ package-get-remote)))
+ package-get-download-sites))
+
+;;;###autoload
+(defun package-get-require-base (&optional force-current)
+ "Require that a package-get database has been loaded.
+If the optional FORCE-CURRENT argument or the value of
+`package-get-always-update' is Non-nil, try to update the database
+from a location in `package-get-remote'. Otherwise a local copy is used
+if available and remote access is never done.
+
+Please use FORCE-CURRENT only when the user is explictly dealing with packages
+and remote access is likely in the near future."
+ (setq force-current (or force-current package-get-always-update))
+ (unless (and (boundp 'package-get-base)
+ package-get-base
+ (or (not force-current) package-get-was-current))
+ (package-get-update-base nil force-current))
+ (if (or (not (boundp 'package-get-base))
+ (not package-get-base))
+ (error "Package-get database not loaded")
+ (setq package-get-was-current force-current)))
+
+(defconst package-get-pgp-signed-begin-line "^-----BEGIN PGP SIGNED MESSAGE-----"
+ "Text for start of PGP signed messages.")
+(defconst package-get-pgp-signature-begin-line "^-----BEGIN PGP SIGNATURE-----"
+ "Text for beginning of PGP signature.")
+(defconst package-get-pgp-signature-end-line "^-----END PGP SIGNATURE-----"
+ "Text for end of PGP signature.")
+
+;;;###autoload
+(defun package-get-update-base-entry (entry)
+ "Update an entry in `package-get-base'."
+ (let ((existing (assq (car entry) package-get-base)))
+ (if existing
+ (setcdr existing (cdr entry))
+ (setq package-get-base (cons entry package-get-base))
+ (package-get-custom-add-entry (car entry) (car (cdr entry))))))
+
+(defun package-get-locate-file (file &optional nil-if-not-found no-remote)
+ "Locate an existing FILE with respect to `package-get-remote'.
+If FILE is an absolute path or is not found, simply return FILE.
+If optional argument NIL-IF-NOT-FOUND is non-nil, return nil
+if FILE can not be located.
+If NO-REMOTE is non-nil never search remote locations."
+ (if (file-name-absolute-p file)
+ file
+ (let ((entries package-get-remote)
+ (expanded nil))
+ (while entries
+ (unless (and no-remote (caar entries))
+ (let ((expn (package-get-remote-filename (car entries) file)))
+ (if (and expn (file-exists-p expn))
+ (setq entries nil
+ expanded expn))))
+ (setq entries (cdr entries)))
+ (or expanded
+ (and (not nil-if-not-found)
+ file)))))
+
+(defun package-get-locate-index-file (no-remote)
+ "Locate the package-get index file. Do not return remote paths if NO-REMOTE
+is non-nil."
+ (or (package-get-locate-file package-get-base-filename t no-remote)
+ (if (file-exists-p package-get-user-index-filename)
+ package-get-user-index-filename)))
+
+(defun package-get-maybe-save-index (filename)
+ "Offer to save the current buffer as the local package index file,
+if different."
+ (let ((location (package-get-locate-index-file t)))
+ (unless (and filename (equal filename location))
+ (unless (and location
+ (equal (md5 (current-buffer))
+ (with-temp-buffer
+ (insert-file-contents-literally location)
+ (md5 (current-buffer)))))
+ (unless (and location (file-writable-p location))
+ (setq location package-get-user-index-filename))
+ (when (y-or-n-p (concat "Update package index in " location "? "))
+ (let ((coding-system-for-write 'binary))
+ (write-file location)))))))
+
+
+;;;###autoload
+(defun package-get-update-base (&optional db-file force-current)
+ "Update the package-get database file with entries from DB-FILE.
+Unless FORCE-CURRENT is non-nil never try to update the database."
+ (interactive
+ (let ((dflt (package-get-locate-index-file nil)))
+ (list (read-file-name "Load package-get database: "
+ (file-name-directory dflt)
+ dflt
+ t
+ (file-name-nondirectory dflt)))))
+ (setq db-file (expand-file-name (or db-file
+ (package-get-locate-index-file
+ (not force-current)))))
+ (if (not (file-exists-p db-file))
+ (error "Package-get database file `%s' does not exist" db-file))
+ (if (not (file-readable-p db-file))
+ (error "Package-get database file `%s' not readable" db-file))
+ (let ((buf (get-buffer-create "*package database*")))
+ (unwind-protect
+ (save-excursion
+ (set-buffer buf)
+ (erase-buffer buf)
+ (insert-file-contents-literally db-file)
+ (package-get-update-base-from-buffer buf)
+ (if (file-remote-p db-file)
+ (package-get-maybe-save-index db-file)))
+ (kill-buffer buf))))
+
+;;;###autoload
+(defun package-get-update-base-from-buffer (&optional buf)
+ "Update the package-get database with entries from BUFFER.
+BUFFER defaults to the current buffer. This command can be
+used interactively, for example from a mail or news buffer."
+ (interactive)
+ (setq buf (or buf (current-buffer)))
+ (let (content-beg content-end beg end)
+ (save-excursion
+ (set-buffer buf)
+ (goto-char (point-min))
+ (setq content-beg (point))
+ (setq content-end (save-excursion (goto-char (point-max)) (point)))
+ (when (re-search-forward package-get-pgp-signed-begin-line nil t)
+ (setq beg (match-beginning 0))
+ (setq content-beg (match-end 0)))
+ (when (re-search-forward package-get-pgp-signature-begin-line nil t)
+ (setq content-end (match-beginning 0)))
+ (when (re-search-forward package-get-pgp-signature-end-line nil t)
+ (setq end (point)))
+ (if (not (and content-beg content-end beg end))
+ (or (not package-get-require-signed-base-updates)
+ (yes-or-no-p "Package-get entries not PGP signed, continue? ")
+ (error "Package-get database not updated")))
+ (if (and content-beg content-end beg end)
+ (if (not (condition-case nil
+ (or (fboundp 'mc-pgp-verify-region)
+ (load-library "mc-pgp")
+ (fboundp 'mc-pgp-verify-region))
+ (error nil)))
+ (or (not package-get-require-signed-base-updates)
+ (yes-or-no-p
+ "No mailcrypt; can't verify package-get DB signature, continue? ")
+ (error "Package-get database not updated"))))
+ (if (and beg end
+ (fboundp 'mc-pgp-verify-region)
+ (or (not
+ (condition-case err
+ (mc-pgp-verify-region beg end)
+ (file-error
+ (and (string-match "No such file" (nth 2 err))
+ (or (not package-get-require-signed-base-updates)
+ (yes-or-no-p
+ (concat "Can't find PGP, continue without "
+ "package-get DB verification? ")))))
+ (t nil)))))
+ (error "Package-get PGP signature failed to verify"))
+ ;; ToDo: We should call package-get-maybe-save-index on the region
+ (package-get-update-base-entries content-beg content-end)
+ (message "Updated package-get database"))))