Month: December 2018

  • Capture a Synology Package during installation

    This is an update of a previous post on this topic.

    I noticed that since a recent update of DSM, my previous script was not working fine anymore, when trying to capture a spk during installation. So here is an improved version.

    Click to Read More

    [code language=”bash”]

    #!/bin/bash
    VOLUME=$1
    TARGET=$2

    #Copy also the expanded package ?
    COPYEXPAND=false

    if [ -z "$VOLUME" ]; then
    echo "usage: capture <source VOLUME> <target dir>"
    exit 0
    fi

    if [ -z "$TARGET" ]; then
    echo "usage: capture <source VOLUME> <target dir>"
    exit 0
    fi

    pattern="volume[0-9]+"
    if [[ ! $VOLUME =~ $pattern ]]; then
    echo "The name of the source volume must be like ‘volume<i>’ where <i> is numeric"
    exit 0
    fi

    if [ ! -d "/$VOLUME/@tmp" ]; then
    echo "Temporary dir not found: /$VOLUME/@tmp"
    exit 0
    fi

    if [ -d "/$VOLUME/@tmp/SynoCapture" ]; then
    rm -R "/$VOLUME/@tmp/SynoCapture"
    fi

    if [ -d "/$VOLUME/@tmp/@synopkg" ]; then
    rm -R "/$VOLUME/@tmp/@synopkg"
    fi

    echo "Press any key to stop the capture"

    if [ -t 0 ]; then stty -echo -icanon -icrnl time 0 min 0; fi

    count=0
    keypress=”
    echo "Going to copy the packages into $TARGET/SynoCapture"

    if [ ! -d "$TARGET/SynoCapture" ]; then
    mkdir "$TARGET/SynoCapture"
    fi

    while [ "x$keypress" = "x" ]; do
    if [ -d "/$VOLUME/@tmp/@synopkg/@download/" ]; then
    cp -nlR "/$VOLUME/@tmp/@synopkg/@download/." "/$VOLUME/@tmp/SynoCapture/"
    fi

    if [ "$COPYEXPAND" = true ]; then
    if [ -d "/$VOLUME/@tmp/pkginstall/" ]; then
    cp -nlR "/$VOLUME/@tmp/pkginstall/." "/$VOLUME/@tmp/SynoCapture/pkginstall/"
    fi
    fi
    let count+=1
    echo -ne $count’\r’
    keypress="`cat -v`"
    done

    if [ -t 0 ]; then stty sane; fi

    find "/$VOLUME/@tmp/SynoCapture/" -type f -name ‘@SYNOPKG_DOWNLOAD_*’ -exec sh -c ‘x="{}"; mv "$x" "${x}.spk"’ \;
    if [ "$COPYEXPAND" = true ]; then
    if [ -d "$TARGET/SynoCapture/pkginstall" ]; then
    rm -R "$TARGET/SynoCapture/pkginstall"
    fi
    fi
    cp -fR "/$VOLUME/@tmp/SynoCapture" "$TARGET/"
    rm -R "/$VOLUME/@tmp/SynoCapture"

    echo "$count captures done"
    exit 0

    [/code]

    Now the script will copy only the SPK file into the specified target folder. It’s also possible to copy the expanded version by setting the variable COPYEXPAND=true

    Also, now, I don’t find anymore a folder name “pkglist.tmp” containing files synoserver.enu and otherserver.enu. Those files used to contain the URL’s of all SPK available respectively on the official Synology website and on the various SPK servers that you configured in your Package Center > Settings > Package Sources.

    To make the capture even easier, I have create a Package named “MODS Package Capture, available on my SPK Server and published on GitHub.

    Loading