diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index de4545fa..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,11 +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); + userInput = std::regex_replace(userInput, std::regex("~"), getenv(homeEnvVar.c_str())); boost::algorithm::trim(userInput); } while (userInput.empty()); if (c == 'i' || c == 'I'){ 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" 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