diff --git a/scripts/hostIPFS.sh b/scripts/hostIPFS.sh index d14ea50..285d2fe 100644 --- a/scripts/hostIPFS.sh +++ b/scripts/hostIPFS.sh @@ -5,7 +5,7 @@ if [ "$EUID" -ne 0 ]; exit 1; fi; -this_repo_ipfs_cid="bafybeienn6huru6cxs3ovl5ogeik2wnvviqtoainqj4zn2q3q7zzezvu6u"; +this_repo_ipfs_cid="bafybeieo67exajd256bkdxviwqv6leyi4zxk4bby3wj2u466bqfer7lyde"; user_home_dir=$(eval echo ~$USER); tornado_folder="$user_home_dir/tornado-ipfs"; script_log_file="/tmp/tornado-ipfs-installation.log"; @@ -39,6 +39,7 @@ function install_requred_packages(){ if ! is_package_installed $package; then # Kill apache process, because Debian configuring nginx package right during installation if [ $package = "nginx" ]; then systemctl stop apache2; fi; + echo "Start $package package installation"; apt install --yes --force-yes -o DPkg::Options::="--force-confold" $package &>> $script_log_file; if ! is_package_installed $package; then echo_log_err_and_exit "Error: cannot install \"$package\" package"; @@ -50,11 +51,19 @@ function install_requred_packages(){ } function install_node(){ - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash &>> $script_log_file; + curl -s -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash &>> $script_log_file; . ~/.nvm/nvm.sh; . ~/.profile; . ~/.bashrc; - nvm install 16.20.2 &>> $script_log_file; + + local required_node_version=16.20.2; + nvm install $required_node_version &>> $script_log_file; + nvm use $required_node_version &>> $script_log_file; + if node -v | grep -qw $required_node_version; then + echo "Node $required_node_version successfully installed"; + else + echo_log_err_and_exit "Cannot install node $required_node_version or node installed with error"; + fi; } function download_repo(){ @@ -74,22 +83,33 @@ function install_node_dependencies(){ function run_ipfs_daemon(){ cd $tornado_folder; - wget https://dist.ipfs.tech/kubo/v0.22.0/kubo_v0.22.0_linux-amd64.tar.gz; + wget https://dist.ipfs.tech/kubo/v0.22.0/kubo_v0.22.0_linux-amd64.tar.gz &>> $script_log_file; tar -xvzf kubo_v0.22.0_linux-amd64.tar.gz; cd kubo; - sudo bash install.sh; + sudo bash install.sh &>> $script_log_file; ipfs init --profile server; sudo -b ipfs daemon; } function configure_firewall(){ + ufw allow OpenSSH; + echo "y" | ufw enable; + + if ufw status | grep -qw active; then ufw allow 8080; ufw allow 4001; ufw deny 5000; ufw deny 5001; - ufw insert 1 allow OpenSSH; - echo "y" | ufw enable; ufw reload; + if ufw status | grep -qw 4001; then + echo "Peering ports for IPFS opened successfully via UFW"; + else + echo_log_err $(ufw status); + echo_log_err_and_exit "Cannot open ports for IPFS daemon, configure ufw please"; + fi; + else + echo "UFW is disabled, ports already opened successfully, but need to close port 5001"; + fi; } function add_to_cron(){ @@ -112,6 +132,14 @@ function add_to_cron(){ fi; } +function prepare_env(){ + cd $tornado_folder; + delete_if_exists .env; + local rpc_url="https://eth.llamarpc.com"l; + echo "RPC_URL=$rpc_url" > .env; + echo "ENS_ROOT_DOMAIN=tornadocash.eth" >> .env; +} + function run_pinner(){ cd $tornado_folder; yarn pin; @@ -125,4 +153,5 @@ install_node_dependencies; run_ipfs_daemon; configure_firewall; add_to_cron; +prepare_env; run_pinner; \ No newline at end of file