projects
/
rrq
/
newlisp-ftw.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
21c10f5
)
use upfront sudo
author
Ralph Ronnquist
<ralph.ronnquist@gmail.com>
Mon, 30 May 2022 01:51:08 +0000
(11:51 +1000)
committer
Ralph Ronnquist
<ralph.ronnquist@gmail.com>
Mon, 30 May 2022 01:51:08 +0000
(11:51 +1000)
enitool.lsp
patch
|
blob
|
history
diff --git
a/enitool.lsp
b/enitool.lsp
index 2511142e9a9ef3804548e74d9ba6305de42363f3..6e72882f6f7d93f642a3ecfcddaa745e9475fa82 100755
(executable)
--- a/
enitool.lsp
+++ b/
enitool.lsp
@@
-13,6
+13,11
@@
;(signal 2 (fn (x) (exit)))
;(signal 2 (fn (x) (exit)))
+(when (!= "0" (if (exec "id -u") ($it 0) ""))
+ (let ((SUDO (if (exec "command -v sudo") ($it 0) "/usr/bin/sudo")))
+ (wait-pid (process (join (cons SUDO (main-args) " ")))))
+ (exit 0))
+
(constant
;; all "block starters", including blank lines
'ENI-KEY '( "iface" "mapping" "auto" "allow-\\w*" "rename"
(constant
;; all "block starters", including blank lines
'ENI-KEY '( "iface" "mapping" "auto" "allow-\\w*" "rename"
@@
-20,17
+25,15
@@
;; regex to identify block starters
'ENI-HEAD (format "^\\s*#?\\s*(%s)" (join ENI-KEY "|"))
'ENI-COMMENT "^\\s*#"
;; regex to identify block starters
'ENI-HEAD (format "^\\s*#?\\s*(%s)" (join ENI-KEY "|"))
'ENI-COMMENT "^\\s*#"
- 'PROC (if (exec (format "command -v %s" (or (env "EDITOR") "nano"))) ($it 0)
- "/bin/nano")
- 'SUDO (if (exec "command -v sudo") ($it 0) "")
+ 'EDITOR (or (env "EDITOR") "nano")
+ 'PROC (if (exec (format "command -v %s" EDITOR)) ($it 0) "/bin/nano")
)
(define (is-eni-key PAT S)
(when (regex PAT S 0) true))
(define (is-eni-comment S)
)
(define (is-eni-key PAT S)
(when (regex PAT S 0) true))
(define (is-eni-comment S)
- (is-eni-key ENI-COMMENT S)
- )
+ (is-eni-key ENI-COMMENT S))
(define (istrue? A B)
(list A B) (= A B true))
(define (istrue? A B)
(list A B) (= A B true))
@@
-40,7
+43,7
@@
;; Pull out the block headed by the B line. If this head is a blank
;; line, then the block includes preceeding comment and the blank line
;; Pull out the block headed by the B line. If this head is a blank
;; line, then the block includes preceeding comment and the blank line
-;; only. Otherwise it includes preceeding comment, head line and
f
the
+;; only. Otherwise it includes preceeding comment, head line and the
;; following mix of non-head lines and comment lines (i.e. up to next
;; head line). FROM is the line after the prior block, and it is moved
;; to end of this block.
;; following mix of non-head lines and comment lines (i.e. up to next
;; head line). FROM is the line after the prior block, and it is moved
;; to end of this block.
@@
-76,18
+79,17
@@
; Edit a file
(define (edit-file I FILE)
; Edit a file
(define (edit-file I FILE)
- (wait-pid (process (format "%s
%s +%d %s" SUDO
PROC (int I) FILE))))
+ (wait-pid (process (format "%s
+%d %s"
PROC (int I) FILE))))
(define (ensure-newline TXT)
(if (empty? TXT) "" (ends-with TXT "\n") TXT (string TXT "\n")))
(define (update-file B E TXT FILE)
(define (ensure-newline TXT)
(if (empty? TXT) "" (ends-with TXT "\n") TXT (string TXT "\n")))
(define (update-file B E TXT FILE)
- ;;(println (list 'update-file B E TXT FILE))
(let ((DATA (parse (read-file FILE) "\n")))
(write-file TXT (string (join (0 B DATA) "\n" true)
(ensure-newline (read-file TXT))
(join (E DATA) "\n")))
(let ((DATA (parse (read-file FILE) "\n")))
(write-file TXT (string (join (0 B DATA) "\n" true)
(ensure-newline (read-file TXT))
(join (E DATA) "\n")))
- (exec (format "
%s mv %s %s" SUDO
TXT FILE))
+ (exec (format "
mv %s %s"
TXT FILE))
))
(define (key-command-select I FILE) ; PATH
))
(define (key-command-select I FILE) ; PATH
@@
-110,7
+112,7
@@
(let ((BLOCK (find-block (- (int I) 1) FILE))
(TMP "/tmp/enitool/tmp.conf"))
(when (= (3 BLOCK) '(""))
(let ((BLOCK (find-block (- (int I) 1) FILE))
(TMP "/tmp/enitool/tmp.conf"))
(when (= (3 BLOCK) '(""))
- (exec (format "
%s ed %s" SUDO
FILE)
+ (exec (format "
ed -s %s"
FILE)
(format "%dd\nw\n" (+ 1 (BLOCK 0)))))))
(define (toggle-commenting I FILE)
(format "%dd\nw\n" (+ 1 (BLOCK 0)))))))
(define (toggle-commenting I FILE)
@@
-134,7
+136,7
@@
((member $2 '("KEY_RIGHT" "RETURN")) (key-command-select $1 FILE))
((= $2 "d") (delete-block-maybe $1 FILE))
((= $2 "#") (toggle-commenting $1 FILE))
((member $2 '("KEY_RIGHT" "RETURN")) (key-command-select $1 FILE))
((= $2 "d") (delete-block-maybe $1 FILE))
((= $2 "#") (toggle-commenting $1 FILE))
- ((= $2 "e") (edit-file $1 FILE
SUDO
))
+ ((= $2 "e") (edit-file $1 FILE))
)))
(define (iselect POS FILE)
)))
(define (iselect POS FILE)
@@
-142,12
+144,11
@@
"enitool" FILE (int POS) FILE)))
(change-dir "/etc/network")
"enitool" FILE (int POS) FILE)))
(change-dir "/etc/network")
-(wait-pid (process (format "
%s mkdir -m 777 -p /tmp/enitool" SUDO
)))
+(wait-pid (process (format "
mkdir -m 777 -p /tmp/enitool"
)))
(while PATH
(while PATH
- (let ((SEL (apply iselect (PATH 0))) (FILE (PATH 0 1)))
- (if SEL (command-dispatch (SEL 0) FILE)
- (pop PATH))
- ))
+ (if (apply iselect (PATH 0))
+ (command-dispatch ($it 0) (PATH 0 1))
+ (pop PATH)))
(exit 0)
(exit 0)