diff options
author | robocoder <anthon.pang@gmail.com> | 2012-07-28 23:11:32 +0400 |
---|---|---|
committer | robocoder <anthon.pang@gmail.com> | 2012-07-28 23:11:32 +0400 |
commit | 979a0198cb7175aac7445520bbcd449b730c856a (patch) | |
tree | 6ac609be4181aeadb029e204fd3cae681727df7a /misc/package | |
parent | c461e4edaee23ec738d908df06f606dc721f6a7f (diff) |
fixes #3278
git-svn-id: http://dev.piwik.org/svn/trunk@6583 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'misc/package')
-rw-r--r-- | misc/package/ASUStor/Piwik/CONTROL/icon-disable.png | bin | 0 -> 4227 bytes | |||
-rw-r--r-- | misc/package/ASUStor/Piwik/CONTROL/icon-enable.png | bin | 0 -> 4713 bytes | |||
-rw-r--r-- | misc/package/ASUStor/apkg_build | 441 | ||||
-rw-r--r-- | misc/package/ASUStor/build.sh | 10 | ||||
-rw-r--r-- | misc/package/ASUStor/config.json.tpl | 20 | ||||
-rw-r--r-- | misc/package/ASUStor/jsongrep.py | 37 |
6 files changed, 508 insertions, 0 deletions
diff --git a/misc/package/ASUStor/Piwik/CONTROL/icon-disable.png b/misc/package/ASUStor/Piwik/CONTROL/icon-disable.png Binary files differnew file mode 100644 index 0000000000..e0ce2c1a68 --- /dev/null +++ b/misc/package/ASUStor/Piwik/CONTROL/icon-disable.png diff --git a/misc/package/ASUStor/Piwik/CONTROL/icon-enable.png b/misc/package/ASUStor/Piwik/CONTROL/icon-enable.png Binary files differnew file mode 100644 index 0000000000..4c06045b1d --- /dev/null +++ b/misc/package/ASUStor/Piwik/CONTROL/icon-enable.png diff --git a/misc/package/ASUStor/apkg_build b/misc/package/ASUStor/apkg_build new file mode 100644 index 0000000000..ffb5e9a582 --- /dev/null +++ b/misc/package/ASUStor/apkg_build @@ -0,0 +1,441 @@ +#!/bin/sh + +# pkg-build -- construct a debian file format .apk from a directory +# Walker Lee <walkerlee@asustor.com> +# based on a script by Steve Redler IV, steve@sr-tech.com 5-21-2001 + +set -e + +TMP_DIR="/tmp" +THIS_DIR=`pwd` +SCRIPT_PATH=`readlink -f $0` +SCRIPT_DIR=`dirname ${SCRIPT_PATH}` + +JSON_GREP="$SCRIPT_DIR/jsongrep.py" + +PKG_BUILD_PROGRAM=`basename $0` +#PKG_BUILD_PROGRAM="apkg-build" +PKG_BUILD_VER="1.0" +PKG_BUILD_FORMAT="zip" # ar, tar, zip + +PKG_CONTROL_DIR="CONTROL" +PKG_WEBMAN_DIR="webman" +PKG_WEB_DIR="www" + +PKG_WEB_USER="admin" +PKG_WEB_GROUP="administrators" + +PKG_WEB_USER_ID=999 +PKG_WEB_GROUP_ID=999 + +PKG_WEB_PERM=770 + +PKG_DIR_PERM=755 +PKG_FILE_PERM=644 + +PKG_VERSION_FILE="apkg-version" +PKG_DATA_FILE="data.tar.gz" +PKG_CONTROL_FILE="control.tar.gz" + +PKG_CONFIG_FILE="config.json" +PKG_ICON_ENABLE_FILE="icon-enable.png" +PKG_ICON_DISABLE_FILE="icon-disable.png" + +PKG_PRE_INSTALL_SCRIPT="pre-install.sh" +PKG_PRE_UNINSTALL_SCRIPT="pre-uninstall.sh" + +PKG_POST_INSTALL_SCRIPT="post-install.sh" +PKG_POST_UNINSTALL_SCRIPT="post-uninstall.sh" + +PKG_START_STOP_SCRIPT="start-stop.sh" + +PKG_SCRIPT_LIST="$PKG_PRE_INSTALL_SCRIPT $PKG_PRE_UNINSTALL_SCRIPT \ + $PKG_POST_INSTALL_SCRIPT $PKG_POST_UNINSTALL_SCRIPT \ + $PKG_START_STOP_SCRIPT" + +PKG_SRC_DIR=$1 +PKG_DEST_DIR=$2 +PKG_TMP_DIR=$TMP_DIR/APKG_BUILD.$$ + +PKG_SUFFIX="apk" + + +pkg_struct_check() { + local owd=`pwd` + local error=0 + + # check pkg base dir + if [ ! -d $PKG_SRC_DIR ]; then + echo " *** Error: Directory $PKG_SRC_DIR does not exist" >&2 + return 1 + fi + + cd $PKG_SRC_DIR + + # check pkg control dir + if [ ! -d "$PKG_CONTROL_DIR" ]; then + echo " *** Error: Directory $PKG_SRC_DIR has no $PKG_CONTROL_DIR subdirectory." >&2 + error=1 + fi + + # check pkg config file + if [ ! -f "$PKG_CONTROL_DIR/$PKG_CONFIG_FILE" ]; then + echo " *** Error: Package config file $PKG_SRC_DIR/$PKG_CONTROL_DIR/$PKG_CONFIG_FILE not found." >&2 + error=1 + fi + + # TODO: check pkg config file is utf8 format + + # check enable pkg icon file + if [ ! -f "$PKG_CONTROL_DIR/$PKG_ICON_ENABLE_FILE" ]; then + echo " *** Error: Package enable icon file $PKG_SRC_DIR/$PKG_CONTROL_DIR/$PKG_ICON_ENABLE_FILE not found." >&2 + error=1 + fi + + # check disable pkg icon file + if [ ! -f "$PKG_CONTROL_DIR/$PKG_ICON_DISABLE_FILE" ]; then + echo " *** Error: Package disable icon file $PKG_SRC_DIR/$PKG_CONTROL_DIR/$PKG_ICON_DISABLE_FILE not found." >&2 + error=1 + fi + + cd $owd + + return $error +} + +required_field() { + field=$1 + + raw_value=`$JSON_GREP app $field < $PKG_CONTROL_DIR/$PKG_CONFIG_FILE` + value=`expr "$raw_value" : '..\(.*\).'` + if [ -z "$value" ]; then + echo " *** Error: $PKG_CONTROL_DIR/$PKG_CONFIG_FILE is missing field $field" >&2 + return 1 + fi + echo $value + return 0 +} + +pkg_config_check() { + local owd=`pwd` + local error=0 + + cd $PKG_SRC_DIR + + PKG_FIELD_PACKAGE=`required_field package` + [ "$?" -ne 0 ] && error=1 + + PKG_FIELD_NAME=`required_field name` + [ "$?" -ne 0 ] && error=1 + + PKG_FIELD_VERSION=`required_field version` + [ "$?" -ne 0 ] && error=1 + + PKG_FIELD_SECTION=`required_field section` +# [ "$?" -ne 0 ] && error=1 + + PKG_FIELD_VISIBILITY=`required_field visibility` + [ "$?" -ne 0 ] && error=1 + + PKG_FIELD_PRIORITY=`required_field priority` + [ "$?" -ne 0 ] && error=1 + + PKG_FIELD_MAINTAINER=`required_field maintainer` + [ "$?" -ne 0 ] && error=1 + + PKG_FIELD_EMAIL=`required_field email` +# [ "$?" -ne 0 ] && error=1 + + PKG_FIELD_WEBSITE=`required_field website` +# [ "$?" -ne 0 ] && error=1 + + PKG_FIELD_ARCHITECTURE=`required_field architecture` + [ "$?" -ne 0 ] && error=1 + + PKG_FIELD_FIRMWARE=`required_field firmware` + [ "$?" -ne 0 ] && error=1 + + PKG_FIELD_DESCRIPTION=`required_field description` + [ "$?" -ne 0 ] && error=1 + + PKG_FIELD_CHANGES=`required_field changes` +# [ "$?" -ne 0 ] && error=1 + +# PKG_FIELD_TAGS=`required_field tags` +# [ "$?" -ne 0 ] && error=1 + + if echo $PKG_FIELD_PACKAGE | grep '[^a-z0-9.+-]' > /dev/null 2>&1; then + if [ $error -eq 1 ]; then + echo >&2 + fi + echo " *** Error: Package name $PKG_FIELD_PACKAGE contains illegal characters, (other than [a-z0-9.+-])" >&2 + error=1 + fi + +# if [ -z "$PKG_FIELD_SECTION" ]; then +# if [ $error -eq 1 ]; then +# echo >&2 +# fi +# echo " The Section field should have one of the following values:" >&2 +# echo " admin, base, comm, editors, extras, games, graphics, kernel, libs, misc, net, text, web, x11" >&2 +# fi + + if [ -z "$PKG_FIELD_PRIORITY" ]; then + if [ $error -eq 1 ]; then + echo >&2 + fi + echo " The Priority field should have one of the following values:" >&2 + echo " required, important, standard, optional, extra" >&2 + echo " If you don't know which priority value you should be using, then use \`optional'" >&2 + + fi + + cd $owd + + return $error +} + +pkg_script_check() { + local owd=`pwd` + local error=0 + + cd $PKG_SRC_DIR + + for script_file in $PKG_SCRIPT_LIST; do + if [ -f $PKG_CONTROL_DIR/$script_file -a ! -x $PKG_CONTROL_DIR/$script_file ]; then + echo " *** Error: package script $PKG_CONTROL_DIR/$script_file is not executable" >&2 + error=1 + fi + done + + cd $owd + + return $error +} + +pkg_misc_check() { + local owd=`pwd` + local error=0 + + cd $PKG_SRC_DIR + + tilde_files=`find . -name '*~'` + if [ -n "$tilde_files" ]; then + echo "*** Warning: The following files have names ending in '~'. +You probably want to remove them: " >&2 + ls -ld $tilde_files + echo >&2 + fi + + swap_files=`find . -name '*.swp'` + if [ -n "$swap_files" ]; then + echo "*** Warning: The following files have names ending in '.swp'. +You probably want to remove them: " >&2 + ls -ld $swap_files + echo >&2 + fi + + svn_files=`find . -name '.svn'` + if [ -n "$svn_files" ]; then + echo "*** Warning: The following files have names ending in '.svn'. +You probably want to remove them: " >&2 + ls -ld $svn_files + echo >&2 + fi + + git_files=`find . -name '*.git'` + if [ -n "$git_files" ]; then + echo "*** Warning: The following files have names ending in '.git'. +You probably want to remove them: " >&2 + ls -ld $git_files + echo >&2 + fi + + cvs_files=`find . -name '*.cvs'` + if [ -n "$cvs_files" ]; then + echo "*** Warning: The following files have names ending in '.cvs'. +You probably want to remove them: " >&2 + ls -ld $cvs_files + echo >&2 + fi + +# maybe check SUID & GUID file + +# large_uid_files=`find . -uid +99` +# if [ -n "$large_uid_files" ]; then +# echo "*** Warning: The following files have a UID greater than 99. +#You probably want to chown these to a system user: " >&2 +# ls -ld $large_uid_files +# echo >&2 +# fi + + cd $owd + + return $error +} + +### +# apkg-build "main" +### + +# set pkg dest dir +case $# in +1) + PKG_SRC_DIR=`readlink -f $PKG_SRC_DIR` + PKG_DEST_DIR=$THIS_DIR + ;; +2) + PKG_SRC_DIR=`readlink -f $PKG_SRC_DIR` + PKG_DEST_DIR=`readlink -f $PKG_DEST_DIR` + ;; +*) + echo "Usage: $PKG_BUILD_PROGRAM <pkg_directory> [<destination_directory>]" >&2 + exit 1 + ;; +esac + +if [ $PKG_SRC_DIR = $PKG_DEST_DIR ]; then + echo "*** Error: Can't not build pkg in the same directory" >&2 + echo " pkg_directory: $PKG_SRC_DIR" >&2 + echo " destination_directory: $PKG_DEST_DIR" >&2 + exit 1 +fi + +# check pkg package folder structure +echo "Check package folder structure..." +if ! pkg_struct_check; then + echo >&2 + echo "$PKG_BUILD_PROGRAM: Please fix the above errors and try again." >&2 + exit 1 +fi +echo "Done" + +echo + +# check pkg config +echo "Check package config information..." +if ! pkg_config_check; then + echo >&2 + echo "$PKG_BUILD_PROGRAM: Please fix the above errors and try again." >&2 + exit 1 +fi +echo "Done" + +echo + +# check pkg script +echo "Check package script file..." +if ! pkg_script_check; then + echo >&2 + echo "$PKG_BUILD_PROGRAM: Please fix the above errors and try again." >&2 + exit 1 +fi +echo "Done" + +echo + +# check pkg misc +echo "Check package misc..." +if ! pkg_misc_check; then + echo >&2 + echo "$PKG_BUILD_PROGRAM: Please fix the above errors and try again." >&2 + exit 1 +fi +echo "Done" + +echo + +# archive pkg control script +mkdir -p $PKG_TMP_DIR + +# force chown user:group to web folder +if [ -d $PKG_SRC_DIR/$PKG_WEB_DIR ]; then + echo -n "Force change $PKG_SRC_DIR/$PKG_WEB_DIR/* owner and group to $PKG_WEB_USER:$PKG_WEB_GROUP ... " + if [ `ls -la $PKG_SRC_DIR/$PKG_WEB_DIR | wc -l` -gt 3 ]; then + # change owner + chown $PKG_WEB_USER_ID:$PKG_WEB_GROUP_ID $PKG_SRC_DIR/$PKG_WEB_DIR -R + # TODO change file permission + # chmod $PKG_WEB_PERM $PKG_SRC_DIR/$PKG_WEB_DIR -R + fi + echo "Done" + + echo +fi + +echo -n "Archive package data..." +tar -C $PKG_SRC_DIR -czf $PKG_TMP_DIR/$PKG_DATA_FILE . --exclude=$PKG_CONTROL_DIR +echo "Done" + +echo + +# archive pkg data +echo -n "Archive package control script..." +tar -C $PKG_SRC_DIR/$PKG_CONTROL_DIR -czf $PKG_TMP_DIR/$PKG_CONTROL_FILE . +echo "Done" + +echo + +# generate pkg version +echo -n "Generate $PKG_VERSION_FILE..." +echo $PKG_BUILD_VER > $PKG_TMP_DIR/$PKG_VERSION_FILE +echo "Done" + +echo + +# prepare pkg filename +PKG_ARCHIVE_FILE=${PKG_FIELD_PACKAGE}_${PKG_FIELD_VERSION}_${PKG_FIELD_ARCHITECTURE}.$PKG_SUFFIX + +# use which type archive +echo "Use $PKG_BUILD_FORMAT format to archive $PKG_ARCHIVE_FILE..." +cd $PKG_TMP_DIR + +PKG_ARCHIVE_LIST="./$PKG_VERSION_FILE ./$PKG_DATA_FILE ./$PKG_CONTROL_FILE" + +rm -rf $TMP_DIR/$PKG_ARCHIVE_FILE + +if [ "$PKG_BUILD_FORMAT" = "ar" ] ; then + ar -crvf $TMP_DIR/$PKG_ARCHIVE_FILE $PKG_ARCHIVE_LIST +elif [ "$PKG_BUILD_FORMAT" = "tar" ] ; then + tar -zcvf $TMP_DIR/$PKG_ARCHIVE_FILE $PKG_ARCHIVE_LIST +elif [ "$PKG_BUILD_FORMAT" = "zip" ] ; then + zip -r $TMP_DIR/$PKG_ARCHIVE_FILE $PKG_ARCHIVE_LIST +fi +echo "Done" + +PKG_SIZE=`ls -l $TMP_DIR/$PKG_ARCHIVE_FILE | awk '{print $5}'` +PKG_MD5=`md5sum $TMP_DIR/$PKG_ARCHIVE_FILE | cut -d' ' -f1` +PKG_SHA1=`sha1sum $TMP_DIR/$PKG_ARCHIVE_FILE | cut -d' ' -f1` + +# move pkg to dest dir +[ "$PKG_DEST_DIR" != "$TMP_DIR" ] && mkdir -p $PKG_DEST_DIR && mv $TMP_DIR/$PKG_ARCHIVE_FILE $PKG_DEST_DIR + +echo + +# clean up +echo -n "Clean building data..." +rm -f $PKG_TMP_DIR/$PKG_VERSION_FILE $PKG_TMP_DIR/$PKG_DATA_FILE $PKG_TMP_DIR/$PKG_CONTROL_FILE +rmdir $PKG_TMP_DIR +echo "Done" + +echo + +echo "Package Summary" +echo " Source: $PKG_SRC_DIR" +echo " Destination: $PKG_DEST_DIR" +echo " Package: $PKG_FIELD_PACKAGE" +echo " Name: $PKG_FIELD_NAME" +echo " Version: $PKG_FIELD_VERSION" +echo " Section: $PKG_FIELD_SECTION" +echo " Visibility: $PKG_FIELD_VISIBILITY" +echo " Priority: $PKG_FIELD_PRIORITY" +echo " Maintainer: $PKG_FIELD_MAINTAINER" +echo " Email: $PKG_FIELD_EMAIL" +echo " WebSite: $PKG_FIELD_WEBSITE" +echo " Architecture: $PKG_FIELD_ARCHITECTURE" +echo " Firmware: $PKG_FIELD_FIRMWARE" +echo " Description: $PKG_FIELD_DESCRIPTION" +echo " Changes: $PKG_FIELD_CHANGES" +echo " File: $PKG_ARCHIVE_FILE" +echo " Size: $PKG_SIZE" +echo " MD5sum: $PKG_MD5" +echo " SHA1sum: $PKG_SHA1" diff --git a/misc/package/ASUStor/build.sh b/misc/package/ASUStor/build.sh new file mode 100644 index 0000000000..bf3d909d97 --- /dev/null +++ b/misc/package/ASUStor/build.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +LATEST=`curl -s http://api.piwik.org/1.0/getLatestVersion/` +curl -s http://builds.piwik.org/piwik-$LATEST.tar.gz | gunzip | tar xf - +mv piwik Piwik/www + +sed "s/{{VERSION}}/$LATEST/" <config.json.tpl >Piwik/CONTROL/config.json +cp ../../gpl-3.0.txt Piwik/CONTROL/license.txt + +sh apkg_build Piwik diff --git a/misc/package/ASUStor/config.json.tpl b/misc/package/ASUStor/config.json.tpl new file mode 100644 index 0000000000..c887f1967a --- /dev/null +++ b/misc/package/ASUStor/config.json.tpl @@ -0,0 +1,20 @@ +{ + "app": { + "package": "piwik", + "name": "Piwik", + "version": "{{VERSION}}", + "visibility": true, + "priority": "optional", + "depends": [], + "conflicts": [], + "suggests": [], + "maintainer": "Piwik", + "email": "hello@piwik.org", + "website": "http://piwik.org/", + "architecture": "x86-64", + "firmware": "0.6.0", + "description": "Open source, self-hosted web analytics.", + "changes": "http://piwik.org/changelog/", + "tags": ["analytics", "visits", "visitors", "hits"] + } +} diff --git a/misc/package/ASUStor/jsongrep.py b/misc/package/ASUStor/jsongrep.py new file mode 100644 index 0000000000..7b1b4713a0 --- /dev/null +++ b/misc/package/ASUStor/jsongrep.py @@ -0,0 +1,37 @@ +#Original author: Terry Jones (http://blogs.fluidinfo.com/terry/about/) +#Source: http://blogs.fluidinfo.com/terry/2010/11/25/jsongrep-py-python-for-extracting-pieces-of-json-objects/ + +#!/usr/bin/env python + +import sys +import re +import json +from pprint import pprint + +def jsongrep(d, patterns): + try: + pattern = patterns.pop(0) + except IndexError: + pprint(d) + else: + if isinstance(d, dict): + keys = filter(pattern.match, d.keys()) + elif isinstance(d, list): + keys = map(int, + filter(pattern.match, + ['%d' % i for i in range(len(d))])) + else: + if pattern.match(str(d)): + pprint(d) + return + for item in (d[key] for key in keys): + jsongrep(item, patterns[:]) + +if __name__ == '__main__': + try: + j = json.loads(sys.stdin.read()) + except ValueError, e: + print >>sys.stderr, 'Could not load JSON object from stdin.' + sys.exit(1) + + jsongrep(j, map(re.compile, sys.argv[1:])) |