install.sh fixes

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

install.sh fixes

jcalcote
Hi Yaguang,

Here's a patch for ubuntu14/install.sh:

diff --git a/ubuntu14/install.sh b/ubuntu14/install.sh
--- a/ubuntu14/install.sh
+++ b/ubuntu14/install.sh
@@ -239,8 +239,8 @@
     $SCP -r vsmrepo $USER@$1:/tmp
     $SSH $USER@$1 "$SUDO mv /tmp/vsmrepo /opt"
     $SSH $USER@$1 "if [[ -f /etc/apt/apt.conf ]]; then $SUDO mv /etc/apt/apt.conf /tmp; $SUDO chown $USER /tmp/apt.conf; \
-        $SUDO echo \"APT::Get::AllowUnauthenticated 1 ;\" >> /tmp/apt.conf; $SUDO chown root /tmp/apt.conf; $SUDO mv /tmp/apt.conf /etc/apt; \
-        else touch /tmp/apt.conf; echo \"APT::Get::AllowUnauthenticated 1 ;\" >> /tmp/apt.conf; \
+        $SUDO bash -c 'echo \"APT::Get::AllowUnauthenticated 1 ;\" >> /tmp/apt.conf'; $SUDO chown root /tmp/apt.conf; $SUDO mv /tmp/apt.conf /etc/apt; \
+        else $SUDO touch /tmp/apt.conf; $SUDO bash -c 'echo \"APT::Get::AllowUnauthenticated 1 ;\" >> /tmp/apt.conf'; \
         $SUDO mv /tmp/apt.conf /etc/apt; fi"
 #    $SCP apt.conf $USER@$1:/etc/apt
     $SCP vsm.list $USER@$1:/tmp
@@ -262,8 +262,8 @@
         $SUDO chown root /tmp/apt.conf
         $SUDO mv /tmp/apt.conf /etc/apt
     else
-        touch /tmp/apt.conf
-        echo "APT::Get::AllowUnauthenticated 1 ;" >> /tmp/apt.conf
+        $SUDO touch /tmp/apt.conf
+        $SUDO bash -c 'echo "APT::Get::AllowUnauthenticated 1 ;" >> /tmp/apt.conf'
         $SUDO mv /tmp/apt.conf /etc/apt
     fi
     $SUDO cp vsm.list /etc/apt/sources.list.d
@@ -318,7 +318,7 @@
         $SSH $USER@$CONTROLLER_ADDRESS "$SUDO preinstall controller"
         setup_remote_controller
         #$SSH $USER@$CONTROLLER_ADDRESS "ls /var/cache/apt/archives/*.deb"
-        if [ `$SSH $USER@$CONTROLLER_ADDRESS "ls /var/cache/apt/archives/*.deb | wc -l"` -lt 1 ]; then
+        if [ `$SSH $USER@$CONTROLLER_ADDRESS "ls /var/cache/apt/archives/*.deb | wc -l"` -gt 1 ]; then
             $SCP $USER@$CONTROLLER_ADDRESS:/var/cache/apt/archives/*.deb $REPO_PATH/vsm-dep-repo
         fi
         cd $REPO_PATH

There are actually two fixes in here - the first two hunks represent fixes for one issue, and the last hunk is a fix for another issue entirely.

The first issue is one where files with well-known names get created in the /tmp directory during one installation, and then later, during another installation with a different username, these files cannot be overwritten by the current installation.

The second issue is a simple logic reversal that is not exposed unless you're installing with intent to import an existing cluster.
John
Reply | Threaded
Open this post in threaded view
|

Re: install.sh fixes

jcalcote
As I thought about this later in the evening, I realized that it's probably not the case that our QA team used different users to install subsequent deployments of VSM. It's much more likely that they installed under the 'A' account as the user 'B' on one system and then, later during a subsequent installation, reused one of the previous agent nodes as the new controller/admin node. The controller/admin node creates the local copy of /tmp/apt.conf as user 'A', while remote nodes' copies of this file get created via an ssh command as user 'B'. Thus, the 'B'-owned copy of the file is already sitting on the new controller/admin node (which was a remote agent in the previous installation) when the next installation starts and the local 'A' user attempts to overwrite the file.

It also occurred to me that there are better ways to fix this issue:

* before attempting to write to the file:
$SUDO rm /tmp/apt.conf
* create the file using mktemp:
APTFILE=$(mktemp -t apt.conf.XXXXX)
echo stuff >> $APTFILE
* better still, create a temporary directory and put all the usual files in that directory:
WORKDIR=$(mktemp -dt vsm.XXXXX)
touch /tmp/$WORKDIR/apt.conf
echo stuff >> /tmp/$WORKDIR/apt.conf
Reply | Threaded
Open this post in threaded view
|

Re: install.sh fixes

jcalcote
Here's a better patch for install.sh:

01-ubuntu14-install-sh.patch

Content:
diff --git a/ubuntu14/install.sh b/ubuntu14/install.sh
--- a/ubuntu14/install.sh
+++ b/ubuntu14/install.sh
@@ -232,16 +232,20 @@
 }

 function set_remote_repo() {
-    $SSH $USER@$1 "$SUDO rm -rf /etc/apt/sources.list.d/vsm.list /etc/apt/sources.list.d/vsm-dep.list; \
-        $SUDO rm -rf /opt/vsm-dep-repo /opt/vsmrepo"
+    $SSH $USER@$1 "bash -x -s" <<EOF
+$SUDO rm -rf /etc/apt/sources.list.d/vsm.list /etc/apt/sources.list.d/vsm-dep.list
+$SUDO rm -rf /opt/vsm-dep-repo /opt/vsmrepo
+EOF
     $SCP -r $REPO_PATH/vsm-dep-repo $USER@$1:/tmp
     $SSH $USER@$1 "$SUDO mv /tmp/vsm-dep-repo /opt"
     $SCP -r vsmrepo $USER@$1:/tmp
     $SSH $USER@$1 "$SUDO mv /tmp/vsmrepo /opt"
-    $SSH $USER@$1 "if [[ -f /etc/apt/apt.conf ]]; then $SUDO mv /etc/apt/apt.conf /tmp; $SUDO chown $USER /tmp/apt.conf; \
-        $SUDO echo \"APT::Get::AllowUnauthenticated 1 ;\" >> /tmp/apt.conf; $SUDO chown root /tmp/apt.conf; $SUDO mv /tmp/apt.conf /etc/apt; \
-        else touch /tmp/apt.conf; echo \"APT::Get::AllowUnauthenticated 1 ;\" >> /tmp/apt.conf; \
-        $SUDO mv /tmp/apt.conf /etc/apt; fi"
+    $SSH $USER@$1 "bash -x -s" <<EOF
+$SUDO rm /tmp/apt.conf
+test -f /etc/apt/apt.conf && $SUDO mv /etc/apt/apt.conf /tmp
+echo "APT::Get::AllowUnauthenticated 1 ;" | $SUDO tee --append /tmp/apt.conf >/dev/null
+$SUDO mv /tmp/apt.conf /etc/apt
+EOF
 #    $SCP apt.conf $USER@$1:/etc/apt
     $SCP vsm.list $USER@$1:/tmp
     $SSH $USER@$1 "$SUDO mv /tmp/vsm.list /etc/apt/sources.list.d"
@@ -255,17 +259,10 @@
     $SUDO rm -rf /opt/vsm-dep-repo /opt/vsmrepo
     $SUDO cp -r $REPO_PATH/vsm-dep-repo /opt
     $SUDO cp -r vsmrepo /opt
-    if [[ -f /etc/apt/apt.conf ]]; then
-        $SUDO mv /etc/apt/apt.conf /tmp
-        $SUDO chown $USER /tmp/apt.conf
-        $SUDO echo "APT::Get::AllowUnauthenticated 1 ;" >> /tmp/apt.conf
-        $SUDO chown root /tmp/apt.conf
-        $SUDO mv /tmp/apt.conf /etc/apt
-    else
-        touch /tmp/apt.conf
-        echo "APT::Get::AllowUnauthenticated 1 ;" >> /tmp/apt.conf
-        $SUDO mv /tmp/apt.conf /etc/apt
-    fi
+    $SUDO rm /tmp/apt.conf
+    test -f /etc/apt/apt.conf && $SUDO mv /etc/apt/apt.conf /tmp
+    echo "APT::Get::AllowUnauthenticated 1 ;" | $SUDO tee --append /tmp/apt.conf >/dev/null
+    $SUDO mv /tmp/apt.conf /etc/apt
     $SUDO cp vsm.list /etc/apt/sources.list.d
     $SUDO cp vsm-dep.list /etc/apt/sources.list.d
     $SUDO apt-get update
@@ -318,7 +315,7 @@
         $SSH $USER@$CONTROLLER_ADDRESS "$SUDO preinstall controller"
         setup_remote_controller
         #$SSH $USER@$CONTROLLER_ADDRESS "ls /var/cache/apt/archives/*.deb"
-        if [ `$SSH $USER@$CONTROLLER_ADDRESS "ls /var/cache/apt/archives/*.deb | wc -l"` -lt 1 ]; then
+        if [ `$SSH $USER@$CONTROLLER_ADDRESS "ls /var/cache/apt/archives/*.deb | wc -l"` -gt 1 ]; then
             $SCP $USER@$CONTROLLER_ADDRESS:/var/cache/apt/archives/*.deb $REPO_PATH/vsm-dep-repo
         fi
         cd $REPO_PATH
Reply | Threaded
Open this post in threaded view
|

Re: install.sh fixes

jcalcote
I spent some time this weekend polishing my github foo - I created a pull request for these changes. I hope to be able to continue this trend for our patches in the future.

John