Setting up multiple machine configs [Intermediate?]

Forum › Forums › General › Tips and Tricks › Setting up multiple machine configs [Intermediate?]

  • This topic has 11 replies, 8 voices, and was last updated Apr 22-5:38 am by Robin.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #202195
    m4r35n357
    Member

      It is often said that copying a single text file is simpler and less error-prone than transferring a hierarchy of complex text or XML. This is mostly true, but in practice each machine is likely to have its own particularities, and even copying simple text files can get messy & confusing catering for these differences. Is there a “better” way? Of course! In setting up FVWM on four machines I found the graphical diff most useful (I now need to find a non-GTK3 diff, looking at xxdiff . . .).

      Now, doing a graphical diff between machines? Yes, if you have SSH access set up between them. Let’s take ~/.fvwm/config as a concrete example. A shell newbie will realize that the “remote” config can be obtained by:

      ssh remote cat ~/.fvwm/config

      so far so good, perhaps shell command substitution can help here – but no, it just puts the command output into a string that you can assign to a variable, or form part of a command, but it is not helpful here!

      The answer is a feature of bash (NOT POSIX) called process substitution (terrible, terrible name!). Look it up in the bash man page and see if the description makes sense to you 😉 Like command substitution, it makes the command output accessible, but instead of putting the output into a string it puts it into a file (descriptor). To compare & contrast the two, here is command substitution:

      $(ssh remote cat ~/.fvwm/config)

      and here is process substitution (YUCK!):

      <(ssh remote cat ~/.fvwm/config)

      My point? Well, now we can put this together into a command that allows interactive transfer of parts of configs between machines.

      meld <(ssh remote cat ~/.fvwm/config) ~/.fvwm/config

      If you are curious where this “file” is, look into the man page (you don’t need to and probably don’t want to know!). I have classed this as intermediate, is that about right?

      NOTE according to this command, your “local” config is in the right hand pane – don’t bother making changes in the left hand side!

      • This topic was modified 5 months, 1 week ago by m4r35n357. Reason: trying to get note to show . .
      • This topic was modified 5 months, 1 week ago by m4r35n357.
      • This topic was modified 5 months, 1 week ago by m4r35n357. Reason: if this does not work I give up!
      #202206
      anticapitalista
      Forum Admin

        I prefer diffuse to meld.
        It is now gtk3 though

        Philosophers have interpreted the world in many ways; the point is to change it.

        antiX with runit - leaner and meaner.

        #202208
        m4r35n357
        Member

          xxdiff does not seem to like the “fake file” – at least it seems to work with “real” ones 😉

          I tried diffuse, it has a dependency on gir1.2-gtk-3.0, but the interface looks more gtk-2-ish, which is nice. I am going to evaluate this on antiX, but I see it is not part of Alpine (stable) ATM. Thanks for the recommendation.

          • This reply was modified 5 months, 1 week ago by m4r35n357. Reason: sp!
          #202232
          sybok
          Member

            The substitution is a nice way of getting the data.
            I’d probably go for a temporary file to store the remote configuration and compare it to the local using ‘vimdiff’.

            vimdiff -- local.conf <(shell substitution acquired conf)
            Surprisingly, no need to use ‘vimdiff -‘ to read from STDIN.

            Since ‘vimdiff’ is terminal-based, iteration over multiple configuration files can be easily scripted though it is practical only if the remote machine is accessed in a password-less way (such as SSH using keys) to avoid inputting password for each file.

            Learning can be fun!

            #202249
            Dave
            Forum Admin

              Interesting process. I have done this similarly using nfs mounts rather than per file over ssh. Generally if upgrading one machine to a new machine.

              For several machines… (or even one)
              Rsync against the fresh install to the old install or other machine to find the differing files in dry run and export the list of files (so you have a stored list of what will be packaged). Then run regularly and use the archive option to package them. With this package of all the different files you now have a base backup. Afterwards you can run rsync against the package and the fresh install in whatever machine with the run external command option. As the external command you can make a little script similar to the apt setup for replacing configs. In a loop question either skip the config, keep the new config, replace the config with the one from the package or check differences with diff (or diffuse, meld, etc) and reprompt.

              • This reply was modified 5 months, 1 week ago by Dave.

              Computers are like air conditioners. They work fine until you start opening Windows. ~Author Unknown

              #202257
              Captain Stall
              Member

                Hi @anticapitalista, if I may ask, what is about diffuse that you like it better than meld?

                #202258
                anticapitalista
                Forum Admin

                  Hi @anticapitalista, if I may ask, what is about diffuse that you like it better than meld?

                  Mostly because I find it a lot simpler to use.
                  Meld has too many options for me.

                  Philosophers have interpreted the world in many ways; the point is to change it.

                  antiX with runit - leaner and meaner.

                  #202261
                  anti-apXos
                  Member

                    It’s not GUI, but this what I have in my .bashrc for doing nice comparisons in a terminal:

                    diffy () { diff --width=150 --side-by-side --color=always --palette='ad=1;32:de=1,31' "$@" | sed 's/\(^.* |\t.*\)/\x1b[1;33m\1\x1b[0m/'; }

                    Then use it as:

                    diffy <(ssh remote cat ~/.fvwm/config) ~/.fvwm/config

                    It’s really just standard diff, but always in side-by-side” mode and with changed lines colored yellow in addition to added lines in green and deleted lines in red.

                    The width=150 part may need to be changed for other terminal setups.

                    "--"

                    #202263
                    Captain Stall
                    Member

                      Thanks @anticapitalista and thanks @anti-apXos for that nice enhancement to the standard diff command.

                      #202266
                      Brian Masinick
                      Moderator

                        It’s not GUI, but this what I have in my .bashrc for doing nice comparisons in a terminal:

                        diffy () { diff --width=150 --side-by-side --color=always --palette='ad=1;32:de=1,31' "$@" | sed 's/\(^.* |\t.*\)/\x1b[1;33m\1\x1b[0m/'; }

                        Then use it as:

                        diffy <(ssh remote cat ~/.fvwm/config) ~/.fvwm/config

                        It’s really just standard diff, but always in side-by-side” mode and with changed lines colored yellow in addition to added lines in green and deleted lines in red.

                        The width=150 part may need to be changed for other terminal setups.

                        Cool! That’s a nice command-based implementation of something that a fellow engineer put together with a graphical diff + his colorized modifications; I think that he called his modification mgdiff.

                        Brings back good memories; your approach is efficient and fast!

                        --
                        Brian Masinick
                        Alternate "Search B":
                        This search page

                        #202280
                        m4r35n357
                        Member

                          Nice to see a discussion around this 😉

                          When considering alternatives to my OP, remember that meld highlights “diff” sections for easy copying across (by clicking on an arrow), and also allows arbitrary copies (saving as you go if you want), and updates the diff as you go along (with overviews in the side bar). I am not sure that would be easy with some of the more “texty” approaches, but I am a fan of keyboard-driven processes, so I am still listening!

                          • This reply was modified 5 months, 1 week ago by m4r35n357. Reason: corrections
                          • This reply was modified 5 months, 1 week ago by m4r35n357. Reason: slight addition
                          #202291
                          Robin
                          Member

                            I am not sure that would be easy with some of the more “texty” approaches, but I am a fan of keyboard-driven processes

                            This precisely is why I have switched to meld, even when generally preferring the simplicity of purist text based approaches like anti-apXos’ method. In meld you can even do a folder comparison first, and then mark two of the highlighted files therein, open them in a new tab for detailed file comparison and merge, an once done go back to the first tab for continuing with the next highlighted file in the folders. This is some feature I won’t want to miss in complex merge operations. Meanwhile I have even set up git to use meld instead of diff for merging, which actually avoids the nasty code breaking git-merge-marker-insertations into files, instead the delta is simply highlighted.

                            Windows is like a submarine. Open a window and serious problems will start.

                          Viewing 12 posts - 1 through 12 (of 12 total)
                          • You must be logged in to reply to this topic.