virtualhere.sh 1.71 KB
Newer Older
1 2 3 4 5 6
#!/bin/sh

PKGNAME=virtualhere
PRODUCTDIR=/opt/$PKGNAME
BINNAME=vhusbd
SUPPORTEDARCHES="x86_64 armhf mips mipsel aarch64 x86"
7
VERSION="$2"
8 9 10 11
DESCRIPTION='Generic VirtualHere USB Server from the official site'

. $(dirname $0)/common.sh

12
arch="$(epm print info -a)"
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
case "$arch" in
    x86_64)
        file="vhusbdx86_64"
        ;;
    x86)
        file="vhusbdi386"
        ;;
    armhf)
        file="vhusbdarm"
        ;;
    mips)
        file="vhusbdmips"
        ;;
    mipsel)
        file="vhusbdmipsel"
        ;;
    aarch64)
        file="vhusbdarm64"
        ;;
    *)
        fatal "$arch arch is not supported"
        ;;
esac

37
pkgtype="$(epm print info -p)"
38 39

tdir=$(mktemp -d)
40
trap "rm -fr $tdir" EXIT
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
mkdir -p $tdir/opt/$PKGNAME/
cd $tdir || fatal

# https://github.com/virtualhere/script/blob/main/install_server
epm tool eget -O opt/$PKGNAME/$BINNAME https://www.virtualhere.com/sites/default/files/usbserver/$file || fatal
chmod 0755 opt/$PKGNAME/$BINNAME

pack_tar() {
    local tarname="$1"
    local file="$2"
    local destfile="$3"
    [ -n "$destfile" ] || destfile="$PRODUCTDIR/$(basename $file)"
    local dest=$(dirname $destfile)
    mkdir -p .$dest
    [ -s .$dest/$(basename $file) ] || cp -v $file .$dest/
    a='' tar cf $tarname .$(dirname $dest)
}

59 60 61 62 63 64 65
# FIXME
VERSION="*"
if [ "$VERSION" = "*" ] ; then
    VERSION="$(epm tool eget -O- https://virtualhere.com/usb_server_software | grep "<b>Version [0-9.]*</b>" | sed -e 's|.*<b>Version \([0-9.]*\)</b>.*|\1|')"
    [ -n "$VERSION" ] || fatal "Can't get version for $PKGNAME"
fi

66 67 68
PKG=$PKGNAME-$VERSION.tar
pack_tar $PKG opt/$PKGNAME/$BINNAME

69
epm install --repack "$PKG" || exit
70 71 72 73 74 75

echo
echo "Note: run
# serv $PKGNAME on
to enable and start $PKGNAME system service
"