diff --git a/installer/setup.sh b/installer/setup.sh index e3f474c..fc8b272 100755 --- a/installer/setup.sh +++ b/installer/setup.sh @@ -81,7 +81,7 @@ export MB_XRPL_DATA=$SASHIMONO_DATA/mb-xrpl export REPUTATIOND_DATA=$SASHIMONO_DATA/reputationd export MB_XRPL_CONFIG="$MB_XRPL_DATA/mb-xrpl.cfg" - export REPUTATIOND_CONFIG="$REPUTATIOND_DATA/reputation.cfg" + export REPUTATIOND_CONFIG="$REPUTATIOND_DATA/reputationd.cfg" export SASHIMONO_SERVICE="sashimono-agent" export CGCREATE_SERVICE="sashimono-cgcreate" export MB_XRPL_SERVICE="sashimono-mb-xrpl" @@ -1416,15 +1416,29 @@ WantedBy=timers.target" >/etc/systemd/system/$EVERNODE_AUTO_UPDATE_SERVICE.timer # Write the verison timestamp to a file for later updated version comparison. echo $installer_version_timestamp >$SASHIMONO_DATA/$installer_version_timestamp_file - - if confirm "\nWould you like to opt-in to the Evernode reputation and reward system?"; then - if ! configure_reputationd; then - echomult "\nError occured configuring ReputationD!!\n You can retry opting-in by executing 'evernode reputationd' after installation.\n" + if [ "$upgrade" == "0" ]; then + if confirm "\nWould you like to opt-in to the Evernode reputation and reward system?"; then + if ! configure_reputationd 0; then + echomult "\nError occured configuring ReputationD!!\n You can retry opting-in by executing 'evernode reputationd' after installation.\n" + else + echomult "\nReputationD configuration successfull!!\n" + fi else - echomult "\nReputationD configuration successfull!!\n" + echomult "\nSkipped from opting-in Evernode reputation and reward system.\nYou can opt-in later by using 'evernode reputationd' command.\n" fi else - echomult "\nSkipped from opting-in Evernode reputation and reward system.\nYou can opt-in later by using 'evernode reputationd' command.\n" + #[ "$upgrade" == "1" ] + if sudo -u "$REPUTATIOND_USER" [ -f "/home/$REPUTATIOND_USER/.config/systemd/user/$REPUTATIOND_SERVICE.service" ]; then + #reputationd_enabled=true + echo "Configuring Evernode reputation and reward system." + if ! configure_reputationd 1; then + echomult "\nError occured configuring ReputationD!!\n You can retry opting-in by executing 'evernode reputationd' after installation.\n" + else + echomult "\nReputationD configuration successfull!!\n" + fi + else + echo "You are not opted-in to Evernode reputation and reward system." + fi fi } @@ -2013,20 +2027,22 @@ WantedBy=timers.target" >/etc/systemd/system/$EVERNODE_AUTO_UPDATE_SERVICE.timer } function configure_reputationd() { + local upgrade=$1 [ "$EUID" -ne 0 ] && echo "Please run with root privileges (sudo)." && exit 1 # Configure reputationd users and register host. echomult "configuring Evernode reputation for reward distribution..." if [ -f "$REPUTATIOND_CONFIG" ]; then - reputationd_secret_path=$(jq -r '.reputation.secretPath' "$REPUTATIOND_CONFIG") + reputationd_secret_path=$(jq -r '.xrpl.secretPath' "$REPUTATIOND_CONFIG") chown "$REPUTATIOND_USER": $reputationd_secret_path fi - - #account generation, - if ! set_host_reputationd_account; then - echo "error setting up reputationd account." - return 1 + if [ "$upgrade" == "0" ]; then + #account generation, + if ! set_host_reputationd_account; then + echo "error setting up reputationd account." + return 1 + fi fi reputationd_user_dir=/home/"$REPUTATIOND_USER" @@ -2037,48 +2053,52 @@ WantedBy=timers.target" >/etc/systemd/system/$EVERNODE_AUTO_UPDATE_SERVICE.timer # NOTE : There can be user id mismatch, as we do not delete REPUTATIOND_USER's home in the uninstallation even though the user is removed. chown -R "$REPUTATIOND_USER":"$SASHIADMIN_GROUP" $reputationd_user_dir - echo -e "\nAccount setup is complete." + if [ "$upgrade" == "0" ]; then + echo -e "\nAccount setup is complete." - local message="Your host account with the address $reputationd_xrpl_address will be on Xahau $NETWORK. - \nThe secret key of the account is located at $reputationd_key_file_path. - \nNOTE: It is your responsibility to safeguard/backup this file in a secure manner. - \nIf you lose it, you will not be able to access any funds in your Host account. NO ONE else can recover it. - \n\nThis is the account that will represent this host on the Evernode host registry. You need to load up the account with following funds in order to continue with the installation." + local message="Your host account with the address $reputationd_xrpl_address will be on Xahau $NETWORK. + \nThe secret key of the account is located at $reputationd_key_file_path. + \nNOTE: It is your responsibility to safeguard/backup this file in a secure manner. + \nIf you lose it, you will not be able to access any funds in your Host account. NO ONE else can recover it. + \n\nThis is the account that will represent this host on the Evernode host registry. You need to load up the account with following funds in order to continue with the installation." - local min_reputation_xah_requirement=$(echo "$MIN_REPUTATION_COST_PER_MONTH*$MIN_OPERATIONAL_DURATION + 1.2" | bc) - local lease_amount=$(jq ".xrpl.leaseAmount | select( . != null )" "$MB_XRPL_CONFIG") - local min_reputation_evr_requirement=$(echo "$lease_amount*24*30*$MIN_OPERATIONAL_DURATION" | bc) + local min_reputation_xah_requirement=$(echo "$MIN_REPUTATION_COST_PER_MONTH*$MIN_OPERATIONAL_DURATION + 1.2" | bc) + local lease_amount=$(jq ".xrpl.leaseAmount | select( . != null )" "$MB_XRPL_CONFIG") + local min_reputation_evr_requirement=$(echo "$lease_amount*24*30*$MIN_OPERATIONAL_DURATION" | bc) - local need_xah=$(echo "$min_reputation_xah_requirement > 0" | bc -l) - local need_evr=$(echo "$min_reputation_evr_requirement > 0" | bc -l) - [[ "$need_xah" -eq 1 ]] && message="$message\n(*) At least $min_reputation_xah_requirement XAH to cover regular transaction fees for the first three months." - [[ "$need_evr" -eq 1 ]] && message="$message\n(*) At least $min_reputation_evr_requirement EVR to cover Evernode registration." + local need_xah=$(echo "$min_reputation_xah_requirement > 0" | bc -l) + local need_evr=$(echo "$min_reputation_evr_requirement > 0" | bc -l) + [[ "$need_xah" -eq 1 ]] && message="$message\n(*) At least $min_reputation_xah_requirement XAH to cover regular transaction fees for the first three months." + [[ "$need_evr" -eq 1 ]] && message="$message\n(*) At least $min_reputation_evr_requirement EVR to cover Evernode registration." - message="$message\n\nYou can scan the following QR code in your wallet app to send funds based on the account condition:\n" + message="$message\n\nYou can scan the following QR code in your wallet app to send funds based on the account condition:\n" - echomult "$message" + echomult "$message" - generate_qrcode "$reputationd_xrpl_address" + generate_qrcode "$reputationd_xrpl_address" - ! sudo -u $REPUTATIOND_USER REPUTATIOND_DATA_DIR=$REPUTATIOND_DATA node $REPUTATIOND_BIN new $reputationd_xrpl_address $reputationd_key_file_path && echo "error creating configs" && exit 1 + ! sudo -u $REPUTATIOND_USER REPUTATIOND_DATA_DIR=$REPUTATIOND_DATA node $REPUTATIOND_BIN new $reputationd_xrpl_address $reputationd_key_file_path && echo "error creating configs" && exit 1 - echomult "To set up your reputationd host account, ensure a deposit of $min_reputation_xah_requirement XAH to cover the regular transaction fees for the first three months." - echomult "\nChecking the reputationd account condition." - while true; do - wait_call "sudo -u $REPUTATIOND_USER REPUTATIOND_DATA_DIR=$REPUTATIOND_DATA node $REPUTATIOND_BIN wait-for-funds NATIVE $min_reputation_xah_requirement" && break - confirm "\nDo you want to retry?\nPressing 'n' would terminate the opting-in." || return 1 - done + echomult "To set up your reputationd host account, ensure a deposit of $min_reputation_xah_requirement XAH to cover the regular transaction fees for the first three months." + echomult "\nChecking the reputationd account condition." + while true; do + wait_call "sudo -u $REPUTATIOND_USER REPUTATIOND_DATA_DIR=$REPUTATIOND_DATA node $REPUTATIOND_BIN wait-for-funds NATIVE $min_reputation_xah_requirement" && break + confirm "\nDo you want to retry?\nPressing 'n' would terminate the opting-in." || return 1 + done + fi ! sudo -u $REPUTATIOND_USER REPUTATIOND_DATA_DIR=$REPUTATIOND_DATA node $REPUTATIOND_BIN prepare && echo "error preparing account" && exit 1 - echomult "\n\nIn order to register in reputation and reward system you need to have $min_reputation_evr_requirement EVR balance in your host account. Please deposit the required registration fee in EVRs. - \nYou can scan the provided QR code in your wallet app to send funds." + if [ "$upgrade" == "0" ]; then + echomult "\n\nIn order to register in reputation and reward system you need to have $min_reputation_evr_requirement EVR balance in your host account. Please deposit the required registration fee in EVRs. + \nYou can scan the provided QR code in your wallet app to send funds." - while true; do - wait_call "sudo -u $REPUTATIOND_USER REPUTATIOND_DATA_DIR=$REPUTATIOND_DATA node $REPUTATIOND_BIN wait-for-funds ISSUED $min_reputation_evr_requirement" && break - confirm "\nDo you want to retry?\nPressing 'n' would terminate the opting-in." || return 1 - done + while true; do + wait_call "sudo -u $REPUTATIOND_USER REPUTATIOND_DATA_DIR=$REPUTATIOND_DATA node $REPUTATIOND_BIN wait-for-funds ISSUED $min_reputation_evr_requirement" && break + confirm "\nDo you want to retry?\nPressing 'n' would terminate the opting-in." || return 1 + done + fi # Setup env variable for the reputationd user. echo " export XDG_RUNTIME_DIR=$reputationd_user_runtime_dir" >>"$reputationd_user_dir"/.bashrc @@ -2437,7 +2457,7 @@ WantedBy=timers.target" >/etc/systemd/system/$EVERNODE_AUTO_UPDATE_SERVICE.timer elif [ "$mode" == "reputationd" ]; then if [ "$2" == "opt-in" ]; then init_setup_helpers - configure_reputationd || echomult "\nError occured configuring ReputationD." + configure_reputationd 0 || echomult "\nError occured configuring ReputationD." elif [ "$2" == "opt-out" ]; then ! confirm "Are you sure you want to opt out from Evernode reputation for reward distribution?" "n" && exit 1 remove_reputationd