Skip to content

Commit

Permalink
several package manager improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed May 15, 2019
1 parent 4588110 commit b2b6f7c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
19 changes: 13 additions & 6 deletions addon_files/redmatic/bin/redmatic-pkg
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ function usage()
echo ""
}

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

function install()
{
PACKAGE="$1"
Expand All @@ -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
Expand All @@ -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."
Expand Down
15 changes: 10 additions & 5 deletions bundle-pkgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
};

});
Expand All @@ -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.