Skip to content
Permalink
Browse files

several package manager improvements

  • Loading branch information...
hobbyquaker committed May 15, 2019
1 parent 4588110 commit b2b6f7c1c62ea909754baf8f647d78a4c13b9f5c
Showing with 23 additions and 11 deletions.
  1. +13 −6 addon_files/redmatic/bin/redmatic-pkg
  2. +10 −5 bundle-pkgs.js
@@ -17,6 +17,12 @@ function usage()
echo ""
}

function error()
{
echo "Error: $1"
exit 1
}

function install()
{
PACKAGE="$1"
@@ -25,8 +31,8 @@ function install()
VERSION=`jq -r ".\"$PACKAGE\".version" $REPO`

if [ $URL == "null" ]; then
echo "unknown package: $1"
exit 1
echo "Error: unknown package: $1"
exit 1
fi

if [ -f $ADDON_DIR/lib/node_modules/$PACKAGE/package.json ]; then
@@ -42,24 +48,25 @@ function install()
echo "Get $URL"
set -o pipefail
T_START=$(date +"%s")
/usr/bin/curl $URL -o $ADDON_DIR/tmp/$1.tar.gz --fail --show-error --silent --location || exit 1
/usr/bin/curl $URL -o $ADDON_DIR/tmp/$1.tar.gz --fail --show-error --silent --location 2>&1 || error "Install failed."
T_END=$(date +"%s")
echo "Downloaded $(stat -c %s $ADDON_DIR/tmp/$1.tar.gz | awk '{ suffix="KMGT"; for(i=0; $1>1024 && i < length(suffix); i++) $1/=1024; print int($1) substr(suffix, i, 1), $3; }')in $(( T_END-T_START )) seconds"

D_INTEGRITY=sha512-$(cat $ADDON_DIR/tmp/$1.tar.gz | /usr/bin/openssl sha512 -binary | base64 | tr -d \\n)

if [ "$INTEGRITY" == "$D_INTEGRITY" ]; then
echo "File integrity check successful"
else
echo "File integrity check failed"
echo " Expected $INTEGRITY"
echo " Got $D_INTEGRITY"
rm $ADDON_DIR/tmp/$1.tar.gz
exit 1
error "Install failed."
fi

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) || exit 1
(cd $ADDON_DIR ; tar --no-same-owner -xzf tmp/$1.tar.gz) || error "Install failed."

rm $ADDON_DIR/tmp/$1.tar.gz
echo "Done."
@@ -31,7 +31,9 @@ Object.keys(pkgLib.dependencies).forEach(name => {
if (blacklist.includes(name)) {
return;
}
const version = pkgLib.dependencies[name]
const pkgJson = require(__dirname + '/addon_tmp/redmatic/lib/node_modules/' + name + '/package.json');
const {version, description, keywords, homepage, repository} = pkgJson;

const filename = 'redmatic-pkg-' + name + '-' + version + '.tar.gz';

let cmd = 'tar -C ' + __dirname + '/addon_tmp/redmatic/ -czf ' + __dirname + '/dist/' + filename + ' lib/node_modules/' + name;
@@ -48,7 +50,11 @@ Object.keys(pkgLib.dependencies).forEach(name => {
repo[name] = {
integrity: checksum(fs.readFileSync(__dirname + '/dist/' + filename)),
resolved: 'https://github.com/rdmtc/RedMatic/releases/download/v' + redmaticVersion + '/' + filename,
version
version,
description,
keywords,
homepage,
repository
};

});
@@ -65,7 +71,6 @@ remove.forEach(path => {
});

function checksum(input) {
var hash = crypto.createHash('sha512').update(input, 'utf8');
var hashBase64 = hash.digest('base64');
return 'sha512-' + hashBase64;
const hash = crypto.createHash('sha512').update(input, 'utf8');
return 'sha512-' + hash.digest('base64');
}

0 comments on commit b2b6f7c

Please sign in to comment.
You can’t perform that action at this time.