next question: remote-test / remote-home ?

Andreas Reuleaux rx at a-rx.info
Wed Aug 3 18:07:41 BST 2022


OK, I am progressing.

And I am rewriting some of my propellor configuration in consfigurator
now, thus my next question:

My original propellor bash-property looks like this:
- I am creating my own .bashrc (in Scheme! - as I tired of Bash - but
never mind the details, and I can apply this to different users: Rx,
Guest, etc., translated to (User "rx"), (User "guest"), ... with pusr)

My real issue is with safety measure before:
I store away the original .bashrc as .bashrc.orig (unless a .bashrc.orig
exists already) - which is simple enough to understand (i.e. it is
stored away on the very first usage of this my bash property only):


--8<---------------cut here---------------start------------->8---
bash :: Usr -> Property UnixLike
bash = \u -> propertyList "bash configured" $ props
             & userScriptProperty (pusr u)
             (tail
              [ ""
              
              -- keep ~/.bashrc as ~/.bashrc.orig
              , "if [ ! -e ~/.bashrc.orig ]; then mv ~/.bashrc ~/.bashrc.orig; fi"
              ]) `assume` MadeChange

              -- ... for stamp, cf. below

             & "/home/rx/.bashrc" `File.hasContent`
             (tail
               [ ""
               , "# -*- mode: shell-script -*-"
               , "source ~/cfg/bash/stamp"
               , "source <(~/cfg/bash/bashrc.scm)"
               ]
             ) `assume` MadeChange
--8<---------------cut here---------------end--------------->8---


Now in consfigurator, very roughly:


--8<---------------cut here---------------start------------->8---

(defproplist my-bashrc :posix ()
  
  (:desc #?"${(get-connattr :remote-home)}.bashrc" )

  (unless (probe-file (uiop:native-namestring "~/.bashrc.orig"))
    (cmd:single "if [ ! -e ~/.bashrc.orig ]; then mv ~/.bashrc ~/.bashrc.orig; fi")
    )
  
  (file:has-content (uiop:native-namestring "~/cfg/bash/stamp")
		    `(
		      "case $- in"
		      "    *i*) ;;"
		      "    *) return ;; "
		      "esac"
		      )
		    )

  
  (file:has-content (uiop:native-namestring "~/.bashrc")
		    `(
		      "# -*- mode: shell-script -*-"
		      "source ~/cfg/bash/stamp"
		      "source <(~/cfg/bash/bashrc.scm)"
		      )
		    )
  
  )
--8<---------------cut here---------------end--------------->8---


and I can apply this on my host softland with different users:

--8<---------------cut here---------------start------------->8---
(deploy-these ((:ssh :user "rx")) softland (my-bashrc))

(deploy-these ((:ssh :user "guest")) softland (my-bashrc))

etc
--8<---------------cut here---------------end--------------->8---

Now I am a little more ambitious, and would like to move the
logic "unless .bashrc.orig exists already" to the common lisp /
consfigurator side:


--8<---------------cut here---------------start------------->8---

(defproplist my-bashrc :posix ()
  
  (:desc #?"${(get-connattr :remote-home)}.bashrc" )

  (unless (probe-file (uiop:native-namestring "~/.bashrc.orig"))
    (cmd:single "mv ~/.bashrc ~/.bashrc.orig")
    )
  
  (file:has-content (uiop:native-namestring "~/cfg/bash/stamp")
		    `(
		      "case $- in"
		      "    *i*) ;;"
		      "    *) return ;; "
		      "esac"
		      )
		    )

  
  (file:has-content (uiop:native-namestring "~/.bashrc")
		    `(
		      "# -*- mode: shell-script -*-"
		      "source ~/cfg/bash/stamp"
		      "source <(~/cfg/bash/bashrc.scm)"
		      )
		    )
  
  )
--8<---------------cut here---------------end--------------->8---


But this probe-file (and uiop:native-namestring for "~") is wrong (as I
understand): this works on my local machine !!

Whereas really I want to test if ~/.bashrc.orig exists already, on the
remote machine, in the account of rx / guest / ... there.

Something along these lines (I guess):

--8<---------------cut here---------------start------------->8---
 (unless (remote-test "-f" #?"${(get-connattr :remote-home)}.bashrc.orig")
    (cmd:single "mv ~/.bashrc ~/.bashrc.orig")
    )
--8<---------------cut here---------------end--------------->8---

which unfortunately I cannot do (at least not within a defproplist) [?].
- which is strange enough, as I *can* use
#?"${(get-connattr :remote-home)}.bashrc" in the :desc (description).

Maybe I have to create (just) a property w/ defprop ? - Just a boolean
test, really, if a (remote) file .bashrc.orig exists in a (remote) home
directory? How?

Thanks again in advance.
-A 






More information about the sgo-software-discuss mailing list