Created
July 23, 2018 14:26
-
-
Save joe-dempsey/db36541da00f27f06dcbb4f2c5b0c1b4 to your computer and use it in GitHub Desktop.
Bitcoin Mining Hardware Shopify
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
#!/bin/bash | |
set -e | |
set -o pipefail | |
log_title() { | |
local code="\033[" | |
local color="${code}1;34m" | |
[ -z "$text" ] && local text="$color$1${code}0m" | |
echo -e "\n$text" | |
} | |
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." | |
package_arch="amd64" | |
package_version=$(jq -r ".version" "${root_dir}/package.json") | |
package_maintainer=$(jq -r ".author" "${root_dir}/package.json") | |
package_description=$(jq -r ".description" "${root_dir}/package.json") | |
deb_dir="${root_dir}/build/bitcore_${package_version}_${package_arch}" | |
log_title "Making Debian package:\n" | |
echo -e " Name: bitcore" | |
echo -e " Version: ${package_version}" | |
echo -e " Maintainer: ${package_maintainer}" | |
echo -e " Description: ${package_description}" | |
echo -e "" | |
if [ -e "$deb_dir" ]; then rm -rf "$deb_dir"; fi | |
escape() { | |
sed -e 's/[]\/$*.^|[]/\\&/g' -e 's/&/\\&/g' <<< "$@" | |
} | |
replace_vars() { | |
declare -r file="$1" | |
declare -r target_file="$2" | |
sed < "$file" \ | |
-e "s/{{ deb_package_version }}/$(escape $package_version)/g" \ | |
-e "s/{{ deb_package_description }}/$(escape $package_description)/g" \ | |
-e "s/{{ deb_package_maintainer }}/$(escape $package_maintainer)/g" \ | |
-e "s/{{ deb_package_arch }}/$(escape $package_arch)/g" \ | |
> "$target_file" | |
} | |
log_title "Setting up Debian package:" | |
mkdir -vp "$deb_dir/DEBIAN" \ | |
"$deb_dir/etc/bitcore" \ | |
"$deb_dir/usr/opt/bitcore" \ | |
"$deb_dir/usr/opt/bitcore/bin" \ | |
"$deb_dir/usr/bin" | |
mkdir -vp "$deb_dir/etc/init" | |
mkdir -vp "$deb_dir/etc/systemd/system" | |
replace_vars "${root_dir}/scripts/debian/control" "$deb_dir/DEBIAN/control" | |
replace_vars "${root_dir}/scripts/debian/postinst" "$deb_dir/DEBIAN/postinst" | |
replace_vars "${root_dir}/scripts/debian/prerm" "$deb_dir/DEBIAN/prerm" | |
replace_vars "${root_dir}/scripts/debian/bitcore.conf" "$deb_dir/etc/init/bitcore.conf" | |
replace_vars "${root_dir}/scripts/debian/bitcore.service" "$deb_dir/etc/systemd/system/bitcore.service" | |
replace_vars "${root_dir}/scripts/debian/bitcore-bitcoind.conf" "$deb_dir/etc/init/bitcore-bitcoind.conf" | |
replace_vars "${root_dir}/scripts/debian/bitcore-bitcoind.service" "$deb_dir/etc/systemd/system/bitcore-bitcoind.service" | |
chmod -vR 0755 "$deb_dir/DEBIAN/" | |
log_title "Copying Bitcore" | |
app_dir="$deb_dir/usr/opt/bitcore" | |
cp -v "${root_dir}/bin/bitcored" "${app_dir}/bin/bitcored" | |
cp -v "${root_dir}/bin/bitcore" "${app_dir}/bin/bitcore" | |
chmod -vR 0755 "${app_dir}/bin/bitcore" "${app_dir}/bin/bitcored" | |
cp -v "${root_dir}/package.json" "${app_dir}" | |
cp -v "${root_dir}/README.md" "${app_dir}" | |
cp -v "${root_dir}/index.js" "${app_dir}" | |
pushd "${deb_dir}/usr/bin" | |
ln -vs "../opt/bitcore/bin/bitcore" | |
ln -vs "../opt/bitcore/bin/bitcored" | |
ln -vs "../opt/bitcore/node_modules/.bin/bitcoind" "bitcore-bitcoind" | |
popd | |
log_title "Installing Bitcore Modules" | |
pushd "${app_dir}" | |
VERIFY_BITCOIN_DOWNLOAD=1 npm install --production | |
echo "Cleanup Node.js addon binaries before packaging:" | |
find "${app_dir}" -type f -name '*.node' -print -delete | |
find "${app_dir}" -type f -name '*.o' -print -delete | |
echo "Cleanup intermediate files:" | |
rm -v "${deb_dir}/usr/opt/bitcore/node_modules/bitcore-node/bin/bitcoin-0.12.1-linux64.tar.gz" | |
npm shrinkwrap --dev | |
popd | |
log_title "Building Debian package" | |
dpkg-deb -Z gzip --verbose --build "$deb_dir" | |
log_title "Signing Debian package" | |
dpkg-sig --sign builder "${deb_dir}.deb" | |
echo -e "Success.\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bitcoin Mining Hardware site strikemine opens on Shopify. Built by Liquify Shopify Developers. Buy Bitcoin mining hardware for sale.