2018-11-16 12:43:55 +01:00
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
|
|
|
;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
|
2019-04-24 17:59:06 +02:00
|
|
|
;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
|
2019-06-08 05:04:36 +02:00
|
|
|
;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
|
2018-11-16 12:43:55 +01:00
|
|
|
;;;
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
;;;
|
|
|
|
;;; GNU Guix 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 3 of the License, or (at
|
|
|
|
;;; your option) any later version.
|
|
|
|
;;;
|
|
|
|
;;; GNU Guix 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 GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
(define-module (gnu installer newt user)
|
2018-12-05 06:48:38 +01:00
|
|
|
#:use-module (gnu installer user)
|
2019-05-07 11:48:51 +02:00
|
|
|
#:use-module ((gnu installer steps) #:select (&installer-step-abort))
|
2018-11-16 12:43:55 +01:00
|
|
|
#:use-module (gnu installer newt page)
|
|
|
|
#:use-module (gnu installer newt utils)
|
|
|
|
#:use-module (guix i18n)
|
|
|
|
#:use-module (newt)
|
|
|
|
#:use-module (ice-9 match)
|
|
|
|
#:use-module (ice-9 receive)
|
|
|
|
#:use-module (srfi srfi-1)
|
|
|
|
#:use-module (srfi srfi-26)
|
2019-05-07 11:48:51 +02:00
|
|
|
#:use-module (srfi srfi-34)
|
|
|
|
#:use-module (srfi srfi-35)
|
2018-11-16 12:43:55 +01:00
|
|
|
#:export (run-user-page))
|
|
|
|
|
2019-04-28 22:28:51 +02:00
|
|
|
(define* (run-user-add-page #:key (name "") (real-name "")
|
|
|
|
(home-directory ""))
|
|
|
|
"Run a form to enter the user name, home directory, and password. Use NAME,
|
|
|
|
REAL-NAME, and HOME-DIRECTORY as the initial values in the form."
|
2018-11-16 12:43:55 +01:00
|
|
|
(define (pad-label label)
|
2019-05-06 21:45:41 +02:00
|
|
|
(string-pad-right label 25))
|
2018-11-16 12:43:55 +01:00
|
|
|
|
|
|
|
(let* ((label-name
|
|
|
|
(make-label -1 -1 (pad-label (G_ "Name"))))
|
2019-04-28 22:28:51 +02:00
|
|
|
(label-real-name
|
|
|
|
(make-label -1 -1 (pad-label (G_ "Real name"))))
|
2018-11-16 12:43:55 +01:00
|
|
|
(label-home-directory
|
|
|
|
(make-label -1 -1 (pad-label (G_ "Home directory"))))
|
2019-04-24 17:59:06 +02:00
|
|
|
(label-password
|
|
|
|
(make-label -1 -1 (pad-label (G_ "Password"))))
|
2019-05-06 21:45:41 +02:00
|
|
|
(entry-width 35)
|
2019-04-25 11:43:44 +02:00
|
|
|
(entry-name (make-entry -1 -1 entry-width
|
|
|
|
#:initial-value name))
|
2019-04-28 22:28:51 +02:00
|
|
|
(entry-real-name (make-entry -1 -1 entry-width
|
|
|
|
#:initial-value real-name))
|
2019-04-25 11:43:44 +02:00
|
|
|
(entry-home-directory (make-entry -1 -1 entry-width
|
|
|
|
#:initial-value home-directory))
|
2019-05-05 12:54:40 +02:00
|
|
|
(password-visible-cb
|
2019-06-08 05:04:36 +02:00
|
|
|
(make-checkbox -1 -1 (G_ "Show") #\space "x "))
|
2019-04-24 17:59:06 +02:00
|
|
|
(entry-password (make-entry -1 -1 entry-width
|
2019-05-14 11:57:55 +02:00
|
|
|
#:flags (logior FLAG-PASSWORD
|
|
|
|
FLAG-SCROLL)))
|
2019-05-05 12:54:40 +02:00
|
|
|
(entry-grid (make-grid 3 5))
|
2018-11-16 12:43:55 +01:00
|
|
|
(button-grid (make-grid 1 1))
|
2019-01-06 11:04:14 +01:00
|
|
|
(ok-button (make-button -1 -1 (G_ "OK")))
|
2018-11-16 12:43:55 +01:00
|
|
|
(grid (make-grid 1 2))
|
|
|
|
(title (G_ "User creation"))
|
|
|
|
(set-entry-grid-field
|
|
|
|
(cut set-grid-field entry-grid <> <> GRID-ELEMENT-COMPONENT <>))
|
|
|
|
(form (make-form)))
|
|
|
|
|
|
|
|
(set-entry-grid-field 0 0 label-name)
|
|
|
|
(set-entry-grid-field 1 0 entry-name)
|
2019-04-28 22:28:51 +02:00
|
|
|
(set-entry-grid-field 0 1 label-real-name)
|
|
|
|
(set-entry-grid-field 1 1 entry-real-name)
|
|
|
|
(set-entry-grid-field 0 2 label-home-directory)
|
|
|
|
(set-entry-grid-field 1 2 entry-home-directory)
|
|
|
|
(set-entry-grid-field 0 3 label-password)
|
|
|
|
(set-entry-grid-field 1 3 entry-password)
|
2018-11-16 12:43:55 +01:00
|
|
|
|
2019-05-05 12:54:40 +02:00
|
|
|
(set-grid-field entry-grid
|
|
|
|
2 3
|
|
|
|
GRID-ELEMENT-COMPONENT
|
|
|
|
password-visible-cb
|
|
|
|
#:pad-left 1)
|
|
|
|
|
2018-11-16 12:43:55 +01:00
|
|
|
(set-grid-field button-grid 0 0 GRID-ELEMENT-COMPONENT ok-button)
|
|
|
|
|
|
|
|
(add-component-callback
|
|
|
|
entry-name
|
|
|
|
(lambda (component)
|
|
|
|
(set-entry-text entry-home-directory
|
2019-04-28 22:28:51 +02:00
|
|
|
(string-append "/home/" (entry-value entry-name)))
|
|
|
|
|
|
|
|
(when (string-null? (entry-value entry-real-name))
|
|
|
|
(set-entry-text entry-real-name
|
|
|
|
(string-titlecase (entry-value entry-name))))))
|
2018-11-16 12:43:55 +01:00
|
|
|
|
2019-05-05 12:54:40 +02:00
|
|
|
(add-component-callback
|
|
|
|
password-visible-cb
|
|
|
|
(lambda (component)
|
|
|
|
(set-entry-flags entry-password
|
|
|
|
FLAG-PASSWORD
|
|
|
|
FLAG-ROLE-TOGGLE)))
|
|
|
|
|
2018-11-16 12:43:55 +01:00
|
|
|
(add-components-to-form form
|
2019-04-28 22:28:51 +02:00
|
|
|
label-name label-real-name
|
|
|
|
label-home-directory label-password
|
|
|
|
entry-name entry-real-name
|
|
|
|
entry-home-directory entry-password
|
2019-05-05 12:54:40 +02:00
|
|
|
password-visible-cb
|
2018-11-16 12:43:55 +01:00
|
|
|
ok-button)
|
|
|
|
|
|
|
|
(make-wrapped-grid-window (vertically-stacked-grid
|
|
|
|
GRID-ELEMENT-SUBGRID entry-grid
|
|
|
|
GRID-ELEMENT-SUBGRID button-grid)
|
|
|
|
title)
|
|
|
|
(let ((error-page
|
|
|
|
(lambda ()
|
2018-12-05 14:08:33 +01:00
|
|
|
(run-error-page (G_ "Empty inputs are not allowed.")
|
2018-11-16 12:43:55 +01:00
|
|
|
(G_ "Empty input")))))
|
|
|
|
(receive (exit-reason argument)
|
|
|
|
(run-form form)
|
|
|
|
(dynamic-wind
|
|
|
|
(const #t)
|
|
|
|
(lambda ()
|
|
|
|
(when (eq? exit-reason 'exit-component)
|
|
|
|
(cond
|
|
|
|
((components=? argument ok-button)
|
2019-04-24 17:59:06 +02:00
|
|
|
(let ((name (entry-value entry-name))
|
2019-04-28 22:28:51 +02:00
|
|
|
(real-name (entry-value entry-real-name))
|
2019-04-24 17:59:06 +02:00
|
|
|
(home-directory (entry-value entry-home-directory))
|
|
|
|
(password (entry-value entry-password)))
|
2018-11-16 12:43:55 +01:00
|
|
|
(if (or (string=? name "")
|
|
|
|
(string=? home-directory ""))
|
|
|
|
(begin
|
|
|
|
(error-page)
|
|
|
|
(run-user-add-page))
|
2019-04-28 22:42:21 +02:00
|
|
|
(let ((password (confirm-password password)))
|
|
|
|
(if password
|
|
|
|
(user
|
|
|
|
(name name)
|
|
|
|
(real-name real-name)
|
|
|
|
(home-directory home-directory)
|
|
|
|
(password password))
|
|
|
|
(run-user-add-page #:name name
|
|
|
|
#:real-name real-name
|
|
|
|
#:home-directory
|
|
|
|
home-directory)))))))))
|
2018-11-16 12:43:55 +01:00
|
|
|
(lambda ()
|
|
|
|
(destroy-form-and-pop form)))))))
|
|
|
|
|
2019-04-28 22:42:21 +02:00
|
|
|
(define* (confirm-password password #:optional (try-again (const #f)))
|
2019-04-25 11:17:31 +02:00
|
|
|
"Ask the user to confirm PASSWORD, a possibly empty string. Call TRY-AGAIN,
|
2019-04-28 22:42:21 +02:00
|
|
|
a thunk, if the confirmation doesn't match PASSWORD, and return its result."
|
2019-04-25 11:17:31 +02:00
|
|
|
(define confirmation
|
|
|
|
(run-input-page (G_ "Please confirm the password.")
|
|
|
|
(G_ "Password confirmation required")
|
|
|
|
#:allow-empty-input? #t
|
2019-06-08 05:04:36 +02:00
|
|
|
#:input-visibility-checkbox? #t))
|
2019-04-25 11:17:31 +02:00
|
|
|
|
|
|
|
(if (string=? password confirmation)
|
|
|
|
password
|
|
|
|
(begin
|
|
|
|
(run-error-page
|
|
|
|
(G_ "Password mismatch, please try again.")
|
|
|
|
(G_ "Password error"))
|
|
|
|
(try-again))))
|
|
|
|
|
2019-04-24 21:54:28 +02:00
|
|
|
(define (run-root-password-page)
|
|
|
|
;; TRANSLATORS: Leave "root" untranslated: it refers to the name of the
|
|
|
|
;; system administrator account.
|
2019-04-25 11:17:31 +02:00
|
|
|
(define password
|
|
|
|
(run-input-page (G_ "Please choose a password for the system \
|
2019-04-24 21:54:28 +02:00
|
|
|
administrator (\"root\").")
|
2019-04-25 11:17:31 +02:00
|
|
|
(G_ "System administrator password")
|
2019-06-08 05:04:36 +02:00
|
|
|
#:input-visibility-checkbox? #t))
|
2019-04-25 11:17:31 +02:00
|
|
|
|
|
|
|
(confirm-password password run-root-password-page))
|
2019-04-24 21:54:28 +02:00
|
|
|
|
2018-11-16 12:43:55 +01:00
|
|
|
(define (run-user-page)
|
|
|
|
(define (run users)
|
|
|
|
(let* ((listbox (make-listbox
|
|
|
|
-1 -1 10
|
|
|
|
(logior FLAG-SCROLL FLAG-BORDER)))
|
|
|
|
(info-textbox
|
|
|
|
(make-reflowed-textbox
|
|
|
|
-1 -1
|
|
|
|
(G_ "Please add at least one user to system\
|
|
|
|
using the 'Add' button.")
|
|
|
|
40 #:flags FLAG-BORDER))
|
|
|
|
(add-button (make-compact-button -1 -1 (G_ "Add")))
|
|
|
|
(del-button (make-compact-button -1 -1 (G_ "Delete")))
|
|
|
|
(listbox-button-grid
|
|
|
|
(apply
|
|
|
|
vertically-stacked-grid
|
|
|
|
GRID-ELEMENT-COMPONENT add-button
|
|
|
|
`(,@(if (null? users)
|
|
|
|
'()
|
|
|
|
(list GRID-ELEMENT-COMPONENT del-button)))))
|
2019-01-06 11:04:14 +01:00
|
|
|
(ok-button (make-button -1 -1 (G_ "OK")))
|
2018-12-05 11:50:17 +01:00
|
|
|
(exit-button (make-button -1 -1 (G_ "Exit")))
|
2019-05-09 00:34:35 +02:00
|
|
|
(title (G_ "User creation"))
|
2018-11-16 12:43:55 +01:00
|
|
|
(grid
|
|
|
|
(vertically-stacked-grid
|
|
|
|
GRID-ELEMENT-COMPONENT info-textbox
|
|
|
|
GRID-ELEMENT-SUBGRID (horizontal-stacked-grid
|
|
|
|
GRID-ELEMENT-COMPONENT listbox
|
|
|
|
GRID-ELEMENT-SUBGRID listbox-button-grid)
|
|
|
|
GRID-ELEMENT-SUBGRID (horizontal-stacked-grid
|
|
|
|
GRID-ELEMENT-COMPONENT ok-button
|
2018-12-05 11:50:17 +01:00
|
|
|
GRID-ELEMENT-COMPONENT exit-button)))
|
2018-11-16 12:43:55 +01:00
|
|
|
(sorted-users (sort users (lambda (a b)
|
2018-12-05 06:48:38 +01:00
|
|
|
(string<= (user-name a)
|
|
|
|
(user-name b)))))
|
2018-11-16 12:43:55 +01:00
|
|
|
(listbox-elements
|
|
|
|
(map
|
|
|
|
(lambda (user)
|
|
|
|
`((key . ,(append-entry-to-listbox listbox
|
2018-12-05 06:48:38 +01:00
|
|
|
(user-name user)))
|
2018-11-16 12:43:55 +01:00
|
|
|
(user . ,user)))
|
|
|
|
sorted-users))
|
|
|
|
(form (make-form)))
|
|
|
|
|
|
|
|
|
|
|
|
(add-form-to-grid grid form #t)
|
|
|
|
(make-wrapped-grid-window grid title)
|
|
|
|
(if (null? users)
|
|
|
|
(set-current-component form add-button)
|
|
|
|
(set-current-component form ok-button))
|
|
|
|
|
|
|
|
(receive (exit-reason argument)
|
|
|
|
(run-form form)
|
|
|
|
(dynamic-wind
|
|
|
|
(const #t)
|
|
|
|
(lambda ()
|
|
|
|
(when (eq? exit-reason 'exit-component)
|
|
|
|
(cond
|
|
|
|
((components=? argument add-button)
|
|
|
|
(run (cons (run-user-add-page) users)))
|
|
|
|
((components=? argument del-button)
|
|
|
|
(let* ((current-user-key (current-listbox-entry listbox))
|
|
|
|
(users
|
|
|
|
(map (cut assoc-ref <> 'user)
|
|
|
|
(remove (lambda (element)
|
|
|
|
(equal? (assoc-ref element 'key)
|
|
|
|
current-user-key))
|
|
|
|
listbox-elements))))
|
|
|
|
(run users)))
|
|
|
|
((components=? argument ok-button)
|
|
|
|
(when (null? users)
|
|
|
|
(run-error-page (G_ "Please create at least one user.")
|
|
|
|
(G_ "No user"))
|
2018-12-05 06:48:38 +01:00
|
|
|
(run users))
|
2019-05-07 11:48:51 +02:00
|
|
|
(reverse users))
|
|
|
|
((components=? argument exit-button)
|
|
|
|
(raise
|
|
|
|
(condition
|
|
|
|
(&installer-step-abort)))))))
|
2018-11-16 12:43:55 +01:00
|
|
|
(lambda ()
|
|
|
|
(destroy-form-and-pop form))))))
|
2019-04-24 21:54:28 +02:00
|
|
|
|
|
|
|
;; Add a "root" user simply to convey the root password.
|
|
|
|
(cons (user (name "root")
|
|
|
|
(home-directory "/root")
|
|
|
|
(password (run-root-password-page)))
|
|
|
|
(run '())))
|