diff --git a/Gruntfile.js b/Gruntfile.js index 210bc36..ff23d61 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -22,6 +22,15 @@ module.exports = function (grunt) { var usbListenerDir = "./usbDriveListener"; var gypCompileCmd = "node-gyp configure build"; var gypCleanCmd = "node-gyp clean"; + var pkgdata = require('./package.json'); + var currentArch = (function() { + if (process.arch == 'ia32') + return 'i386'; + else if (process.arch == 'x64') + return "x86_64"; + else + return "noarch"; + })(); function nodeGypShell(cmd, cwd) { return { @@ -43,6 +52,9 @@ module.exports = function (grunt) { jsonlint: { src: ["gpii/**/*.json"] }, + appFileName: "gpii-linux", + buildDir: "build", + pkgdata: pkgdata, shell: { options: { stdout: true, @@ -79,12 +91,51 @@ module.exports = function (grunt) { "sudo rm -f -r /var/lib/gpii" ].join("&&") }, + prepareRpmEnv: { + command: "dnf install -y nodejs-grunt-cli npm alsa-lib-devel json-glib-devel PackageKit-glib-devel libXrandr-devel libgnome-keyring-devel sudo @development-tools rpmdevtools" + }, + buildRpmDocker: { + command: "docker run --rm -i -v $(pwd):/sync fedora /bin/bash -c 'dnf install -y nodejs-grunt-cli; cp -r /sync /packages; cd /packages; grunt build-rpm; cp -r /packages/bin /sync'" + }, runAcceptanceTests: { command: "vagrant ssh -c 'DISPLAY=:0 node /home/vagrant/sync/tests/AcceptanceTests.js'" }, runUnitTests: { command: "vagrant ssh -c 'cd /home/vagrant/sync/tests/; DISPLAY=:0 ./UnitTests.sh'" } + }, + easy_rpm: { + options: { + release: 1, + summary: pkgdata.description, + rpmDestination: "bin", + tempDir: "bin/tmp", + keepTemp: true, + license: pkgdata.license, + url: pkgdata.homepage, + buildArch: currentArch, + requires: [ + "nodejs >= 0.10.42", + "python-httplib2" + ] + }, + release: { + files: [ + {src: "gpii.js", dest: "/opt/gpii-linux"}, + {src: "index.js", dest: "/opt/gpii-linux"}, + {src: "package.json", dest: "/opt/gpii-linux"}, + {src: "gpii/**/*", dest: "/opt/gpii-linux"}, + {src: "../node_modules/**/*", dest: "/opt/gpii-linux/node_modules"}, + {src: "gpii-linux-autostart.desktop", dest: "/etc/xdg/autostart", cwd: 'build/resources'}, + {src: "gpii-linux-start", dest: "/usr/bin", cwd: 'build/resources'}, + {src: "/var/lib/gpii/log.txt", dest: "/", mode: 666}, + {src: "gpii-usb-user-listener", dest: "/usr/bin", mode: "755", cwd: 'usbDriveListener'}, + {src: "gpii-usb-user-listener.desktop", dest: "/usr/share/applications", cwd: 'usbDriveListener'} + ], + excludeFiles: [ + "../node_modules/**/examples/switch-bench.js" //avoid strange dependency + ] + }, } }); @@ -132,4 +183,14 @@ module.exports = function (grunt) { grunt.task.run("shell:runUnitTests"); grunt.task.run("shell:runAcceptanceTests"); }); + grunt.registerTask("build-rpm-docker", "Build Linux RPM package using a Docker container", function () { + grunt.task.run("shell:buildRpmDocker"); + }); + grunt.registerTask("build-rpm", "Build GPII Linux and RPM package", function () { + grunt.task.run("shell:prepareRpmEnv"); + grunt.task.run("build"); + grunt.task.run("easy_rpm"); + }); + grunt.loadNpmTasks("grunt-easy-rpm"); + grunt.loadTasks('tasks'); }; diff --git a/README.md b/README.md index 2add2ee..d1357f5 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,18 @@ this may prompt you for sudo access. grunt install grunt uninstall +## Building a RPM package + +We use Docker to build the RPM package in a clean environment, this also avoids +to polute your environment. + +To build a RPM package run the following command at the root of the git repository: + + grunt build-rpm-docker + +you will get the rpm package and the source files of the package in the ``bin`` +directory. + # Setting Up a Virtual Machine This repository contains content that will allow you to automatically provision a development VM. A [Vagrantfile](http://docs.vagrantup.com/v2/vagrantfile/) is provided that downloads a [Fedora Vagrant box](https://github.com/idi-ops/packer-fedora), starts a VM, and deploys the GPII Framework on it. diff --git a/build/resources/gpii-linux-autostart.desktop b/build/resources/gpii-linux-autostart.desktop new file mode 100644 index 0000000..154897f --- /dev/null +++ b/build/resources/gpii-linux-autostart.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Application +Name=GPII Linux +Exec=/usr/bin/gpii-linux-start +OnlyShowIn=GNOME; diff --git a/build/resources/gpii-linux-start b/build/resources/gpii-linux-start new file mode 100755 index 0000000..3058793 --- /dev/null +++ b/build/resources/gpii-linux-start @@ -0,0 +1,4 @@ +#!/bin/sh +systemctl --user import-environment +cd /opt/gpii-linux +node gpii.js diff --git a/build/resources/gpii-linux.service b/build/resources/gpii-linux.service new file mode 100644 index 0000000..46f3f34 --- /dev/null +++ b/build/resources/gpii-linux.service @@ -0,0 +1,14 @@ +# Use with Systemd > 219 +[Unit] +Description=Components of the GPII personalization infrastructure for use on Linux +Documentation=http://gpii.net + +[Service] +Type=simple +ExecStart=/usr/bin/gpii-linux-start +WorkingDirectory=/opt/gpii-linux +Restart=on-failure + +[Install] +WantedBy=default.target +