XEmacs 21.2.41 "Polyhymnia".
[chise/xemacs-chise.git.1] / lisp / package-net.el
1 ;;; package-net.el --- Installation and Maintenance of XEmacs packages
2
3 ;; Copyright (C) 2000 Andy Piper.
4
5 ;; Keywords: internal
6
7 ;; This file is part of XEmacs.
8
9 ;; XEmacs is free software; you can redistribute it and/or modify it
10 ;; under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; XEmacs is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 ;; General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 ;; 02111-1307, USA.
23
24 ;;; Synched up with: Not in FSF
25
26 ;;; Commentary:
27
28 ;; Manipulate packages for the netinstall setup utility
29
30 ;; The process should be so:
31
32 ;; 1. The package maintainer or release manager makes a release
33 ;; announcement.
34 ;;
35 ;; 2. For a new package releases the netinstall maintainer simply
36 ;; needs to update `ftp://ftp.xemacs.org/pub/xemacs/setup.ini'. This is
37 ;; harder than it sounds because the file also includes information
38 ;; about the binary releases. At the moment going to the netinstall
39 ;; directory and typing:
40 ;;
41 ;;   `make XEMACS=<current executable location> setup.ini' 
42 ;;
43 ;; will do the right thing provided that:
44 ;; 
45 ;; (a) `package-net-cygwin32-binary-size' and
46 ;; `package-net-win32-binary-size' are set correctly.
47 ;;
48 ;; (b) The binary pointed to by `XEMACS' has a current
49 ;; `package-index.LATEST.pgp' file. If you don't specify the XEMACS=
50 ;; part then you will get whatever is current for your build tree -
51 ;; which is probably not what you want.
52 ;;
53 ;; You can run `package-net-convert-index-to-ini' manually and specify
54 ;; REMOTE but I generally found that to be inconvenient and error-prone.
55 ;;
56 ;; 3. For package releases that's all you need to do. For binary
57 ;; releases you need to build both cygwin and win32 binaries and put
58 ;; them in appropriate tarballs:
59 ;;
60 ;; For cygwin, configure, make and install and then do (this is for
61 ;; 21.1.13):
62 ;;
63 ;;   cd <install dir>
64 ;;   tar cvzf xemacs-i686-pc-cygwin32-21.1.13.tar.gz \
65 ;;      ./bin/i686-pc-cygwin32 ./lib/xemacs-21.1.13 \
66 ;;      ./lib/xemacs/lock ./man/man1/xemacs.1 \
67 ;;      ./man/man1/ctags.1 ./man/man1/gnu*.1'
68 ;;
69 ;;  Note that the naming of the package is important. Don't be tempted
70 ;;  to change the order in any way.
71 ;;
72 ;; For win32 build and install the release and then (again for
73 ;; 21.1.13):
74 ;;
75 ;;   cd <install dir>
76 ;;   tar cvzf xemacs-i386-pc-win32-21.1.13.tar.gz ./XEmacs-21.1.13
77 ;; 
78 ;; The binaries should be uploaded to
79 ;; `ftp://ftp.xemacs.org/pub/xemacs/binaries/cygwin32' and
80 ;; `ftp://ftp.xemacs.org/pub/xemacs/binaries/win32' respectively. Take
81 ;; a note of their sizes and set `package-net-cygwin32-binary-size'
82 ;; and `package-net-win32-binary-size' appropriately in this file and
83 ;; then follow step 2.
84
85 (require 'package-admin)
86 (require 'package-get)
87
88 ;; What path should we use from the myriad available?
89 ;; For netinstall we just want something simple, and anyway this is only to 
90 ;; bootstrap the process. This will be:
91 ;; <root>/setup/ for native windows
92 ;; <root>/lib/xemacs/setup for cygwin.
93 ;;
94 ;;; To Do:
95 ;;
96 ;; 1. Package update functions should also update the installed
97 ;; database so that running setup.exe again does not reinstall
98 ;; packages.
99 ;;
100 ;; 2. Generating setup.ini should be more automatic.
101
102 (defvar package-net-cygwin32-binary-size 6917126
103   "The size in bytes of the cygwin32 binary distribution.")
104
105 (defvar package-net-win32-binary-size 6563941
106   "The size in bytes of the win32 binary distribution.")
107
108 ;;;###autoload
109 (defun package-net-setup-directory ()
110   (file-truename (concat data-directory "../../" (if (eq system-type 'cygwin32)
111                                                      "xemacs/setup/" "setup/"))))
112
113 (defun package-net-convert-index-to-ini (&optional destdir remote version)
114   "Convert the package index to ini file format in DESTDIR.
115 DESTDIR defaults to the value of `data-directory'."
116   (package-get-require-base remote)
117
118   (setq destdir (file-name-as-directory (or destdir data-directory)))
119   (let ((buf (get-buffer-create "*setup.ini*")))
120     (unwind-protect
121         (save-excursion
122           (set-buffer buf)
123           (erase-buffer buf)
124           (goto-char (point-min))
125           (let ((entries package-get-base) entry plist)
126             (insert "# This file is automatically generated.  If you edit it, your\n")
127             (insert "# edits will be discarded next time the file is generated.\n")
128             (insert "#\n\n")
129             (insert (format "setup-timestamp: %d\n" 
130                             (+ (* (car (current-time)) 65536) (car (cdr (current-time))))))
131             (insert (format "setup-version: %s\n\n" (or version "1.0")))
132             ;; Native version
133             (insert (format "@ %s\n" "xemacs-i386-pc-win32"))
134             (insert (format "version: %s\n" emacs-program-version))
135             (insert "type: native\n")
136             (insert (format "install: binaries/win32/%s %d\n\n"
137                             (concat emacs-program-name
138                                     "-i386-pc-win32-"
139                                     emacs-program-version ".tar.gz")
140                             package-net-win32-binary-size))
141             ;; Cygwin version
142             (insert (format "@ %s\n" "xemacs-i686-pc-cygwin32"))
143             (insert (format "version: %s\n" emacs-program-version))
144             (insert "type: cygwin\n")
145             (insert (format "install: binaries/cygwin32/%s %d\n\n"
146                             (concat emacs-program-name
147                                     "-i686-pc-cygwin32-"
148                                     emacs-program-version ".tar.gz") 
149                             package-net-cygwin32-binary-size))
150             ;; Standard packages
151             (while entries
152               (setq entry (car entries))
153               (setq plist (car (cdr entry)))
154               ;; ignore mule packages
155               (unless (or (memq 'mule-base (plist-get plist 'requires))
156                           (eq 'mule-base (car entry)))
157                 (insert (format "@ %s\n" (symbol-name (car entry))))
158                 (insert (format "version: %s\n" (plist-get plist 'version)))
159                 (insert (format "install: packages/%s %s\n" (plist-get plist 'filename)
160                                 (plist-get plist 'size)))
161               ;; These are not supported as yet
162               ;;
163               ;; (insert (format "source: %s\n" (plist-get plist 'source)))
164               ;; (insert "[prev]\n")
165               ;; (insert (format "version: %s\n" (plist-get plist 'version)))
166               ;; (insert (format "install: %s\n" (plist-get plist 'filename)))
167               ;; (insert (format "source: %s\n" (plist-get plist 'source)))
168                 (insert "\n"))
169               (setq entries (cdr entries))))
170           (insert "# setup.ini file ends here\n")
171           (write-region (point-min) (point-max) (concat destdir "setup.ini")))
172       (kill-buffer buf))))
173
174 (defun package-net-batch-convert-index-to-ini ()
175   "Convert the package index to ini file format."
176   (unless noninteractive
177     (error "`package-net-batch-convert-index-to-ini' is to be used only with -batch"))
178   (let ((dir (car command-line-args-left))
179         (version (car (cdr command-line-args-left)))
180         (package-get-require-signed-base-updates nil))
181     (package-net-convert-index-to-ini dir nil version)))
182
183 ;;;###autoload
184 (defun package-net-update-installed-db (&optional destdir)
185   "Write out the installed package index in a net install suitable format.
186 If DESTDIR is non-nil then use that as the destination directory. 
187 DESTDIR defaults to the value of `package-net-setup-directory'."
188   ;; Need the local version
189   (package-get-require-base)
190
191   (setq destdir (file-name-as-directory 
192                  (or destdir (package-net-setup-directory))))
193   (let ((buf (get-buffer-create "*installed.db*")))
194     (unwind-protect
195         (save-excursion
196           (set-buffer buf)
197           (erase-buffer buf)
198           (goto-char (point-min))
199           (let ((entries package-get-base) entry plist)
200             (while entries
201               (setq entry (car entries))
202               (setq plist (car (cdr entry)))
203               (insert (format "%s %s %s\n" (symbol-name (car entry))
204                               (plist-get plist 'filename)
205                               (plist-get plist 'size)))
206               (setq entries (cdr entries))))
207           (make-directory-path destdir)
208           (write-region (point-min) (point-max) (concat destdir "installed.db")))
209       (kill-buffer buf))))
210
211 (defun package-net-convert-download-sites-to-mirrors (&optional destdir)
212   "Write out the download site list in a net install suitable format.
213 If DESTDIR is non-nil then use that as the destination directory. 
214 DESTDIR defaults to the value of `data-directory'."
215
216   (setq destdir (file-name-as-directory (or destdir data-directory)))
217   (let ((buf (get-buffer-create "*mirrors.lst*")))
218     (unwind-protect
219         (save-excursion
220           (set-buffer buf)
221           (erase-buffer buf)
222           (goto-char (point-min))
223           (let ((entries package-get-download-sites) entry)
224             (while entries
225               (setq entry (car entries))
226               (insert (format "ftp://%s/%s;%s;%s\n"
227                               (nth 1 entry) (substring (nth 2 entry) 0 -9)
228                               (nth 0 entry) (nth 0 entry)))
229               (setq entries (cdr entries))))
230           (write-region (point-min) (point-max) (concat destdir "mirrors.lst")))
231       (kill-buffer buf))))