1. added multipath protocol and schema suport

2. added SCTP protocol and schema support
3. added set of NAS models support (Asustor, ReadyNAS, Drobo, QNAP, WD, Synology, Terramaster)
4. moved to fc00::/7 private segment
5. added Windows, MacOS and Linux UI for peers edit and current status
This commit is contained in:
vadym 2022-10-27 22:03:37 +03:00
parent cfa293d189
commit d8a4000141
198 changed files with 8589 additions and 697 deletions

108
contrib/nas/nas-asustor.sh Normal file
View file

@ -0,0 +1,108 @@
#!/bin/sh
# This is a lazy script to create a .bin for WD NAS build.
# You can give it the PKGARCH= argument
# i.e. PKGARCH=x86_64 contrib/nas/nas-asustor.sh
if [ `pwd` != `git rev-parse --show-toplevel` ]
then
echo "You should run this script from the top-level directory of the git repo"
exit 1
fi
PKGBRANCH=$(basename `git name-rev --name-only HEAD`)
PKG=$(sh contrib/semver/name.sh)
PKGVERSION=$(sh contrib/semver/version.sh --bare)
PKGARCH=${PKGARCH-amd64}
PKGFOLDER=$ENV_TAG-$PKGARCH-$PKGVERSION
PKGFILE=mesh-$PKGFOLDER.apk
PKGREPLACES=mesh
if [ $PKGBRANCH = "master" ]; then
PKGREPLACES=mesh-develop
fi
if [ $PKGARCH = "x86-64" ]; then GOOS=linux GOARCH=amd64 ./build
elif [ $PKGARCH = "armv7" ]; then GOOS=linux GOARCH=arm GOARM=7 ./build
else
echo "Specify PKGARCH=x86-64 or armv7"
exit 1
fi
echo "Building $PKGFOLDER"
rm -rf /tmp/$PKGFOLDER
mkdir -p /tmp/$PKGFOLDER/bin
mkdir -p /tmp/$PKGFOLDER/var/log
chmod 0775 /tmp/$PKGFOLDER/ -R
echo "coping ui package..."
cp contrib/ui/nas-asustor/* /tmp/$PKGFOLDER/ -r
cp contrib/ui/www/* /tmp/$PKGFOLDER/www/ -r
echo "Converting icon for: 90x90"
convert -colorspace sRGB ./riv.png -resize 90x90 PNG32:/tmp/$PKGFOLDER/CONTROL/icon.png
chmod 644 /tmp/$PKGFOLDER/CONTROL/icon.png
cat > /tmp/$PKGFOLDER/CONTROL/config.json << EOF
{
"general": {
"package": "mesh-$ENV_TAG",
"name": "RiV Mesh",
"version": "$PKGVERSION",
"depends": [],
"conflicts": [],
"developer": "Riv Chain ltd",
"maintainer": "Riv Chain ltd",
"email": "vadym.vikulin@rivchain.org",
"website": "https://github.com/RiV-chain/RiV-mesh",
"architecture": "$PKGARCH",
"firmware": "2.4.0"
},
"adm-desktop": {
"app": {
"type":"custom",
"protocol":"http",
"port": 19019,
"url": "/"
},
"privilege": {
"accessible": "administrators",
"customizable": true
}
},
"register": {
"share-folder": [
],
"prerequisites": {
"enable-service": [],
"restart-service": []
},
"boot-priority": {
"start-order": 95,
"stop-order": 5
},
"port": []
}
}
EOF
cat > /tmp/$PKGFOLDER/CHANGELOG.md << EOF
See https://github.com/RiV-chain/RiV-mesh
EOF
cat > /tmp/$PKGFOLDER/CONTROL/changelog.txt << EOF
See https://github.com/RiV-chain/RiV-mesh
EOF
cp mesh /tmp/$PKGFOLDER/bin
cp meshctl /tmp/$PKGFOLDER/bin
cp LICENSE /tmp/$PKGFOLDER/CONTROL/license.txt
chmod +x /tmp/$PKGFOLDER/bin/*
chmod 0775 /tmp/$PKGFOLDER/www -R
fakeroot python2 ./contrib/nas/tool/asustor_apkg_tools.py create /tmp/$PKGFOLDER
rm -rf /tmp/$PKGFOLDER/
#mv *.apk $PKGFILE

90
contrib/nas/nas-drobo.sh Normal file
View file

@ -0,0 +1,90 @@
#!/bin/sh
# This is a lazy script to create a .bin for WD NAS build.
# You can give it the PKGARCH= argument
# i.e. PKGARCH=x86_64 contrib/nas/nas-asustor.sh
if [ `pwd` != `git rev-parse --show-toplevel` ]
then
echo "You should run this script from the top-level directory of the git repo"
exit 1
fi
PKGBRANCH=$(basename `git name-rev --name-only HEAD`)
PKG=$(sh contrib/semver/name.sh)
PKGVERSION=$(sh contrib/semver/version.sh --bare)
PKGARCH=${PKGARCH-amd64}
PKGNAME=$ENV_TAG-$PKGARCH-$PKGVERSION
PKGFOLDER=$PKGNAME/mesh
PKGFILE=mesh-$PKGNAME.tar.gz
PKGREPLACES=mesh
if [ $PKGBRANCH = "master" ]; then
PKGREPLACES=mesh-develop
fi
if [ $PKGARCH = "armv7" ]; then GOOS=linux GOARCH=arm GOARM=7 ./build
else
echo "Specify PKGARCH=armv7"
exit 1
fi
echo "Building $PKGFOLDER"
rm -rf /tmp/$PKGFOLDER
mkdir -p /tmp/$PKGFOLDER/bin
mkdir -p /tmp/$PKGFOLDER/config
mkdir -p /tmp/$PKGFOLDER/var/log
mkdir -p /tmp/$PKGFOLDER/lib/modules
if [ $ENV_TAG = "nas-drobo-5n" ]; then
for kernel in 3.2.96-3 3.2.58-2 3.2.58-1 3.2.58 3.2.27; do
echo "Loading tun module for Linux kernel $kernel"
wget -N ftp://updates.drobo.com/droboapps/kernelmodules/5N/3.2.96-3/tun.ko -P /tmp/$PKGFOLDER/lib/modules/$kernel
done
elif [ $ENV_TAG = "nas-drobo-5n2" ]; then
for kernel in 3.2.96-3 3.2.58-2; do
echo "Loading tun module for Linux kernel $kernel"
wget -N ftp://updates.drobo.com/droboapps/kernelmodules/5N2/3.2.96-3/tun.ko -P /tmp/$PKGFOLDER/lib/modules/$kernel
done
elif [ $ENV_TAG = "nas-drobo-b810n" ]; then
for kernel in 3.2.96-3 3.2.58-2 3.2.58-1 3.2.58; do
echo "Loading tun module for Linux kernel $kernel"
wget -N ftp://updates.drobo.com/droboapps/kernelmodules/B810n/3.2.96-3/tun.ko -P /tmp/$PKGFOLDER/lib/modules/$kernel
done
else
echo "Specify ENV_TAG=nas-drobo-5n or nas-drobo-5n2 or nas-drobo-b810n"
exit 1
fi
mkdir -p /tmp/$PKGFOLDER/tmp
chmod 0775 /tmp/$PKGFOLDER/ -R
echo "coping ui package..."
cp contrib/ui/nas-drobo/Content/* /tmp/$PKGFOLDER/ -r
cp contrib/ui/www/* /tmp/$PKGFOLDER/www/ -r
cat > /tmp/$PKGFOLDER/version.txt << EOF
$PKGVERSION
EOF
cp mesh /tmp/$PKGFOLDER/bin
cp meshctl /tmp/$PKGFOLDER/bin
cp LICENSE /tmp/$PKGFOLDER/
chmod +x /tmp/$PKGFOLDER/*.sh
chmod +x /tmp/$PKGFOLDER/bin/*
chmod 0775 /tmp/$PKGFOLDER/www -R
current_dir=$(pwd)
cd /tmp/$PKGFOLDER && tar czf ../mesh.tgz $(ls .)
cd ../ && md5sum mesh.tgz > mesh.tgz.md5
tar czf $PKGFILE mesh.tgz mesh.tgz.md5
mv $PKGFILE "$current_dir"
cd "$current_dir"
rm -rf /tmp/$PKGNAME/

View file

@ -0,0 +1,108 @@
#!/bin/sh
# This is a lazy script to create a .deb for Debian/Ubuntu. It installs
# mesh and enables it in systemd. You can give it the PKGARCH= argument
# i.e. PKGARCH=i386 sh contrib/deb/generate.sh
if [ $(pwd) != $(git rev-parse --show-toplevel) ]
then
echo "You should run this script from the top-level directory of the git repo"
exit 1
fi
PKGBRANCH=$(basename `git name-rev --name-only HEAD`)
PKG=$(sh contrib/semver/name.sh)
PKGVERSION=$(sh contrib/semver/version.sh --bare)
PKGARCH=${PKGARCH-amd64}
PKGNAME=$ENV_TAG-$PKGVERSION
PKGFILE=$PKGNAME.deb
PKGREPLACES=mesh
if [ $PKGBRANCH = "master" ]; then
PKGREPLACES=mesh-develop
fi
if [ $PKGARCH = "amd64" ]; then GOARCH=amd64 GOOS=linux ./build
elif [ $PKGARCH = "armel" ]; then GOARCH=arm GOARM=5 GOOS=linux ./build
else
echo "Specify PKGARCH=amd64,armel"
exit 1
fi
echo "Building $PKGFILE"
mkdir -p /tmp/$PKGNAME/usr/bin
mkdir -p /tmp/$PKGNAME/debian/
mkdir -p /tmp/$PKGNAME/DEBIAN/
mkdir -p /tmp/$PKGNAME/apps/mesh/bin
mkdir -p /tmp/$PKGNAME/apps/mesh/www
mkdir -p /tmp/$PKGNAME/apps/mesh/var/log
mkdir -p /tmp/$PKGNAME/apps/mesh/var/lib/mesh/hooks
mkdir -p /tmp/$PKGNAME/usr/share/doc/mesh
chmod 0775 /tmp/$PKGNAME/ -R
for resolution in 150x150; do
echo "Converting icon for: $resolution"
convert -colorspace sRGB ./riv.png -resize $resolution PNG32:/tmp/$PKGNAME/apps/mesh/logo.png && \
chmod 644 /tmp/$PKGNAME/apps/mesh/logo.png
done
cat > /tmp/$PKGNAME/apps/mesh/config.xml << EOF
<Application resource-id="mesh"><!-- 'resource-id' must be AppName -->
<Name>RiV Mesh</Name><!-- Any desciptive name, upto 48 chars -->
<Author>Riv Chain Ltd</Author><!-- Authors name. upto 48 chars -->
<Version>$PKGVERSION</Version><!-- Version -->
<RequireReboot>0</RequireReboot><!-- If non-zero, it indicates reboot is required. -->
<ConfigURL></ConfigURL><!-- 'localhost' will be replaced by framework JS. -->
<LaunchURL>https://localhost/apps/mesh/</LaunchURL><!-- 'localhost' will be replaced by framework JS. -->
<ReservePort>19019</ReservePort>
<DebianPackage>mesh</DebianPackage>
<ServiceName>fvapp-mesh.service</ServiceName><!-- If start/stop need to start/stop service, specify service name -->
<Description lang="en-us">RiV-mesh is an implementation of a fully end-to-end encrypted IPv6 network.</Description>
</Application>
EOF
echo "coping ui package..."
cp contrib/ui/nas-netgear-os6/package/apps /tmp/$PKGNAME/ -r
cp contrib/ui/www/* /tmp/$PKGNAME/apps/mesh/www/ -r
cat > /tmp/$PKGNAME/debian/changelog << EOF
Please see https://github.com/RiV-chain/RiV-mesh/
EOF
echo 9 > /tmp/$PKGNAME/debian/compat
cat > /tmp/$PKGNAME/DEBIAN/control << EOF
Package: mesh
Version: $PKGVERSION
Section: contrib/net
Priority: extra
Architecture: $PKGARCH
Replaces: $PKGREPLACES
Conflicts: $PKGREPLACES
Maintainer: Vadym Vikulin <vadym.vikulin@rivchain.org>
Description: RiV-mesh is an implementation of a fully end-to-end encrypted IPv6 network.
It is lightweight, self-arranging, supported on multiple platforms and
allows pretty much any IPv6-capable application to communicate securely with
other RiV-mesh nodes.
EOF
cat > /tmp/$PKGNAME/debian/copyright << EOF
Please see https://github.com/RiV-chain/RiV-mesh/
EOF
cat > /tmp/$PKGNAME/debian/docs << EOF
Please see https://github.com/RiV-chain/RiV-mesh/
EOF
cp mesh /tmp/$PKGNAME/apps/mesh/bin
cp meshctl /tmp/$PKGNAME/apps/mesh/bin
ln -s /apps/mesh/bin/meshctl /tmp/$PKGNAME/usr/bin/meshctl
ln -s /apps/mesh/var/log/mesh.log /tmp/$PKGNAME/apps/mesh/www/log
chmod 0775 /tmp/$PKGNAME/DEBIAN/*
chmod 755 /tmp/$PKGNAME/apps/mesh/bin/*
dpkg-deb -Zxz --build --root-owner-group /tmp/$PKGNAME
cp /tmp/$PKGFILE .
rm -rf /tmp/$PKGNAME

84
contrib/nas/nas-qnap.sh Normal file
View file

@ -0,0 +1,84 @@
#!/bin/sh
# This is a lazy script to create a .bin for WD NAS build.
# You can give it the PKGARCH= argument
# i.e. PKGARCH=x86_64 contrib/nas/nas-asustor.sh
if [ `pwd` != `git rev-parse --show-toplevel` ]
then
echo "You should run this script from the top-level directory of the git repo"
exit 1
fi
PKGBRANCH=$(basename `git name-rev --name-only HEAD`)
PKG=$(sh contrib/semmsiver/name.sh)
PKGVERSION=$(sh contrib/msi/msversion.sh --bare)
PKGARCH=${PKGARCH-amd64}
PKGFOLDER=$ENV_TAG-$PKGARCH-$PKGVERSION
PKGFILE=mesh-$PKGFOLDER.qpkg
PKGREPLACES=mesh
if [ $PKGBRANCH = "master" ]; then
PKGREPLACES=mesh-develop
fi
if [ $PKGARCH = "x86-64" ]; then GOOS=linux GOARCH=amd64 ./build
elif [ $PKGARCH = "arm-x31" ]; then GOOS=linux GOARCH=arm GOARM=7 ./build
else
echo "Specify PKGARCH=x86-64 or arm-x31"
exit 1
fi
echo "Building $PKGFOLDER"
rm -rf /tmp/$PKGFOLDER
mkdir -p /tmp/$PKGFOLDER/mesh
mkdir -p /tmp/$PKGFOLDER/mesh/icons
mkdir -p /tmp/$PKGFOLDER/mesh/shared/bin
mkdir -p /tmp/$PKGFOLDER/mesh/shared/tmp
mkdir -p /tmp/$PKGFOLDER/mesh/shared/lib
mkdir -p /tmp/$PKGFOLDER/mesh/shared/www
mkdir -p /tmp/$PKGFOLDER/mesh/shared/var/log
chmod 0775 /tmp/$PKGFOLDER/ -R
echo "coping ui package..."
cp contrib/ui/nas-qnap/package/* /tmp/$PKGFOLDER/mesh -r
cp contrib/ui/nas-qnap/au/* /tmp/$PKGFOLDER/mesh/shared -r
cp contrib/ui/www/* /tmp/$PKGFOLDER/mesh/shared/www/ -r
echo "Converting icon for: 64x64"
convert -colorspace sRGB ./riv.png -resize 64x64 /tmp/$PKGFOLDER/mesh/icons/mesh.gif
echo "Converting icon for: 80x80"
convert -colorspace sRGB ./riv.png -resize 80x80 /tmp/$PKGFOLDER/mesh/icons/mesh_80.gif
convert -colorspace sRGB ./riv.png -resize 64x64 /tmp/$PKGFOLDER/mesh/icons/mesh_gray.gif
cat > /tmp/$PKGFOLDER/mesh/qpkg.cfg << EOF
QPKG_DISPLAY_NAME="RiV Mesh"
QPKG_NAME="mesh"
QPKG_VER="$PKGVERSION"
QPKG_AUTHOR="Riv Chain ltd"
QPKG_SUMMARY="RiV-mesh is an implementation of a fully end-to-end encrypted IPv6 network."
QPKG_RC_NUM="198"
QPKG_SERVICE_PROGRAM="mesh.sh"
QPKG_WEBUI="/mesh"
QPKG_WEB_PORT=
QPKG_LICENSE="LGPLv3"
QDK_BUILD_ARCH="$PKGARCH"
EOF
touch /tmp/$PKGFOLDER/mesh/qdk.conf
cp mesh /tmp/$PKGFOLDER/mesh/shared/bin
cp meshctl /tmp/$PKGFOLDER/mesh/shared/bin
chmod +x /tmp/$PKGFOLDER/mesh/shared/bin/*
chmod 0775 /tmp/$PKGFOLDER/mesh/shared/www -R
chmod -R u+rwX,go+rX,g-w /tmp/$PKGFOLDER
curent_dir=$(pwd)
cd /tmp/$PKGFOLDER/mesh && /opt/tomcat/tool/Qnap/bin/qbuild --force-config -v
mv build/*.qpkg "$curent_dir"/$PKGFILE
rm -rf /tmp/$PKGFOLDER/

View file

@ -0,0 +1,92 @@
#!/bin/sh
# This is a lazy script to create a .bin for WD NAS build.
# You can give it the PKGARCH= argument
# i.e. PKGARCH=armv7hf contrib/nas/nas-westerndigital-os5.sh
if [ `pwd` != `git rev-parse --show-toplevel` ]
then
echo "You should run this script from the top-level directory of the git repo"
exit 1
fi
PKGBRANCH=$(basename `git name-rev --name-only HEAD`)
PKG=$(sh contrib/semver/name.sh)
PKGVERSION=$(sh contrib/nas/tool/synology_version.sh --bare)
PKGARCH=${PKGARCH-amd64}
PKGNAME=$ENV_TAG-$PKGARCH-$PKGVERSION
PKGFOLDER=${PKGNAME}/package
PKGREPLACES=mesh
if [ $PKGBRANCH = "master" ]; then
PKGREPLACES=mesh-develop
fi
if [ $PKGARCH = "x86_64" ]; then GOOS=linux GOARCH=amd64 ./build
elif [ $PKGARCH = "armv7" ]; then GOOS=linux GOARCH=arm GOARM=7 ./build
else
echo "Specify PKGARCH=x86_64"
exit 1
fi
echo "Building $PKGNAME"
rm -rf /tmp/${PKGNAME}
mkdir -p /tmp/$PKGFOLDER/bin/
mkdir -p /tmp/$PKGFOLDER/lib/
mkdir -p /tmp/$PKGFOLDER/tmp/
mkdir -p /tmp/$PKGFOLDER/ui/
mkdir -p /tmp/$PKGFOLDER/var/log/
mkdir -p /tmp/$PKGFOLDER/var/lib/mesh
chmod 0775 /tmp/$PKGFOLDER/ -R
echo "coping ui package..."
cp contrib/ui/nas-synology-dsm6.0/package/* /tmp/$PKGFOLDER/ -r
cp contrib/ui/nas-synology-dsm6.0/spk/* /tmp/$PKGNAME/ -r
cp contrib/ui/www/* /tmp/$PKGFOLDER/www/ -r
for res in 16 24 32 48 64 72 256; do
resolution="${res}x${res}"
echo "Converting icon for: $resolution"
convert -colorspace sRGB ./riv.png -resize $resolution PNG32:/tmp/$PKGFOLDER/ui/mesh-$res.png && \
chmod 644 /tmp/$PKGFOLDER/ui/mesh-$res.png
done
echo "Converting icon for: 72x72"
convert -colorspace sRGB ./riv.png -resize 72x72 PNG32:/tmp/$PKGNAME/PACKAGE_ICON.PNG
echo "Converting icon for: 256x256"
convert -colorspace sRGB ./riv.png -resize 256x256 PNG32:/tmp/$PKGNAME/PACKAGE_ICON_256.PNG
cat > /tmp/$PKGNAME/INFO << EOF
package="mesh"
displayname="RiV Mesh"
version="$PKGVERSION"
description="RiV-mesh is an implementation of a fully end-to-end encrypted IPv6 network. \
It is lightweight, self-arranging, supported on multiple platforms and \
allows pretty much any IPv6-capable application to communicate securely with \
other RiV-mesh nodes."
maintainer="Riv Chain ltd"
maintainer_url="https://github.com/RiV-chain/RiV-mesh"
support_url="https://github.com/RiV-chain/RiV-mesh"
dsmappname="org.mesh"
arch="$PKGARCH"
dsmuidir="ui"
silent_upgrade="yes"
os_min_ver="6.0-7320"
EOF
echo $PKGVERSION > /tmp/$PKGNAME/VERSION
cp mesh /tmp/$PKGFOLDER/bin
cp meshctl /tmp/$PKGFOLDER/bin
cp LICENSE /tmp/$PKGNAME/
chmod -R 0755 /tmp/$PKGFOLDER/www/assets
chmod -R u+rwX,go+rX,g-w /tmp/$PKGFOLDER
chmod -R +x /tmp/$PKGNAME/scripts
fakeroot ./contrib/nas/tool/synology_pkg_util.sh make_package /tmp/$PKGFOLDER /tmp/$PKGNAME
rm -rf /tmp/$PKGFOLDER/
fakeroot ./contrib/nas/tool/synology_pkg_util.sh make_spk /tmp/$PKGNAME . $PKGNAME.spk

View file

@ -0,0 +1,95 @@
#!/bin/sh
# This is a lazy script to create a .bin for WD NAS build.
# You can give it the PKGARCH= argument
# i.e. PKGARCH=armv7hf contrib/nas/nas-westerndigital-os5.sh
if [ `pwd` != `git rev-parse --show-toplevel` ]
then
echo "You should run this script from the top-level directory of the git repo"
exit 1
fi
PKGBRANCH=$(basename `git name-rev --name-only HEAD`)
PKG=$(sh contrib/semver/name.sh)
PKGVERSION=$(sh contrib/nas/tool/synology_version.sh --bare)
PKGARCH=${PKGARCH-amd64}
PKGNAME=$ENV_TAG-$PKGARCH-$PKGVERSION
PKGFOLDER=${PKGNAME}/package
PKGREPLACES=mesh
if [ $PKGBRANCH = "master" ]; then
PKGREPLACES=mesh-develop
fi
if [ $PKGARCH = "x86_64" ]; then GOOS=linux GOARCH=amd64 ./build
elif [ $PKGARCH = "armv7" ]; then GOOS=linux GOARCH=arm GOARM=7 ./build
else
echo "Specify PKGARCH=x86_64 or armv7"
exit 1
fi
echo "Building $PKGNAME"
rm -rf /tmp/${PKGNAME}
mkdir -p /tmp/$PKGFOLDER/bin/
mkdir -p /tmp/$PKGFOLDER/lib/
mkdir -p /tmp/$PKGFOLDER/tmp/
mkdir -p /tmp/$PKGFOLDER/ui/
mkdir -p /tmp/$PKGFOLDER/var/log/
mkdir -p /tmp/$PKGFOLDER/var/lib/mesh
chmod 0775 /tmp/$PKGFOLDER/ -R
echo "coping ui package..."
cp contrib/ui/nas-synology-dsm6.0/package/* /tmp/$PKGFOLDER/ -r
cp contrib/ui/nas-synology-dsm6.0/spk/* /tmp/$PKGNAME/ -r
cp contrib/ui/nas-synology-dsm7.0/package/* /tmp/$PKGFOLDER/ -r
cp contrib/ui/nas-synology-dsm7.0/spk/* /tmp/$PKGNAME/ -r
cp contrib/ui/www/* /tmp/$PKGFOLDER/www/ -r
for res in 16 24 32 48 64 72 256; do
resolution="${res}x${res}"
echo "Converting icon for: $resolution"
convert -colorspace sRGB ./riv.png -resize $resolution PNG32:/tmp/$PKGFOLDER/ui/mesh-$res.png && \
chmod 644 /tmp/$PKGFOLDER/ui/mesh-$res.png
done
echo "Converting icon for: 64x64"
convert -colorspace sRGB ./riv.png -resize 64x64 PNG32:/tmp/$PKGNAME/PACKAGE_ICON.PNG
echo "Converting icon for: 256x256"
convert -colorspace sRGB ./riv.png -resize 256x256 PNG32:/tmp/$PKGNAME/PACKAGE_ICON_256.PNG
cat > /tmp/$PKGNAME/INFO << EOF
package="mesh"
displayname="RiV Mesh"
version="$PKGVERSION"
description="RiV-mesh is an implementation of a fully end-to-end encrypted IPv6 network. \
It is lightweight, self-arranging, supported on multiple platforms and \
allows pretty much any IPv6-capable application to communicate securely with \
other RiV-mesh nodes."
maintainer="Riv Chain ltd"
maintainer_url="https://github.com/RiV-chain/RiV-mesh"
support_url="https://github.com/RiV-chain/RiV-mesh"
dsmappname="org.mesh"
arch="$PKGARCH"
dsmuidir="ui"
silent_upgrade="yes"
os_min_ver="7.0-40000"
EOF
echo $PKGVERSION > /tmp/$PKGNAME/VERSION
cp mesh /tmp/$PKGFOLDER/bin
cp meshctl /tmp/$PKGFOLDER/bin
cp LICENSE /tmp/$PKGNAME/
chmod -R 0755 /tmp/$PKGFOLDER/www/assets
chmod -R u+rwX,go+rX,g-w /tmp/$PKGFOLDER
chmod -R 0755 /tmp/$PKGNAME/scripts
chmod -R 0755 /tmp/$PKGNAME/conf
fakeroot ./contrib/nas/tool/synology_pkg_util.sh make_package /tmp/$PKGFOLDER /tmp/$PKGNAME
rm -rf /tmp/$PKGFOLDER/
fakeroot ./contrib/nas/tool/synology_pkg_util.sh make_spk /tmp/$PKGNAME . $PKGNAME.spk

View file

@ -0,0 +1,91 @@
#!/bin/sh
# This is a lazy script to create a .bin for Terramaster NAS build.
# You can give it the PKGARCH= argument
# i.e. PKGARCH=x86_64 contrib/nas/nas-terramaster.sh
if [ `pwd` != `git rev-parse --show-toplevel` ]
then
echo "You should run this script from the top-level directory of the git repo"
exit 1
fi
PKGBRANCH=$(basename `git name-rev --name-only HEAD`)
PKG=$(sh contrib/semmsiver/name.sh)
PKGVERSION=$(sh contrib/msi/msversion.sh --bare)
PKGARCH=${PKGARCH-amd64}
PKGFOLDER=$ENV_TAG-$PKGARCH-$PKGVERSION
PKGFILE=mesh-$PKGFOLDER.tpk
PKGREPLACES=mesh
if [ $PKGBRANCH = "master" ]; then
PKGREPLACES=mesh-develop
fi
if [ -z $TERRAMASTER_TOOLS ]; then
echo "Specify TERRAMASTER_TOOLS path"
exit 1
fi
if [ $PKGARCH = "x86-64" ]; then GOOS=linux GOARCH=amd64 ./build
elif [ $PKGARCH = "arm-x31" ]; then GOOS=linux GOARCH=arm GOARM=7 ./build
else
echo "Specify PKGARCH=x86-64 or arm-x31"
exit 1
fi
echo "Building $PKGFOLDER"
rm -rf /tmp/$PKGFOLDER
mkdir -p /tmp/$PKGFOLDER/mesh/usr/bin
mkdir -p /tmp/$PKGFOLDER/mesh/var/log
mkdir -p /tmp/$PKGFOLDER/mesh/usr/www/images/icons
chmod 0775 /tmp/$PKGFOLDER/ -R
echo "coping ui package..."
cp contrib/ui/nas-terramaster/mesh /tmp/$PKGFOLDER/ -r
cp contrib/ui/www/* /tmp/$PKGFOLDER/mesh/usr/local/mesh/www -r
echo "Converting icon for: 120x120"
convert -colorspace sRGB ./riv.png -resize 120x120 PNG32:/tmp/$PKGFOLDER/mesh/usr/www/images/icons/mesh.png
echo "$PKGVERSION" > /tmp/$PKGFOLDER/mesh/version
cat > /tmp/$PKGFOLDER/mesh/mesh.lang << EOF
[zh-cn]
name = "RiV Mesh"
auth = "mesh"
version = "$PKGVERSION"
descript = "RiV-mesh is an implementation of a fully end-to-end encrypted IPv6 network."
[en-us]
name = "RiV Mesh"
auth = "mesh"
version = "$PKGVERSION"
descript = "RiV-mesh is an implementation of a fully end-to-end encrypted IPv6 network."
EOF
cp mesh /tmp/$PKGFOLDER/mesh/usr/bin
cp meshctl /tmp/$PKGFOLDER/mesh/usr/bin
cp riv.svg /tmp/$PKGFOLDER/mesh/usr/www/images/icons/mesh.svg
ln -s /usr/mesh/var/log/mesh.log /tmp/$PKGFOLDER/mesh/usr/local/mesh/www/log
chmod +x /tmp/$PKGFOLDER/mesh/usr/bin/*
chmod 0775 /tmp/$PKGFOLDER/mesh/usr/www -R
chmod -R u+rwX,go+rX,g-w /tmp/$PKGFOLDER
curent_dir=$(pwd)
cd /tmp/$PKGFOLDER/
cp $TERRAMASTER_TOOLS/makeapp .
cp $TERRAMASTER_TOOLS/install-* .
cp -r $TERRAMASTER_TOOLS/phpencode .
./makeapp mesh
cd dist/$PKGFOLDER && mv *.tpk "$curent_dir"/$PKGFILE
cd "$curent_dir"
rm -rf /tmp/$PKGFOLDER/

View file

@ -0,0 +1,92 @@
#!/bin/sh
# This is a lazy script to create a .bin for WD NAS build.
# You can give it the PKGARCH= argument
# i.e. PKGARCH=armv7hf contrib/nas/nas-westerndigital-os5.sh
if [ `pwd` != `git rev-parse --show-toplevel` ]
then
echo "You should run this script from the top-level directory of the git repo"
exit 1
fi
PKGBRANCH=$(basename `git name-rev --name-only HEAD`)
PKG=$(sh contrib/semver/name.sh)
PKGVERSION=$(sh contrib/semver/version.sh --bare)
PKGARCH=${PKGARCH-amd64}
PKGNAME=$PKG-$PKGVERSION-$PKGARCH
PKGFOLDER=mesh
PKGREPLACES=mesh
if [ $PKGBRANCH = "master" ]; then
PKGREPLACES=mesh-develop
fi
if [ $PKGARCH = "arm" ]; then GOOS=linux GOARCH=arm GOARM=5 ./build
else
echo "Specify PKGARCH=arm"
exit 1
fi
echo "Building $PKGNAME"
rm -rf /tmp/$PKGFOLDER
mkdir -p /tmp/$PKGFOLDER/bin/
mkdir -p /tmp/$PKGFOLDER/tmp/
mkdir -p /tmp/$PKGFOLDER/lib/
mkdir -p /tmp/$PKGFOLDER/var/log/
mkdir -p /tmp/$PKGFOLDER/var/lib/mesh
chmod 0775 /tmp/$PKGFOLDER/ -R
echo "coping ui package..."
cp contrib/ui/nas-westerndigital/package/mesh/* /tmp/$PKGFOLDER/ -r
cp contrib/ui/www/* /tmp/$PKGFOLDER/www/ -r
for resolution in 256x256; do
echo "Converting icon for: $resolution"
convert -colorspace sRGB ./riv.png -resize $resolution PNG32:/tmp/$PKGFOLDER/www/mesh.png && \
chmod 644 /tmp/$PKGFOLDER/www/mesh.png
done
cat > /tmp/$PKGFOLDER/apkg.rc << EOF
Package: mesh
Section: Apps
Version: $PKGVERSION
Packager: RiV Chain
Email: vadym.vikulin@rivchain.org
Homepage: https://github.com/RiV-chain/RiV-mesh
Description: RiV-mesh is an implementation of a fully end-to-end encrypted IPv6 network.
It is lightweight, self-arranging, supported on multiple platforms and
allows pretty much any IPv6-capable application to communicate securely with
other RiV-mesh nodes.
Icon: mesh.png
AddonShowName: RiV Mesh
AddonIndexPage: index.html?v=$PKGVERSION
AddonUsedPort:
InstDepend:
InstConflict:
StartDepend:
StartConflict:
CenterType: 0
UserControl: 1
MinFWVer:
MaxFWVer:
IndividualFlag:
EOF
cp mesh /tmp/$PKGFOLDER/bin
cp meshctl /tmp/$PKGFOLDER/bin
chmod -R 0755 /tmp/$PKGFOLDER/www/assets
chmod -R u+rwX,go+rX,g-w /tmp/$PKGFOLDER
chmod +x /tmp/$PKGFOLDER/*.sh
curent_dir=$(pwd)
echo "current folder=$curent_dir"
cd /tmp/$PKGFOLDER/ && mksapkg -E -s -m WDMyCloudEX4
cp /tmp/WDMyCloudEX4_mesh_$PKGVERSION.bin* "$curent_dir"
rm -rf /tmp/$PKGFOLDER
cd "$curent_dir"

View file

@ -0,0 +1,92 @@
#!/bin/sh
# This is a lazy script to create a .bin for WD NAS build.
# You can give it the PKGARCH= argument
# i.e. PKGARCH=armv7hf contrib/nas/nas-westerndigital-os5.sh
if [ `pwd` != `git rev-parse --show-toplevel` ]
then
echo "You should run this script from the top-level directory of the git repo"
exit 1
fi
PKGBRANCH=$(basename `git name-rev --name-only HEAD`)
PKG=$(sh contrib/semver/name.sh)
PKGVERSION=$(sh contrib/semver/version.sh --bare)
PKGARCH=${PKGARCH-amd64}
PKGNAME=$PKG-$PKGVERSION-$PKGARCH
PKGFOLDER=mesh
PKGREPLACES=mesh
if [ $PKGBRANCH = "master" ]; then
PKGREPLACES=mesh-develop
fi
if [ $PKGARCH = "armv7hf" ]; then GOOS=linux GOARCH=arm GOARM=7 ./build
else
echo "Specify PKGARCH=armv7hf"
exit 1
fi
echo "Building $PKGNAME"
rm -rf /tmp/$PKGFOLDER
mkdir -p /tmp/$PKGFOLDER/bin/
mkdir -p /tmp/$PKGFOLDER/tmp/
mkdir -p /tmp/$PKGFOLDER/lib/
mkdir -p /tmp/$PKGFOLDER/var/log/
mkdir -p /tmp/$PKGFOLDER/var/lib/mesh
chmod 0775 /tmp/$PKGFOLDER/ -R
echo "coping ui package..."
cp contrib/ui/nas-westerndigital/package/mesh/* /tmp/$PKGFOLDER/ -r
cp contrib/ui/www/* /tmp/$PKGFOLDER/www/ -r
for resolution in 256x256; do
echo "Converting icon for: $resolution"
convert -colorspace sRGB ./riv.png -resize $resolution PNG32:/tmp/$PKGFOLDER/www/mesh.png && \
chmod 644 /tmp/$PKGFOLDER/www/mesh.png
done
cat > /tmp/$PKGFOLDER/apkg.rc << EOF
Package: mesh
Section: Apps
Version: $PKGVERSION
Packager: RiV Chain
Email: vadym.vikulin@rivchain.org
Homepage: https://github.com/RiV-chain/RiV-mesh
Description: RiV-mesh is an implementation of a fully end-to-end encrypted IPv6 network.
It is lightweight, self-arranging, supported on multiple platforms and
allows pretty much any IPv6-capable application to communicate securely with
other RiV-mesh nodes.
Icon: mesh.png
AddonShowName: RiV Mesh
AddonIndexPage: index.html?v=$PKGVERSION
AddonUsedPort:
InstDepend:
InstConflict:
StartDepend:
StartConflict:
CenterType: 0
UserControl: 1
MinFWVer:
MaxFWVer:
IndividualFlag:
EOF
cp mesh /tmp/$PKGFOLDER/bin
cp meshctl /tmp/$PKGFOLDER/bin
chmod -R 0755 /tmp/$PKGFOLDER/www/assets
chmod -R u+rwX,go+rX,g-w /tmp/$PKGFOLDER
chmod +x /tmp/$PKGFOLDER/*.sh
curent_dir=$(pwd)
echo "current folder=$curent_dir"
cd /tmp/$PKGFOLDER/ && MyCloudOS5_mksapkg -E -s -m WDMyCloudEX4100
cp /tmp/WDMyCloudEX4100_mesh_$PKGVERSION.bin* "$curent_dir"
rm -rf /tmp/$PKGFOLDER
cd "$curent_dir"

View file

@ -0,0 +1,574 @@
#!/usr/bin/env python2
# Copyright (c) 2011-2013 Asustor Systems, Inc. All Rights Reserved.
# -*- coding: utf-8 -*-
import os
import sys
import argparse
import zipfile
import tarfile
import tempfile
import shutil
import json
import glob
import re
import csv
__author__ = 'Walker Lee <walkerlee@asustor.com>'
__copyright__ = 'Copyright (C) 2011-2013 ASUSTOR Systems, Inc. All Rights Reserved.'
__version__ = '0.1'
__abs_path__ = os.path.abspath(sys.argv[0])
__program__ = os.path.basename(__abs_path__)
def find_developer(app):
developer = None
if os.path.exists('apkg-developer-mapping.csv'):
with open('apkg-developer-mapping.csv', 'r') as f:
for row in csv.reader(f):
if row[0] == app:
developer = row[1]
break;
return developer
class Chdir:
def __init__(self, newPath):
self.newPath = newPath
def __enter__(self):
self.savedPath = os.getcwd()
os.chdir(self.newPath)
def __exit__(self, etype, value, traceback):
os.chdir(self.savedPath)
class Apkg:
umask = 0022
tmp_dir = '/tmp'
tmp_prefix = 'APKG-'
apk_format = {
'version' : '2.0',
'format' : 'zip',
'suffix' : 'apk'
}
apk_file_contents = {
'version' : 'apkg-version',
'data' : 'data.tar.gz',
'control' : 'control.tar.gz'
}
apk_special_folders = {
'control' : 'CONTROL',
'webman' : 'webman',
'web' : 'www'
}
apk_control_files = {
'pkg-config' : 'config.json',
'changlog' : 'changelog.txt',
'description' : 'description.txt',
'icon' : 'icon.png',
'script-pre-install' : 'pre-install.sh',
'script-pre-uninstall' : 'pre-uninstall.sh',
'script-post-install' : 'post-install.sh',
'script-post-uninstall' : 'post-uninstall.sh',
'script-start-stop' : 'start-stop.sh',
}
apk_web_settings = {
'user' : 'admin',
'group' : 'administrators',
'uid' : 999,
'gid' : 999,
'perms' : 0770
}
def __init__(self):
self.pid = os.getpid()
self.cwd = os.getcwd()
self.pkg_tmp_dir = self.tmp_dir + '/APKG.' + str(self.pid)
def __del__(self):
pass
def pkg_misc_check(self):
pass
def compress_pkg(self):
pass
def __check_apk_format(self, apk_file):
file_list = []
# check apk file format
try:
with zipfile.ZipFile(apk_file, 'r') as apk_zip:
file_list = apk_zip.namelist()
except zipfile.BadZipfile:
print 'File is not a apk file: %s' % (apk_file)
return False
# check apk file contents
if not file_list:
print 'File is empty: %s' % (apk_file)
return False
result = True
for (key, value) in self.apk_file_contents.items():
if value not in file_list:
print 'Can\'t found file in apk file: %s' % (value)
result = False
return result
# return True for files we want to exclude
def __excluded_files(self, file):
_return = False
# here we're checking to see if the file is 'CONTROL' -
# a file don't want included in our tar archive.
if file.find('CONTROL') > -1:
_return = True
return _return
def __zip_archive(self, apk_file, file_list):
with zipfile.ZipFile(apk_file, 'w') as apk_zip:
for one_file in file_list:
apk_zip.write(one_file)
def __zip_extract(self, apk_file, member, path):
with zipfile.ZipFile(apk_file, 'r') as apk_zip:
apk_zip.extract(member, path)
def __tar_archive(self, tar_file, path):
# create a tar archive of directory
with tarfile.open(tar_file, 'w:gz') as tar:
if os.path.basename(tar_file) == self.apk_file_contents['data']:
tar.add(path, exclude=self.__excluded_files)
else:
tar.add(path)
def __tar_extract(self, tar_file, path):
with tarfile.open(tar_file, 'r:gz') as tar:
tar.extractall(path)
def __get_apkg_version(self, version_file):
with file(version_file) as f:
version = f.read().rstrip()
return version
def __get_app_info_v1(self, control_dir):
with open(control_dir + '/' + self.apk_control_files['pkg-config']) as data_file:
data = json.load(data_file)
return data
def __get_app_info_v2(self, control_dir):
with open(control_dir + '/' + self.apk_control_files['pkg-config']) as data_file:
data = json.load(data_file)
return data
def __get_app_info(self, control_dir, apkg_version):
if apkg_version == '1.0':
return self.__get_app_info_v1(control_dir)
elif apkg_version == '2.0':
return self.__get_app_info_v2(control_dir)
else:
return None
def __check_app_layout(self, app_dir):
control_dir = app_dir + '/' + self.apk_special_folders['control']
if not os.path.isdir(control_dir):
print '[Not found] CONTROL folder: %s' % (control_dir)
return False
config_file = control_dir + '/' + self.apk_control_files['pkg-config']
if not os.path.isfile(config_file):
print '[Not found] config file: %s' % (config_file)
return False
# TODO: check icon exist?
icon_file = control_dir + '/' + self.apk_control_files['icon']
pass
return True
def __check_app_info_fields(self, app_info):
require_fields = ['package', 'version', 'architecture', 'firmware']
for field in require_fields:
try:
if app_info['general'][field].strip() == '':
print 'Empty field: %s' % (field)
return False
except KeyError:
print 'Missing field: %s' % (field)
return False
return True
def __filter_special_chars(self, string, pattern):
filter_string = re.sub(pattern, '', string)
return filter_string
def __check_app_package_name(self, package):
return True if self.__filter_special_chars(package, '[a-zA-Z0-9.+-]') == '' else False
def create(self, folder, dest_dir=None):
# check folder is exist
app_dir = os.path.abspath(folder)
if not os.path.isdir(app_dir):
print 'Not a directory: %s' % (app_dir)
return -1
control_dir = app_dir + '/' + self.apk_special_folders['control']
config_file = control_dir + '/' + self.apk_control_files['pkg-config']
# check package layout is correct
if not self.__check_app_layout(app_dir):
print 'Invalid App layout: %s' % (app_dir)
return -1
# change file mode and owner
os.chmod(control_dir, 0755)
os.chown(control_dir, 0, 0)
all_files = glob.glob(control_dir + '/*')
sh_files = glob.glob(control_dir + '/*.sh')
py_files = glob.glob(control_dir + '/*.py')
for one_file in all_files:
os.chmod(one_file, 0644)
os.chown(one_file, 0, 0)
for one_file in sh_files:
os.chmod(one_file, 0755)
os.system('dos2unix %s > /dev/null 2>&1' % (one_file))
for one_file in py_files:
os.chmod(one_file, 0755)
app_info = self.__get_app_info(control_dir, self.apk_format['version'])
# check config.json fields
if not self.__check_app_info_fields(app_info):
print 'Invalid App config: %s' % (config_file)
return -1
# check package field value
if not self.__check_app_package_name(app_info['general']['package']):
print 'Invalid App package field: %s (valid characters [a-zA-Z0-9.+-])' % ('package')
return -1
# prepare tmp dir
tmp_dir = tempfile.mkdtemp(prefix=self.tmp_prefix)
version_file = tmp_dir + '/' + self.apk_file_contents['version']
control_tar_gz = tmp_dir + '/' + self.apk_file_contents['control']
data_tar_gz = tmp_dir + '/' + self.apk_file_contents['data']
if dest_dir == None:
dest_dir = os.getcwd()
else:
dest_dir = os.path.abspath(dest_dir)
apk_file = dest_dir + '/' + app_info['general']['package'] + '_' + app_info['general']['version'] + '_' + app_info['general']['architecture'] + '.' + self.apk_format['suffix']
# write apkg version
with open(version_file, 'w') as apkg_version:
apkg_version.write(self.apk_format['version'] + '\n')
# archive data files
with Chdir(app_dir):
self.__tar_archive(data_tar_gz, '.')
# archive control files
with Chdir(control_dir):
self.__tar_archive(control_tar_gz, '.')
# archive apk file
with Chdir(tmp_dir):
self.__zip_archive(apk_file, [self.apk_file_contents['version'], self.apk_file_contents['control'], self.apk_file_contents['data']])
# cleanup temp folder
shutil.rmtree(tmp_dir, ignore_errors=True)
return apk_file
def extract(self, package, dest_dir=None):
# check file is exist
apk_file = os.path.abspath(package)
if not os.path.isfile(apk_file):
print 'Not a file: %s' % (apk_file)
return -1
# check package format (apk: zip format; contain files: apkg-version, control.tar.gz, data.tar.gz)
if not self.__check_apk_format(apk_file):
return -1
# unpack package phase 1
tmp_dir = tempfile.mkdtemp(prefix=self.tmp_prefix)
tmp_contents_dir = tmp_dir + '/@contents@'
os.mkdir(tmp_contents_dir)
self.__zip_extract(apk_file, self.apk_file_contents['version'], tmp_contents_dir)
self.__zip_extract(apk_file, self.apk_file_contents['control'], tmp_contents_dir)
self.__zip_extract(apk_file, self.apk_file_contents['data'], tmp_contents_dir)
# unpack package phase 2
tmp_control_dir = tmp_dir + '/' + self.apk_special_folders['control']
os.mkdir(tmp_control_dir)
self.__tar_extract(tmp_contents_dir + '/' + self.apk_file_contents['control'], tmp_control_dir)
self.__tar_extract(tmp_contents_dir + '/' + self.apk_file_contents['data'], tmp_dir)
# get apkg version
apkg_version = self.__get_apkg_version(tmp_contents_dir + '/' + self.apk_file_contents['version'])
# clean tmp contents dir
shutil.rmtree(tmp_contents_dir, ignore_errors=True)
# get apk information
apk_info = self.__get_app_info(tmp_control_dir, apkg_version)
# error handle
if apk_info is None:
print 'Extract error: %s' % (apk_file)
shutil.rmtree(tmp_dir, ignore_errors=True)
return -1
if dest_dir == None:
dest_dir = os.getcwd()
else:
dest_dir = os.path.abspath(dest_dir)
# move dir
if apkg_version == '1.0':
app_dir = dest_dir + '/' + apk_info['app']['name'] + '_' + apk_info['app']['version'] + '_' + apk_info['app']['architecture']
elif apkg_version == '2.0':
app_dir = dest_dir + '/' + apk_info['general']['name'] + '_' + apk_info['general']['version'] + '_' + apk_info['general']['architecture']
if os.path.isdir(app_dir):
print 'The folder is exist, please remove it: %s' % (app_dir)
shutil.rmtree(tmp_dir, ignore_errors=True)
return -1
else:
shutil.move(tmp_dir, app_dir)
return app_dir
def convert(self, package):
app_dir = self.extract(package, dest_dir='/tmp')
if app_dir == -1:
print 'Convert error'
return -1
control_dir = app_dir + '/' + self.apk_special_folders['control']
config_file = control_dir + '/' + self.apk_control_files['pkg-config']
changelog_file = control_dir + '/' + self.apk_control_files['changlog']
description_file = control_dir + '/' + self.apk_control_files['description']
# get old format app information
app_old_info = self.__get_app_info(control_dir, self.apk_format['version'])
app_new_info = {}
developer = find_developer(app_old_info['app']['package'])
app_new_info['general'] = {}
app_new_info['general']['package'] = app_old_info['app']['package']
app_new_info['general']['name'] = app_old_info['app']['name']
app_new_info['general']['version'] = app_old_info['app']['version']
app_new_info['general']['depends'] = app_old_info['app']['depends']
app_new_info['general']['conflicts'] = app_old_info['app']['conflicts']
app_new_info['general']['developer'] = app_old_info['app']['website'] if (developer is None) else developer
app_new_info['general']['maintainer'] = app_old_info['app']['maintainer']
app_new_info['general']['email'] = app_old_info['app']['email']
app_new_info['general']['website'] = app_old_info['app']['website']
app_new_info['general']['architecture'] = app_old_info['app']['architecture']
app_new_info['general']['firmware'] = '2.0'
try:
app_old_info['desktop']
except KeyError:
app_old_info['desktop'] = {}
try:
app_old_info['desktop']['icon']
except KeyError:
app_old_info['desktop']['icon'] = {}
# remove unused field
app_old_info['desktop']['icon'].pop('title', None)
try:
app_old_info['desktop']['privilege']
except KeyError:
app_old_info['desktop']['privilege'] = {}
app_new_info['adm-desktop'] = {}
app_new_info['adm-desktop']['app'] = app_old_info['desktop']['icon']
app_new_info['adm-desktop']['privilege'] = app_old_info['desktop']['privilege']
try:
app_old_info['install']['link']
except KeyError:
app_old_info['install']['link'] = {}
try:
app_old_info['install']['share']
except KeyError:
app_old_info['install']['share'] = []
try:
app_old_info['install']['service-reg']
except KeyError:
app_old_info['install']['service-reg'] = {}
try:
app_old_info['install']['service-reg']['priority']
except KeyError:
app_old_info['install']['service-reg']['priority'] = {}
try:
app_old_info['install']['service-reg']['port']
except KeyError:
app_old_info['install']['service-reg']['port'] = []
try:
app_old_info['install']['dep-service']
except KeyError:
app_old_info['install']['dep-service'] = {}
try:
app_old_info['install']['dep-service']['start']
except KeyError:
app_old_info['install']['dep-service']['start'] = []
try:
app_old_info['install']['dep-service']['restart']
except KeyError:
app_old_info['install']['dep-service']['restart'] = []
app_new_info['register'] = {}
app_new_info['register']['symbolic-link'] = app_old_info['install']['link']
app_new_info['register']['share-folder'] = app_old_info['install']['share']
app_new_info['register']['port'] = app_old_info['install']['service-reg']['port']
app_new_info['register']['boot-priority'] = {}
try:
app_new_info['register']['boot-priority']['start-order'] = app_old_info['install']['service-reg']['priority']['start']
except KeyError:
pass
try:
app_new_info['register']['boot-priority']['stop-order'] = app_old_info['install']['service-reg']['priority']['stop']
except KeyError:
pass
app_new_info['register']['prerequisites'] = {}
app_new_info['register']['prerequisites']['enable-service'] = app_old_info['install']['dep-service']['start']
app_new_info['register']['prerequisites']['restart-service'] = app_old_info['install']['dep-service']['restart']
# get changelog and description
changelog = app_old_info['app'].pop('changes', None).strip()
description = app_old_info['app'].pop('description', None).strip()
# convert json object to string
json_string = json.dumps(app_new_info, indent=3)
# set new format app information
with open(config_file, 'w') as new_file:
new_file.write(json_string + '\n')
# write changelog.txt
if changelog is not None and changelog != '':
with open(changelog_file, 'w') as new_file:
new_file.write(changelog + '\n')
# write description.txt
if description is not None and description != '':
with open(description_file, 'w') as new_file:
new_file.write(description + '\n')
# convert icon
icon_enable_file = control_dir + '/icon-enable.png'
icon_disable_file = control_dir + '/icon-disable.png'
icon_file = control_dir + '/' + self.apk_control_files['icon']
os.unlink(icon_disable_file)
os.rename(icon_enable_file, icon_file)
convert_dir = os.getcwd() + '/apk-2.0'
if not os.path.exists(convert_dir):
os.mkdir(convert_dir)
# re-pack apk
apk_file = self.create(app_dir, dest_dir=convert_dir)
# cleanup app folder
shutil.rmtree(app_dir, ignore_errors=True)
print 'Convert success: %s' % (apk_file)
def upload(self, package):
# check file is exist
abs_path = os.path.abspath(package)
if not os.path.isfile(abs_path):
print 'Not a file: %s' % (abs_path)
return -1
print 'function not support: %s' % ('upload')
# main
if __name__ == "__main__":
# create the top-level parser
parser = argparse.ArgumentParser(description='asustor package helper.')
subparsers = parser.add_subparsers(help='sub-commands')
# create the parser for the "create" commad
parser_create = subparsers.add_parser('create', help='create package from folder')
parser_create.add_argument('folder', help='select a package layout folder to pack')
parser_create.add_argument('--destination', help='move apk to destination folder')
parser_create.set_defaults(command='create')
# create the parser for the "extract" commad
parser_extract = subparsers.add_parser('extract', help='extract package to folder')
parser_extract.add_argument('package', help='select a package to extract')
parser_extract.add_argument('--destination', help='extract apk to destination folder')
parser_extract.set_defaults(command='extract')
# create the parser for the "convert" commad
# parser_convert = subparsers.add_parser('convert', help='convert package format to 2.0')
# parser_convert.add_argument('package', help='select a package to convert')
# parser_convert.set_defaults(command='convert')
# create the parser for the "upload" commad
# parser_upload = subparsers.add_parser('upload', help='upload package to file server')
# parser_upload.add_argument('package', help='select a package to upload')
# parser_upload.set_defaults(command='upload')
# parsing arguments
args = parser.parse_args()
# process commands
apkg = Apkg()
if args.command == 'create':
apkg.create(args.folder, args.destination)
elif args.command == 'extract':
apkg.extract(args.package, args.destination)
# elif args.command == 'convert':
# apkg.convert(args.package)
# elif args.command == 'upload':
# apkg.upload(args.package)

View file

@ -0,0 +1,436 @@
#!/bin/bash
# Copyright (c) 2000-2015 Synology Inc. All rights reserved.
pkg_warn ()
{
local ret=$?;
echo "Error: $@" 1>&2;
return $?
}
pkg_log ()
{
local ret=$?;
echo "$@" 1>&2;
return $ret
}
pkg_get_string ()
{
local file="$1";
local sec="$2";
local key="$3";
local text="$(sed -n '/^\['$sec'\]/,/^'$key'/s/'$key'.*=[^"]*"\(.*\)"/\1/p' "$file")";
local product_name_original="_DISKSTATION_";
local product_name=$(pkg_get_product_name);
local os_name_original="_OSNAME_";
local os_name=$(pkg_get_os_name);
local idx=0;
shift 3;
for val in "$@";
do
text="${text/\{$idx\}/$val}";
let idx=1+$idx;
done;
echo "$text" | sed -e "s/${product_name_original}/${product_name}/g" | sed -e "s/${os_name_original}/${os_name}/g"
}
pkg_dump_info ()
{
local fields="package version maintainer maintainer_url distributor distributor_url arch exclude_arch model
adminprotocol adminurl adminport firmware dsmuidir dsmappname checkport allow_altport
startable helpurl report_url support_center install_reboot install_dep_packages install_conflict_packages install_dep_services
instuninst_restart_services startstop_restart_services start_dep_services silent_install silent_upgrade silent_uninstall install_type
checksum package_icon package_icon_120 package_icon_128 package_icon_144 package_icon_256 thirdparty support_conf_folder log_collector
support_aaprofile auto_upgrade_from offline_install precheckstartstop";
local f= lan= file= sec= key=;
for f in $fields;
do
if [ -n "${!f}" ]; then
echo $f=\"${!f}\";
fi;
done;
if [ -e "$UISTRING_PATH" -a "$description_sec" -a "$description_key" ]; then
sec=$description_sec;
key=$description_key;
for lan in $UISTRING_PATH/*;
do
lan=$(basename "$lan");
file="$UISTRING_PATH/$lan/strings";
if [ -r "$file" ]; then
echo description_$lan=\"$(pkg_get_string "$file" "$sec" "$key")\";
if [ "x$lan" = "xenu" ]; then
echo description=\"$(pkg_get_string "$file" "$sec" "$key")\";
fi;
fi;
done;
else
if [ "x" != "x$description" ]; then
echo "description=\"${description}\"";
fi;
fi;
if [ -e "$UISTRING_PATH" -a "$displayname_sec" -a "$displayname_key" ]; then
sec=$displayname_sec;
key=$displayname_key;
for lan in $UISTRING_PATH/*;
do
lan=$(basename "$lan");
file="$UISTRING_PATH/$lan/strings";
if [ -r "$file" ]; then
echo displayname_$lan=\"$(pkg_get_string "$file" "$sec" "$key")\";
if [ "x$lan" = "xenu" ]; then
echo displayname=\"$(pkg_get_string "$file" "$sec" "$key")\";
fi;
fi;
done;
else
if [ "x" != "x$displayname" ]; then
echo "displayname=\"${displayname}\"";
fi;
fi
}
plat_to_unified_plat() {
local plat="$1"
local unified_plat=
case "$plat" in
x86 | bromolow | cedarview | avoton )
unified_plat="x86 bromolow cedarview avoton"
;;
# alpine and alpine4k use same define.
alpine )
unified_plat="alpine"
;;
*)
unified_plat="$plat"
;;
esac
echo "$unified_plat"
}
get_var_from_envmak() {
return 1
local var="$1"
shift
local envmaks="$@"
local ret=
local defaultSearchPath="/env.mak /env32.mak"
for f in "${envmaks[@]}" $defaultSearchPath; do
if [ ! -r "$f" ]; then
continue
fi
ret=$(grep "^$var=" "$f" | cut -d= -f2)
if [ -n "$ret" ]; then
break
fi
done
if [ -z "$ret" ]; then
pkg_warn "get_var_from_envmak: can not extract $var from '[$envmaks $defaultSearchPath]'"
return 1
else
echo "$ret"
fi
}
pkg_get_platform ()
{
local arch=;
local PLATFORM_ABBR=$(get_var_from_envmak PLATFORM_ABBR "$1" 2> /dev/null) || return 1;
if [ -n "$PLATFORM_ABBR" ]; then
case "$PLATFORM_ABBR" in
6180)
arch="88f6180"
;;
6281)
arch="88f6281"
;;
816x)
arch="ti816x"
;;
ppc)
arch="powerpc"
;;
824x)
arch="ppc824x"
;;
853x)
arch="ppc853x"
;;
854x)
arch="ppc854x"
;;
x64)
arch="x86"
;;
*)
arch="$PLATFORM_ABBR"
;;
esac;
fi;
if [ -z "$arch" ]; then
local SYNO_PLATFORM=$(get_var_from_envmak SYNO_PLATFORM "$1") || return 1;
case "$SYNO_PLATFORM" in
MARVELL_88F6180)
arch="88f6180"
;;
MARVELL_88F6281)
arch="88f6281"
;;
TI_816X)
arch="ti816x"
;;
POWERPC)
arch="powerpc"
;;
PPC_824X)
arch="ppc824x"
;;
PPC_853X)
arch="ppc853x"
;;
PPC_854X)
arch="ppc854x"
;;
PPC_QORIQ)
arch="qoriq"
;;
X64)
arch="x86"
;;
BROMOLOW)
arch="bromolow"
;;
CEDARVIEW)
arch="cedarview"
;;
AVOTON)
arch="avoton"
;;
MARVELL_ARMADAXP)
arch="armadaxp"
;;
MARVELL_ARMADA370)
arch="armada370"
;;
MARVELL_ARMADA375)
arch="armada375"
;;
EVANSPORT)
arch="evansport"
;;
PPC_CATALINA)
arch="catalina"
;;
MINDSPEED_COMCERTO2K)
arch="comcerto2k"
;;
ALPINE)
arch="alpine"
;;
BROADCOM_NORTHSTARPLUS)
arch="northstarplus"
;;
STM_MONACO)
arch="monaco"
;;
HISILICON_HI3535)
arch="hi3535"
;;
MARVELL_ARMADA38X)
arch="armada38x"
;;
*)
arch=""
;;
esac;
fi;
echo "$arch"
}
pkg_get_spk_platform ()
{
local plat=$(pkg_get_platform "$1") || return 1;
local spk_plat=;
case "$plat" in
88f6281)
spk_plat="88f628x"
;;
*)
spk_plat="$plat"
;;
esac;
echo "$spk_plat"
}
pkg_make_package ()
{
local source_path=$1;
local dest_path=$2;
local package_name="package.tgz";
local temp_extractsize="extractsize_tmp";
local pkg_size=;
local tar_option="$(pkg_get_tar_option)";
if [ -z "$source_path" -o ! -d "$source_path" ]; then
pkg_warn "pkg_make_package: bad parameters, please set source dir";
return 1;
fi;
if [ -z "$dest_path" -o ! -d "$dest_path" ]; then
pkg_warn "pkg_make_package: bad parameters, please set destination dir";
return 1;
fi;
pkg_size=`du -sk "$source_path" | awk '{print $1}'`;
echo "${pkg_size}" >> "$dest_path/$temp_extractsize";
echo ls $source_path \| tar $tar_option "$dest_path/$package_name" -C "$source_path" -T /dev/stdin;
ls $source_path | tar $tar_option "$dest_path/$package_name" -C "$source_path" -T /dev/stdin
}
pkg_get_spk_name ()
{
__get_spk_name pkg_get_spk_platform $@
}
pkg_make_spk ()
{
local pack="tar cf";
local source_path=$1;
local dest_path=$2;
local info_path="$source_path/INFO";
local spk_name=$3;
local spk_arch=;
local temp_extractsize="extractsize_tmp";
if [ -z "$source_path" -o ! -d "$source_path" ]; then
pkg_warn "pkg_make_spk: bad parameters, please set source dir";
return 1;
fi;
if [ -z "$dest_path" -o ! -d "$dest_path" ]; then
pkg_warn "pkg_make_spk: bad parameters, please set destination dir";
return 1;
fi;
if [ ! -r "$info_path" ]; then
pkg_warn "pkg_make_spk: INFO '$info_path' is not existed";
return 1;
fi;
spk_name=${3:-`pkg_get_spk_name $info_path`};
pkg_size=`cat $source_path/$temp_extractsize`;
echo "extractsize=\"${pkg_size}\"" >> $info_path;
rm "$source_path/$temp_extractsize";
echo "toolkit_version=\"$DSM_BUILD_NUM\"" >> $info_path;
echo "create_time=\"$(date +%Y%m%d-%T)\"" >> $info_path;
pkg_log "creating package: $spk_name";
pkg_log "source: $source_path";
pkg_log "destination: $dest_path/$spk_name";
$pack "$dest_path/$spk_name" -C "$source_path" $(ls $source_path)
}
pkg_get_unified_platform ()
{
local plat=$(pkg_get_platform "$1") || return 1;
plat_to_unified_plat "$plat"
}
pkg_get_spk_unified_platform ()
{
local plat=$(pkg_get_platform "$1") || return 1;
local spk_unified_platform=;
case "$plat" in
88f6281)
spk_unified_platform="88f628x"
;;
x86 | bromolow | cedarview | avoton)
spk_unified_platform="x64"
;;
alpine)
spk_unified_platform="alpine"
;;
*)
spk_unified_platform="$plat"
;;
esac;
echo "$spk_unified_platform"
}
pkg_get_spk_unified_name ()
{
__get_spk_name pkg_get_spk_unified_platform $@
}
__get_spk_name() { #<info path>
local spk_name=
local platform_func="$1"
local info_path="${2:-$PKG_DIR/INFO}"
local package_name="$3"
. $info_path
# construct package name
if [ -z "$package" -o -z "$arch" -o -z "$version" ]; then
pkg_warn "pkg_make_spk: package, arch, version can not be empty"
return 1
fi
if [ "x$arch" = "xnoarch" ]; then
spk_arch="noarch"
elif ! spk_arch=$($platform_func); then
spk_arch="none"
fi
if [ "x$arch" = "xnoarch" ]; then
spk_arch=""
else
spk_arch="-"$spk_arch
fi
if [ -z "$package_name" ]; then
package_name="$package";
fi
if [ "${NOSTRIP}" == NOSTRIP ]; then
spk_name="$package_name$spk_arch-${version}_debug.spk"
else
spk_name="$package_name$spk_arch-$version.spk"
fi
echo $spk_name;
}
pkg_get_dsm_buildnum() { # [path of VERSION (default: )]
local version_file=${1:-/source/lnxsdk/init/etc/VERSION}
local dsm_build=
if [ ! -r "$version_file" ]; then
pkg_warn "pkg_get_dsm_buildnum: can not find version file '$version_file'"
pkg_warn "use default buildnum: 0"
echo 0
return 1
fi
if ! dsm_build=$(grep -s ^buildnumber "$version_file" | awk -F \" '{print $2}'); then
echo 0
return 1
fi
echo $(($dsm_build))
}
pkg_get_tar_option() {
local version_file="/PkgVersion"
if [ -r $version_file ] && [ "$(pkg_get_dsm_buildnum $version_file)" -ge 5943 ]; then
echo "cJf"
else
echo "czf"
fi
}
[ "$(caller)" != "0 NULL" ] && return 0
Usage() {
cat >&2 << EOF
Usage
$(basename $0) <action> [action options...]
Action
make_spk <source path> <dest path>
make_package <source path> <dest path>
EOF
exit 0
}
[ $# -eq 0 ] && Usage
PkgBuildAction=$1 ; shift
case "$PkgBuildAction" in
make_spk) pkg_make_spk "$@" ;;
make_package) pkg_make_package "$@" ;;
*) Usage ;;
esac

View file

@ -0,0 +1,33 @@
#!/bin/sh
# Get the last tag
TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" 2>/dev/null)
# Did getting the tag succeed?
if [ $? != 0 ] || [ -z "$TAG" ]; then
printf -- "unknown"
exit 0
fi
# Get the current branch
BRANCH=$(git symbolic-ref -q HEAD --short 2>/dev/null)
# Did getting the branch succeed?
if [ $? != 0 ] || [ -z "$BRANCH" ]; then
BRANCH="master"
fi
#replace last dot with -
STAG=$(echo $TAG | sed 's/v//' | sed 's/[^0123456789.].//' | sed 's/\.\([^.]*\)$/-\1/')
#get tail after - and do padding with 4 zeros
TAG_TAIL=$(echo $STAG | sed -n -e 's/^.*-//p' | sed -e :a -e 's/^.\{1,3\}$/&0/;ta')
#replace tail after -
SYNO_VERSION=$(echo $STAG | sed "s/-.*/-$TAG_TAIL/")
case "$*" in
*--bare*)
printf '%s\n' "$SYNO_VERSION"
;;
*)
printf '%s' "$SYNO_VERSION"
;;
esac