Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: Using rsync to share home directories. (plus some other things)

  1. #11
    Join Date
    Nov 2007
    Beans
    12

    Re: Using rsync to share home directories. (plus some other things)

    Ok so ssh sudoing is not the bast thing, so lets revise that a bit. Also running apt-get install 900 times when you already have those packages is a bit of a pain as well.

    Lets start with a new $HOME/coteyr_sync_packages
    Code:
    #!/bin/bash
    REMOTE='upstairs'
    aptitude search '?installed ?not(?automatic)' -F '%p' > local.packages
    ssh $REMOTE "aptitude search '?installed ?not(?automatic)' -F '%p'" > remote.packages
    rm inst.packages
    for lp in `cat local.packages`; do
      noproc="false"
      for rp in `cat remote.packages`; do
        if [ "$lp" == "$rp" ]; then
          noproc="true"
        fi
      done
      if [ "$noproc" != "true" ]; then
        echo "$lp" >> inst.packages
      fi
    done
    scp inst.packages $REMOTE:/tmp/install.packages
    rm inst.packages
    for lp in `cat remote.packages`; do
      noproc="false"
      for rp in `cat local.packages`; do
        if [ "$lp" == "$rp" ]; then
          noproc="true"
        fi
      done
      if [ "$noproc" != "true" ]; then
        echo "$lp" >> inst.packages
      fi
    done
    mv inst.packages /tmp/install.packages
    Now that puts the package that need to be installed on the remote machine. We can let the remote machine decide what to do with them. This also gives us the packages to install on our local machine to make it match the remote machine. I would like to find a grep statement or something that would for to rid us of those ugly for loops, but alas, this does work. The actually installing of the packages we will like for later. This now just gets us the list.

    In the future we will need to secure this list a lot better. Our intent is to list in package in /tmp/install.packages, but thats not very smart as anyone can write to it. We will need to make the package installer run as root, and make the install.packages file exist in a more secure location.

    When we start combining this into a actual script instead of just tests and chunks of code we will want to be able to turn off some features, and turn others on. Not to mention full configuration of paths and such.

  2. #12
    Join Date
    Nov 2007
    Beans
    12

    Re: Using rsync to share home directories. (plus some other things)

    OK let continue with the package installer.

    So we have a list of packages that need to be installed on a machine. Were going to read though the list and install the packages one at a time. But we also need to ignore some packages. For example we want to not install the Nvidia packages on a machine with an ATI card. Also some wireless drivers and some other kernel things. Plus you may just have some packages you don't want shared. Lets go ahead and create a file with a list of packages to be ignored.

    Create the file $HOME/.coteyr_sync/ignore.packages
    Code:
    bcmwl-kernel-source
    fglrx-modaliases
    You will almost certainly want this list to be larger. Also note that we created a directory to hold the file. We don't want are home directory getting all cluttered and we also want these to be specific to a machine (and not synced).

    Now lets go ahead and write the package installer.

    so create $HOME/coteyr_sync_package_installer
    Code:
    #!/bin/bash
    apt-get update
    for package in `cat /tmp/install.packages`; do
      noproc="false"
      for ignore in `cat $HOME/.coteyr_sync/ignore.packages`; do
        if [ "$package" == "$ignore" ]; then
          noproc="true"
        fi
      done
      if [ "$noproc" != "true" ]; then
        DEBIAN_FRONTEND=noninteractive sudo apt-get -y install $package
      fi
    done
    Notice this time we did not call sudo in our script. So the script has to be run with sudo (or root permissions). Go ahead and run it and it will install all the packages that are on your remote machine to your local machine.

    Up till this point we have been having One system act at the "starter" of the sync. But when we want to sync more then one computer it will be a good idea to be able to start the connection from either side. Unfortunately, the scripts and what not are now synced over so making a change on the remote machine modifies settings on the local machine. This is what we want over all but we need different values for our variables on each machine. To accomplish that we will need to edit our scripts again. This is a good time to make them a bit more generic and to combine them. It's also a good time to refactor them a bit and DRY them up a bit.

Page 2 of 2 FirstFirst 12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •