Commits

Aleš Erjavec  committed 1c41c72

Refactored scripts for publishing/rotating builds.

  • Participants
  • Parent commits 586603f

Comments (0)

Files changed (3)

File install-scripts/mac/build-publish.sh

+#!/bin/bash -e
+
+function print_usage() {
+    echo 'build-publish.sh [--remote [user@]host[:dir]] --key KEY -d DIST_DIR FILE
+
+Publish a build FILE in DIST_DIR under KEY
+
+NOTE: KEY  needs to match [A-Z_]+
+NOTE: If --remote is specified then a sshfs executable must be on $PATH
+
+Options:
+    --remote (-r) REMOTE  A "sshfs host" string. If present then the remote
+                          will be mounted under DIST_DIR.
+    --key (-k)            Key under which to publish the file.
+    --dist-dir (-d)       Directory where to publish.
+'
+}
+
+# section "Section title" "delimiter"
+# Note: Can't use "-" as the delimiter
+function section() {
+    line="$1"
+    delim="$2"
+    echo "$line"
+    len=${#line}
+    printf "${delim}%.0s" $(eval "echo {1.."$len"}")
+    echo
+
+}
+
+while [ ${1:0:1} = "-" ];  do
+    case $1 in
+        --key)
+            KEY=$2
+            shift 2
+            ;;
+        -r|--remote)
+            REMOTE=$2
+            shift 2
+            ;;
+        -d|--dist-dir)
+            DIST_DIR=$2
+            shift 2
+            ;;
+        *)
+            echo "Unknown option $1"
+            print_usage
+            exit 1
+    esac
+done
+
+if [[ ! $KEY ]]; then
+    echo "--key must be supplied"
+    exit 1
+fi
+
+if [[ ! $KEY =~ ^[A-Z_]+$ ]]; then
+    echo "Invalid key $KEY"
+    exit 1
+fi
+
+FILE="$1"
+
+if [ ! -e "$FILE" ]; then
+    echo "$FILE does not exist"
+    exit 1
+fi
+
+UNMOUNT=
+
+if [[ $REMOTE ]]; then
+    if { ! mount | grep "$DIST_DIR" > /dev/null; } then
+        echo "Mounting sshfs $REMOTE at $DIST_DIR"
+        mkdir -p "$DIST_DIR"
+        sshfs -o reconnect,uid=$(id -u),gid=$(id -g) \
+            -o workaround=nonodelay:rename \
+            "$REMOTE" \
+            "$DIST_DIR"
+        sleep 5
+        UNMOUNT=1
+    fi
+fi
+
+if [ ! -d "$DIST_DIR" ]; then
+    echo "$DIST_DIR does not exist or is not a directory"
+    exit 1
+fi
+
+FILE_NAME=$(basename "$FILE")
+
+MD5=$(md5 -q "$FILE")
+
+section "Moving $FILE into place" "="
+
+cp "$FILE" "$DIST_DIR"/"$FILE_NAME".new
+
+# Check integrity (buggy sshfs??)
+
+MD5_D=$(md5 -q "$DIST_DIR/$FILE_NAME.new")
+if [[ $MD5 != $MD5_D ]]; then
+    echo "Error moving $FILE_NAME in place ($MD5 != $MD5_D)!"
+    rm "$DIST_DIR"/"$FILE_NAME".new
+    exit 1
+else
+    mv "$DIST_DIR"/"$FILE_NAME".new "$DIST_DIR"/"$FILE_NAME"
+fi
+
+
+section "Registering $KEY=$FILE_NAME with MD5=$MD5" "="
+
+if [[ ! -e "$DIST_DIR"/filenames_mac.set ]]; then
+    touch "$DIST_DIR"/filenames_mac.set
+fi
+
+egrep -v "^($KEY)=" "$DIST_DIR"/filenames_mac.set > "$DIST_DIR"/filenames_mac.set.new || true
+
+
+echo "$KEY=$FILE_NAME" >> "$DIST_DIR"/filenames_mac.set.new
+echo "$KEY=$FILE_NAME"
+
+mv "$DIST_DIR"/filenames_mac.set.new "$DIST_DIR"/filenames_mac.set
+
+sync
+
+if [[ $UNMOUNT ]]; then
+    diskutil unmount "$DIST_DIR"
+fi

File install-scripts/mac/build-rotate.sh

+#!/bin/bash -e
+
+function print_usage() {
+    echo 'build-rotate.sh --match "PATTERN" [--remote [user@]host[:dir]] [--keep N] DIST_DIR
+
+Delete old files matching the glob "PATTERN", in DIST_DIR keping only N
+latest files.
+
+NOTE: Always enclose PATTERN in quotes to prevent shell expansion at
+      the call site.
+
+NOTE: If --remote is specified then a sshfs executable must be on $PATH
+
+Options:
+    --match (-m) PATTERN    Glob pattern to match files in DIST_DIR
+    --remote (-r) REMOTE    Remote sftp address. If supplied the remote
+                            location will be mounted on DIST_DIR using sshfs
+                            for the duration of the command.
+    --keep (-k) N           Number of matching files to keep (default 10).
+
+'
+}
+
+KEEP=10
+
+while [[ ${1:0:1} = "-" ]]; do
+    case $1 in
+        -m|--match)
+            MATCH="$2"
+            shift 2
+            ;;
+        -k|--keep)
+            KEEP="$2"
+            shift 2
+            ;;
+        -r|--remote)
+            REMOTE="$2"
+            shift 2
+            ;;
+        -d|--dry-run)
+            DRY_RUN=1
+            shift 1
+            ;;
+        -h|--help)
+            print_usage
+            exit 0
+            ;;
+        *)
+            echo "Unknown option $1"
+            print_usage
+            exit 1
+            ;;
+    esac
+done
+
+
+DIST_DIR="$1"
+
+if [[ ! $KEEP =~ ^[0-9]+$ ]]; then
+    echo "Invalid --keep parameter $KEEP"
+    exit 1
+fi
+
+if [[ ! $MATCH ]]; then
+    echo "Invalid match parameter"
+    print_usage
+    exit 1
+fi
+
+UNMOUNT=
+
+if [[ $REMOTE ]]; then
+    if { ! mount | grep "$DIST_DIR" > /dev/null; } then
+        echo "Mounting sshfs $REMOTE at $DIST_DIR"
+        mkdir -p "$DIST_DIR"
+        sshfs -o reconnect,uid=$(id -u),gid=$(id -g) \
+            -o workaround=nonodelay:rename \
+            "$REMOTE" \
+            "$DIST_DIR"
+        sleep 5
+        UNMOUNT=1
+    fi
+fi
+
+if [[ ! -d "$DIST_DIR" ]]; then
+    echo "$DIST_DIR does not exist or is not a directory"
+    exit 1
+fi
+
+FILES=( $(ls -t -1 "$DIST_DIR"/$MATCH 2> /dev/null || true) )
+
+NFILES=${#FILES[*]}
+
+echo "$NFILES files matching the pattern."
+echo
+echo "Removing old files"
+echo "------------------"
+
+for (( i=$KEEP; i < $NFILES; i++ )) do
+    echo "removing ${FILES[$i]}"
+    if [[ ! $DRY_RUN ]]; then
+        rm "${FILES[$i]}"
+    fi
+done
+
+sync
+
+if [[ $UNMOUNT ]]; then
+    diskutil unmount "$DIST_DIR"
+fi

File install-scripts/mac/daily-build.sh

 
 ./install-scripts/mac/create-dmg-installer.sh --app dist/Orange.app dist/$DMG_NAME
 
+
 echo "Removing old versions"
 # Note: project name is prepended to the pattern so the dmg image must
 # be named Orange-*.dmg
 python setup.py rotate --keep=10 --dist-dir="$PUBLISH_DIR" --match=".dmg"
 
-MD5=$(md5 -q "dist/$DMG_NAME")
-
-echo "Moving dmg installer into place"
-echo "==============================="
-mv dist/$DMG_NAME "$PUBLISH_DIR"/$DMG_NAME.new
-
-# Check integrity (buggy sshfs??)
-
-MD5_D=$(md5 -q "$PUBLISH_DIR/$DMG_NAME.new")
-if [[ $MD5 != $MD5_D ]]; then
-    echo "Error moving the bundle in place"
-    rm "$PUBLISH_DIR"/$DMG_NAME.new
-    exit 1
-else
-    mv "$PUBLISH_DIR"/$DMG_NAME.new "$PUBLISH_DIR"/$DMG_NAME
-fi
-
-
-echo "Registering new dmg installer"
-echo "============================="
-
-if [[ ! -e "$PUBLISH_DIR"/filenames_mac.set ]]; then
-    touch "$PUBLISH_DIR"/filenames_mac.set
-fi
-
-egrep -v '^(MAC_DAILY)=' "$PUBLISH_DIR"/filenames_mac.set > "$PUBLISH_DIR"/filenames_mac.set.new || true
-
-
-echo "MAC_DAILY=$DMG_NAME" >> "$PUBLISH_DIR"/filenames_mac.set.new
-echo "MAC_DAILY=$DMG_NAME"
-
-mv "$PUBLISH_DIR"/filenames_mac.set.new "$PUBLISH_DIR"/filenames_mac.set
+./install-scripts/mac/build-publish.sh \
+    --dist-dir "$PUBLISH_DIR" \
+    --key MAC_DAILY \
+    "dist/$DMG_NAME"
 
 if [[ $BOOTSTRAP ]]; then
     rm -rf $WORK_DIR