From 914d3c87763c6497e3f8565bf9e32be8a7dca2f0 Mon Sep 17 00:00:00 2001 From: notdixon Date: Wed, 10 Aug 2022 23:08:04 +0100 Subject: [PATCH 1/4] SimpleWallet/SimpleWallet.cpp: Expand Tilde Mimic shell behaviour by expanding the tilde to either $HOME (Linux, OS X, BSD) or %USERPROFILE% (Windows) - most people use "~" instead of typing the entire path to their home directory. --- src/SimpleWallet/SimpleWallet.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index de4545fa..85ddcce1 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -799,6 +799,14 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) { do { std::cout << "Wallet file name: "; std::getline(std::cin, userInput); + +#if defined (WIN32) + userInput = std::regex_replace(userInput, std::regex("~"), getenv("USERPROFILE")); +#else + userInput = std::regex_replace(userInput, std::regex("~"), getenv("HOME")); +#endif + + boost::algorithm::trim(userInput); } while (userInput.empty()); if (c == 'i' || c == 'I'){ From c0bff8bfb90ccf96ddeaf1f084aa6ba5b7d70cc1 Mon Sep 17 00:00:00 2001 From: notdixon Date: Fri, 12 Aug 2022 20:49:32 +0100 Subject: [PATCH 2/4] Updated Tilde Expansion Instead of using "#if defined", we just use Boost to see if the platform is Windows. --- src/SimpleWallet/SimpleWallet.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index 85ddcce1..13345dde 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "Common/Base58.h" #include "Common/CommandLine.h" @@ -794,19 +795,19 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) { return false; } + std::string homeEnvVar; + + if (BOOST_OS_WINDOWS) + homeEnvVar = "USERPROFILE"; + else + homeEnvVar = "HOME"; + std::cout << "Specify wallet file name (e.g., name.wallet).\n"; std::string userInput; do { std::cout << "Wallet file name: "; std::getline(std::cin, userInput); - -#if defined (WIN32) - userInput = std::regex_replace(userInput, std::regex("~"), getenv("USERPROFILE")); -#else - userInput = std::regex_replace(userInput, std::regex("~"), getenv("HOME")); -#endif - - + userInput = std::regex_replace(userInput, std::regex("~"), getenv(homeEnvVar.c_str())); boost::algorithm::trim(userInput); } while (userInput.empty()); if (c == 'i' || c == 'I'){ From 3a2aa508ef1826e99ee47e883557794b190048a1 Mon Sep 17 00:00:00 2001 From: notdixon Date: Fri, 12 Aug 2022 21:20:55 +0100 Subject: [PATCH 3/4] tools: make_swap.sh Script that will get the amount of system memory, and then create a swap file with the size required to get a combined total of 13GB - the recommended stated in the README Works on both Raspberry Pi and standard Linux distributions --- tools/make_swap.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 tools/make_swap.sh diff --git a/tools/make_swap.sh b/tools/make_swap.sh new file mode 100755 index 00000000..cda817a8 --- /dev/null +++ b/tools/make_swap.sh @@ -0,0 +1,36 @@ +#!/bin/bash +SYSTEM_RAMSIZE="$(( $(free | awk 'FNR == 2 {print $2}') / 1000000 ))" +SWAPSIZE="$(( (13 - $SYSTEM_RAMSIZE) * 1024 ))" + +[ -f "/etc/apt/sources.list.d/raspi.list" ] && isRPI=1 || isRPI=0 +[ "$EUID" != "0" ] && printf "Please run this as root: \x1b[1;95msudo $0\x1b[0m\n" && exit 1 + +[ "$SYSTEM_RAMSIZE" -gt 13 ] && \ + printf "A swap file isn't required as there is enough memory is installed\n" && exit + +[ -f "/swapfile" ] && printf "\x1b[1;7;91m WARNING \x1b[0m /swapfile already exists - " && \ + printf "overwrite? [Y/N] " && read overwrite + +case $overwrite in + "y"|"Y") printf "Swapping-off /swapfile\n" && swapoff /swapfile && rm /swapfile;; + "n"|"N") printf "Couldn't create swapfile\n" && exit 1;; +esac + +case $isRPI in + 1) + dphys-swapfile swapoff + sed -i "s/CONF_SWAPSIZE=.*/CONF_SWAPSIZE=$SWAPSIZE/" /etc/dphys-swapfile + dphys-swapfile setup + dphys-swapfile swapon + ;; + 0) + [ -f "/swapfile" ] && printf "\x1b[1;7;91m WARNING \x1b[0m /swapfile already exists - " && \ + printf "overwrite? [Y/N] " && read overwrite + + case $overwrite in + "y"|"Y") printf "Swapping-off /swapfile\n" && swapoff /swapfile && rm /swapfile;; + "n"|"N") printf "Couldn't create swapfile\n" && exit 1;; + esac + + fallocate -l ${SWAPSIZE}M /swapfile; chmod 0600 /swapfile; mkswap /swapfile; swapon /swapfile; exit 0;; +esac From c57e36a238fd508b1d4cea73c2023017786f654c Mon Sep 17 00:00:00 2001 From: notdixon Date: Sun, 14 Aug 2022 15:31:09 +0100 Subject: [PATCH 4/4] tools/deploy.sh: Automated Installation Script A script that automates "deployment" - only requires the script and 'git'. The script will install any dependencies, and can be used to automate it on many systems, such as multiple Raspberry Pi's at a time. Also provides basic functionality to 'concealwallet' --- tools/deploy.sh | 142 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100755 tools/deploy.sh diff --git a/tools/deploy.sh b/tools/deploy.sh new file mode 100755 index 00000000..a09d9152 --- /dev/null +++ b/tools/deploy.sh @@ -0,0 +1,142 @@ +#!/bin/bash + +GIT_URL="https://github.com/ConcealNetwork/conceal-core" +BIN_DIR="$HOME/.local/src/conceal-core/build/src" +WALLETBIN="concealwallet" +BRANCH="master" + +INSTALL=0 +UPDATE=0 + +DISTRO="$(awk -F\" '/PRETTY_NAME/ {print $2}' /etc/os-release)" + +# Check to see if this is a Raspberry Pi +[ -f "/etc/apt/sources.list.d/raspi.list" ] && isRPI=1 || isRPI=0 + +# Number of Cores to dedicate to 'make' (make -j$JOBS) +[ "$isRPI" = "1" ] && JOBS=1 || JOBS="$(( $(nproc) / 3))" + +## FUNCTIONS ## + +# Install Dependencies +installDeps() { + case $DISTRO in + "Arch"*|"Artix"*|"Manjaro"*) + PKGMAN_CMD="sudo pacman -Sy --noconfirm" + PACKAGES="base-devel git cmake boost boost-libs";; + + *"buntu"*|"Debian"*|*"Mint"*) + PKGMAN_CMD="sudo apt install -y" + PACKAGES="build-essential git cmake libboost-all-dev python3-dev";; + esac + + echo "Installing $(echo $PACKAGES | wc -w) Packages" + echo "You may be asked to enter your password" + + sudo $PKGMAN_CMD $PACKAGES +} + +# Get conceal-core +getConceal() { + [ ! -d "$HOME/.local/src" ] && mkdir -p "$HOME/.local/src" + + git clone $GIT_URL -b $BRANCH $HOME/.local/src/conceal-core && \ + mkdir $HOME/.local/src/conceal-core/build || exit + buildConceal +} + +buildConceal() { + cd $HOME/.local/src/conceal-core/build + + cmake .. > buildlog 3>&1 1>&2 2>&3 3>&- && make -j$JOBS >> buildLog 3>&1 1>&2 2>&3 3>&- || buildFail + + which conceald > /dev/null 2>&1 || addToPath + echo "Build Completed at $(date +'%-I:%M%p on %A %-d %B %Y')" + exit 0 +} + +# The build failed +buildFail() { + printf "An error occured when building - check $HOME/.local/src/conceal-core/build/buildLog for information.\n" + exit 1 +} + +# Update the existing conceal installation +updateConceal() { + cd $HOME/.local/src/conceal-core + + echo "Pulling new commits..." + git pull + buildConceal + exit 0 +} + +# Open a wallet using concealwallet +openWallet() { + which concealwallet > /dev/null 2>&1 || WALLETBIN="$BIN_DIR/concealwallet" + + [ "$TESTNET" = 1 ] && WALLET_ARGS="$WALLET_ARGS --testnet" + [ ! -z "$DAEMON_ADDR" ] && WALLET_ARGS="$WALLET_ARGS --daemon-address=$DAEMON_ADDR" + + echo "$WALLETBIN --wallet-file $1 $WALLET_ARGS" +# $WALLETBIN --wallet-file "$1" $WALLET_ARGS + exit 0 +} + +# Add the build directory to $PATH? +addToPath() { + printf ">>> Add the build directory to PATH? [y/N] " + read addToPath + + case $addToPath in + "y"|"Y") echo "export PATH=\"$PATH:$BIN_DIR\" >> $HOME/.bashrc";; + "n"|"N"|*) echo "Don't forget to add '$BIN_DIR' to your PATH later";; + esac + return +} + +# Show available arguments - ie. Help +scriptHelp() { + cat << EOF +Conceal Core Deployment Script +============================== + +General Flags + --help | -h Show this help text + --dev | -d Use the 'development' branch + --master | -m Use the 'master' branch (default) + --install | -i Install conceal-core + --update | -u Update conceal-core + +Wallet Control + --open | -o Open a wallet (--open ) + --testnet | -t Use testnet + --daemon | -D Specify a custom daemon URL +EOF + exit 0 +} + +## The actual script ## +case $1 in + "") scriptHelp;; +esac + +while test "$#" -gt 0; do + case "$1" in + "--master"|"-m") echo "Using master branch" && BRANCH="master";; + "--dev"|"-d") echo "Using development branch" && BRANCH="development";; + + "--install"|"-i") INSTALL=1 UPDATE=0;; + "--update"|"-u") INSTALL=0 UPDATE=1;; + + "--open"|"-o") shift && WALLET="$1";; + "--testnet"|"-t") TESTNET=1;; + "--daemon"|"-D") shift && DAEMON_ADDR="$1";; + + "--help"|"-h") scriptHelp;; + esac + shift +done +[ "$INSTALL" = "1" ] && installDeps && getConceal +[ "$UPDATE" = "1" ] && updateConceal +[ ! -z "$WALLET" ] && openWallet "$WALLET"