-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add simple package management for nodes with binary dependencies (#170)
- Loading branch information
1 parent
1d60ff9
commit 6532f1f
Showing
9 changed files
with
311 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/sh | ||
|
||
ADDON_DIR=/usr/local/addons/redmatic | ||
REPO=$ADDON_DIR/lib/pkg-repo.json | ||
|
||
source $ADDON_DIR/home/.profile | ||
|
||
function usage() | ||
{ | ||
echo "Usage: redmatic-pkg <command> <package>" | ||
echo "commands:" | ||
echo " install" | ||
echo " remove" | ||
echo "" | ||
} | ||
|
||
function install() | ||
{ | ||
PACKAGE="$1" | ||
URL=`jq -r ".\"$PACKAGE\".resolved" $REPO` | ||
INTEGRITY=`jq -r ".\"$PACKAGE\".integrity" $REPO` | ||
VERSION=`jq -r ".\"$PACKAGE\".version" $REPO` | ||
|
||
if [ $URL == "null" ]; then | ||
echo "unknown package: $1" | ||
exit 1 | ||
fi | ||
|
||
echo "Get $URL" | ||
curl $URL -o $ADDON_DIR/tmp/$1.tar.gz --fail --silent --show-error --location || exit 1 | ||
|
||
rm -r $ADDON_DIR/lib/node_modules/$PACKAGE 2> /dev/null | ||
|
||
echo "Extracting $1.tar.gz" | ||
(cd $ADDON_DIR ; tar --no-same-owner -xzf tmp/$1.tar.gz && rm tmp/$1.tar.gz && echo "Done.") | ||
} | ||
|
||
function remove() | ||
{ | ||
PACKAGE="$1" | ||
rm -r $ADDON_DIR/lib/node_modules/$PACKAGE 2> /dev/null | ||
echo "Done." | ||
} | ||
|
||
|
||
case $1 in | ||
i | install) | ||
install $2 | ||
exit | ||
;; | ||
r | remove) | ||
remove $2 | ||
exit | ||
;; | ||
*) | ||
usage | ||
exit 1 | ||
;; | ||
esac | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"node-red-node-serialport": { | ||
"integrity": "sha512-NGTeA2zl9H9agWHDQAjxLQfNuyRhKjBcBLdY6xt9/7HM1sHiMzy/5fnX1ZjGNfyYpNrbBnftPqJKLiaTuSQQrw==", | ||
"resolved": "https://github.com/rdmtc/RedMatic/releases/download/v3.3.2/redmatic-pkg-node-red-node-serialport-0.7.1.tar.gz", | ||
"version": "0.7.1" | ||
}, | ||
"node-red-node-sqlite": { | ||
"integrity": "sha512-oufmJNdYH7nvLO54FtnpHySWIxnXmnsB7+sj6swqSZqxxyeFLjvaX0VLKDf6CqDWUoT+2tQ8ZwzWdRXemZfJ7w==", | ||
"resolved": "https://github.com/rdmtc/RedMatic/releases/download/v3.3.2/redmatic-pkg-node-red-node-sqlite-0.3.6.tar.gz", | ||
"version": "0.3.6" | ||
}, | ||
"node-red-contrib-smartmeter": { | ||
"integrity": "sha512-z4XUte5D0T6fYd2Waa53gEJgVOn63LXPpYY2CKDQ7zLoRcX7uxe9BxpHVQLujIVk++1dCTeyW6L8B+ftE5LSVQ==", | ||
"resolved": "https://github.com/rdmtc/RedMatic/releases/download/v3.3.2/redmatic-pkg-node-red-contrib-smartmeter-0.2.0.tar.gz", | ||
"version": "0.2.0" | ||
}, | ||
"node-red-contrib-modbus": { | ||
"integrity": "sha512-nRU3i+3COOCblviVqDO+FU44HALECihz4mt6K1rzhrWz0pzY18PN4cmVtezU02lVV1x32wmMNeQoQ88uvNncDg==", | ||
"resolved": "https://github.com/rdmtc/RedMatic/releases/download/v3.3.2/redmatic-pkg-node-red-contrib-modbus-4.1.3.tar.gz", | ||
"version": "4.1.3" | ||
}, | ||
"node-red-contrib-mysensors": { | ||
"integrity": "sha512-4fY9TO5aDtafcQDakbWG0WPkT3KlDs0QCG6GaHZdZRmKdfFWR/k6jXcqWVaM7t0paqhl4AVDet4qdtdBME1ZVA==", | ||
"resolved": "https://github.com/rdmtc/RedMatic/releases/download/v3.3.2/redmatic-pkg-node-red-contrib-mysensors-3.3.0.tar.gz", | ||
"version": "3.3.0" | ||
}, | ||
"node-red-contrib-rfxcom": { | ||
"integrity": "sha512-ewgyopSGtXJunxFdaI6egs6zAJtR3BUQ25/Oi2Hzh99NLCNSza+pnTElbchew+/G0NYkpS5keF2xhzyki5qw7A==", | ||
"resolved": "https://github.com/rdmtc/RedMatic/releases/download/v3.3.2/redmatic-pkg-node-red-contrib-rfxcom-2.8.1.tar.gz", | ||
"version": "2.8.1" | ||
}, | ||
"redmatic-homekit": { | ||
"integrity": "sha512-8ZXMcreZVabftjuV0FpXKFFPl92kfQzPhptGlNhvHWPYNrQB16FHjorsaa/9I/ARIsqmZ5SEYWqc84eJpYhq/g==", | ||
"resolved": "https://github.com/rdmtc/RedMatic/releases/download/v3.3.2/redmatic-pkg-redmatic-homekit-2.1.0.tar.gz", | ||
"version": "2.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/bin/tclsh | ||
|
||
source ../lib/querystring.tcl | ||
source ../lib/session.tcl | ||
|
||
|
||
if {[info exists sid] && [check_session $sid]} { | ||
if {[info exists cmd]} { | ||
switch -glob $cmd { | ||
"repo" { | ||
puts -nonewline "Content-Type: text/json; charset=utf-8\r\n\r\n" | ||
puts [exec cat /usr/local/addons/redmatic/lib/pkg-repo.json] | ||
} | ||
"ls" { | ||
puts -nonewline "Content-Type: text/plain; charset=utf-8\r\n\r\n" | ||
puts [exec ls -1 /usr/local/addons/redmatic/lib/node_modules] | ||
} | ||
"install" { | ||
puts -nonewline "Content-Type: text/plain; charset=utf-8\r\n\r\n" | ||
if {[info exists package]} { | ||
puts [exec /usr/local/addons/redmatic/bin/redmatic-pkg install $package] | ||
} else { | ||
puts "param package missing" | ||
} | ||
} | ||
"remove" { | ||
puts -nonewline "Content-Type: text/plain; charset=utf-8\r\n\r\n" | ||
if {[info exists package]} { | ||
puts [exec /usr/local/addons/redmatic/bin/redmatic-pkg remove $package] | ||
} else { | ||
puts "param package missing" | ||
} | ||
} | ||
default { | ||
puts -nonewline "Content-Type: text/plain; charset=utf-8\r\n\r\n" | ||
puts "unknown command $cmd" | ||
} | ||
} | ||
} else { | ||
puts -nonewline "Content-Type: text/plain; charset=utf-8\r\n\r\n" | ||
puts "param cmd missing" | ||
} | ||
|
||
} else { | ||
puts -nonewline "Content-Type: text/plain; charset=utf-8\r\n\r\n" | ||
puts "error: invalid session" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const fs = require('fs'); | ||
const cp = require('child_process'); | ||
var crypto = require('crypto'); | ||
const pkgLib = require(__dirname + '/addon_files/redmatic/lib/package.json'); | ||
const redmaticVersion = require(__dirname + '/package.json').version; | ||
|
||
const blacklist = [ | ||
'node-red', | ||
'npm', | ||
'ain2' | ||
]; | ||
|
||
const extraFiles = { | ||
'redmatic-homekit': [ | ||
'bin/ffmpeg' | ||
] | ||
}; | ||
|
||
const remove = []; | ||
const repo = {}; | ||
|
||
Object.keys(pkgLib.dependencies).forEach(name => { | ||
if (blacklist.includes(name)) { | ||
return; | ||
} | ||
const version = pkgLib.dependencies[name] | ||
const filename = 'redmatic-pkg-' + name + '-' + version + '.tar.gz'; | ||
|
||
let cmd = 'tar -C ' + __dirname + '/addon_tmp/redmatic/ -czf ' + __dirname + '/dist/' + filename + ' lib/node_modules/' + name; | ||
remove.push(__dirname + '/addon_tmp/redmatic/lib/node_modules/' + name); | ||
if (extraFiles[name]) { | ||
extraFiles[name].forEach(file => { | ||
cmd += ' ' + file; | ||
remove.push(__dirname + '/addon_tmp/redmatic/' + file); | ||
}); | ||
} | ||
console.log(cmd); | ||
cp.execSync(cmd); | ||
|
||
repo[name] = { | ||
integrity: checksum(fs.readFileSync(__dirname + '/dist/' + filename)), | ||
resolved: 'https://github.com/rdmtc/RedMatic/releases/download/v' + redmaticVersion + '/' + filename, | ||
version | ||
}; | ||
|
||
}); | ||
|
||
fs.writeFileSync(__dirname + '/addon_tmp/redmatic/lib/pkg-repo.json', JSON.stringify(repo, null, ' ')); | ||
|
||
remove.forEach(path => { | ||
console.log('remove', path); | ||
if (fs.statSync(path).isDirectory()) { | ||
cp.execSync('rm -r ' + path); | ||
} else { | ||
fs.unlinkSync(path); | ||
} | ||
}); | ||
|
||
function checksum(input) { | ||
var hash = crypto.createHash('sha512').update(input, 'utf8'); | ||
var hashBase64 = hash.digest('base64'); | ||
return 'sha512-' + hashBase64; | ||
} |