XEmacs 21.4.2 "Developer-Friendly Unix APIs".
[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 7559692
103   "The size in bytes of the cygwin32 binary distribution.")
104
105 (defvar package-net-win32-binary-size 7421788
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: 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: 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-generate-bin-ini (&optional destdir version)
175   "Convert the package index to ini file format in DESTDIR.
176 DESTDIR defaults to the value of `data-directory'."
177
178   (setq destdir (file-name-as-directory (or destdir data-directory)))
179   (let ((buf (get-buffer-create "*setup-bin.ini*")))
180     (unwind-protect
181         (save-excursion
182           (set-buffer buf)
183           (erase-buffer buf)
184           (goto-char (point-min))
185           (insert "# This file is automatically generated.  If you edit it, your\n")
186           (insert "# edits will be discarded next time the file is generated.\n")
187           (insert "#\n\n")
188           (insert (format "setup-timestamp: %d\n" 
189                           (+ (* (car (current-time)) 65536) (car (cdr (current-time))))))
190           (insert (format "setup-version: %s\n\n" (or version "1.0")))
191           ;; Native version
192           (insert (format "@ %s\n" "xemacs-i386-pc-win32"))
193           (insert (format "version: %s\n" emacs-program-version))
194           (insert "type: native\n")
195           (insert (format "install: win32/%s %d\n\n"
196                           (concat emacs-program-name
197                                   "-i586-pc-win32-"
198                                     emacs-program-version ".tar.gz")
199                           package-net-win32-binary-size))
200           ;; Cygwin version
201           (insert (format "@ %s\n" "xemacs-i686-pc-cygwin"))
202           (insert (format "version: %s\n" emacs-program-version))
203           (insert "type: cygwin\n")
204           (insert (format "install: cygwin32/%s %d\n\n"
205                           (concat emacs-program-name
206                                   "-i686-pc-cygwin-"
207                                   emacs-program-version ".tar.gz") 
208                           package-net-cygwin32-binary-size))
209           (insert "# setup.ini file ends here\n")
210           (write-region (point-min) (point-max) (concat destdir "setup-bin.ini")))
211       (kill-buffer buf))))
212
213 (defun package-net-batch-generate-bin-ini ()
214   "Convert the package index to ini file format."
215   (unless noninteractive
216     (error "`package-net-batch-generate-bin-ini' is to be used only with -batch"))
217   (let ((dir (car command-line-args-left))
218         (version (car (cdr command-line-args-left))))
219     (package-net-generate-bin-ini dir version)))
220
221 ;;;###autoload
222 (defun package-net-update-installed-db (&optional destdir)
223   "Write out the installed package index in a net install suitable format.
224 If DESTDIR is non-nil then use that as the destination directory. 
225 DESTDIR defaults to the value of `package-net-setup-directory'."
226
227   (when (or (eq system-type 'cygwin32)
228             (eq system-type 'window-nt))
229     (setq destdir (file-name-as-directory 
230                    (or destdir (package-net-setup-directory))))
231     (let ((buf (get-buffer-create "*installed.db*")))
232       (unwind-protect
233           (save-excursion
234             (set-buffer buf)
235             (erase-buffer buf)
236             (goto-char (point-min))
237             ;; we use packages-package-list here as we actually want to
238             ;; update relative to the installed reality
239             (let ((entries packages-package-list) entry version)
240               (while entries
241                 (setq entry (car entries))
242                 (setq version (plist-get (cdr entry) :version))
243                 ;; Unfortunately we can't read the size from this
244                 (insert (format "%s %s-%3.2f-pkg.tar.gz 0\n" (symbol-name (car entry))
245                                 (symbol-name (car entry))
246                                 version))
247                 (setq entries (cdr entries))))
248             (make-directory-path destdir)
249             (write-region (point-min) (point-max) (concat destdir "installed.db")))
250         (kill-buffer buf)))))
251
252 (defun package-net-convert-download-sites-to-mirrors (&optional destdir)
253   "Write out the download site list in a net install suitable format.
254 If DESTDIR is non-nil then use that as the destination directory. 
255 DESTDIR defaults to the value of `data-directory'."
256
257   (setq destdir (file-name-as-directory (or destdir data-directory)))
258   (let ((buf (get-buffer-create "*mirrors.lst*")))
259     (unwind-protect
260         (save-excursion
261           (set-buffer buf)
262           (erase-buffer buf)
263           (goto-char (point-min))
264           (let ((entries package-get-download-sites) entry)
265             (while entries
266               (setq entry (car entries))
267               (insert (format "ftp://%s/%s;%s;%s\n"
268                               (nth 1 entry) (substring (nth 2 entry) 0 -9)
269                               (nth 0 entry) (nth 0 entry)))
270               (setq entries (cdr entries))))
271           (write-region (point-min) (point-max) (concat destdir "mirrors.lst")))
272       (kill-buffer buf))))