ls -la
total 28
drwxr-xr-x 7 root root 4096 Nov 8 14:13 .
drwxr-xr-x 15 root root 4096 May 18 2022 ..
lrwxrwxrwx 1 root root 30 Aug 26 2022 aaa-admin.aaavalidator.com -> /var/www/clients/client2/web3/
lrwxrwxrwx 1 root root 30 Oct 13 2022 aaavalidator.com -> /var/www/clients/client1/web1/
lrwxrwxrwx 1 root root 31 Oct 13 2022 api.aaavalidator.com -> /var/www/clients/client4/web4//
drwxr-xr-x 2 ispapps ispapps 4096 May 17 2022 apps
drwxr-xr-x 4 root root 4096 Aug 2 14:28 automation
drwxr-xr-x 2 root root 4096 May 17 2022 awffull
drwxr-xr-x 10 root root 4096 Aug 2 13:55 clients
lrwxrwxrwx 1 root root 31 Nov 8 14:13 eth.nodigy.com -> /var/www/clients/client6/web19/
lrwxrwxrwx 1 root root 31 Nov 8 14:11 goerli.nodigy.com -> /var/www/clients/client6/web18/
drwxr-xr-x 4 root root 4096 Oct 6 11:51 html
lrwxrwxrwx 1 root root 30 Feb 22 2023 nodigy.com -> /var/www/clients/client6/web6/
lrwxrwxrwx 1 root root 31 Nov 8 14:04 nymtest.nodigy.com -> /var/www/clients/client6/web17/
lrwxrwxrwx 1 root root 30 Sep 3 2022 static.aaavalidator.com -> /var/www/clients/client5/web5/
lrwxrwxrwx 1 root root 31 Feb 23 2023 test.nodigy.com -> /var/www/clients/client6/web12/
0
ls -la скинуть в дев нул && echo "true" || echo "false"
lalalal команда явно с ошибкой
ls -la
echo $?
вариант с регулярным выражением не подходит, так как на все команды этих регулярок не напасешься
echo $?
# lalalal команда явно с ошибкой
bash: sdfsdf: command not found
# echo $?
127
# ls -la
...
# echo $?
0
ls -la || exit 1
ls -la || exit 1
ls -la || exit 1
ls -la || exit 1
#!/bin/bash -c
###############################################################################
# запуск скрипта подаем на него одну единственную переменную scrypt.sh 13
# где 13 ID в БД нуного нам инсталятора
node_id=$1;
echo "node_id $node_id"
sleep 1
set -v # включает отображение выполняемых команд
# ставлю пхп эту часть можо удалить нужно для запуска на чистой машине чего-то что могло бы общаться с mysql
sudo apt-get update -y
sudo apt-get install php php-mysql -y
sudo apt-get install php-mysql -y
function insert_db {
if [ -f "$1.php" ]; then
rm -rf "$1.php"
fi
cat > ./$1.php << EOF
<?php
\$servername = "111.111.111.111";
\$username = "username";
\$password = "password";
\$dbname = "dmname";
\$node_id= "$node_id";
\$conn = mysqli_connect(\$servername, \$username, \$password, \$dbname);
if (!\$conn) {
die("Connection failed: " . mysqli_connect_error());
}
\$sql = "UPDATE \`wizard_setting_nym_testnet\` SET \`$1\` = '$2', \`deleted_at\` = NULL WHERE \`wizard_setting_nym_testnet\`.\`node_id\`= '\$node_id' ";
\$result = mysqli_query(\$conn, \$sql);
mysqli_close(\$conn);
?>
EOF
php ./$1.php
}
function select_db {
if [ -f "$1.php" ]; then
rm -rf "$1.php"
fi
cat > ./$1.php << EOF
<?php
\$servername = "111.111.111.111";
\$username = "username";
\$password = "password";
\$dbname = "dmname";
\$node_id= "$node_id";
\$conn = mysqli_connect(\$servername, \$username, \$password, \$dbname);
if (!\$conn) {
die("Connection failed: " . mysqli_connect_error());
}
\$sql = "SELECT \`$1\` FROM \`wizard_setting_nym_testnet\` WHERE \`node_id\` = '\$node_id'";
\$result = mysqli_query(\$conn, \$sql);
if (mysqli_num_rows(\$result) > 0) {
while(\$row = mysqli_fetch_assoc(\$result)) {
print_r(\$row["$1"]);
}
} else {
echo "0 results";
}
mysqli_close(\$conn);
?>
EOF
eval "$1=\"$(php ./$1.php)\"";
eval "echo \"select in db: $1=$(php ./$1.php)\""
}
#################################################
function step_start {
((now_step++)) # добавляем единичку
select_db "previous_succesfull_step"
insert_db "now_step" "$now_step"
insert_db "step_description" "$3"
step_description=$3 # сохраняем в переменную чтоб вторая функция его видела
if [[ "$now_step" -gt "$previous_succesfull_step" ]]; then # Больше последнего удачного
$1
if [ $? -eq $2 ]; then #Если код завершение комакнды до этой функуции равен 2 значению функции"
if [[ "$previous_succesfull_step" -lt "$now_step" ]]; then #Проверяем не больше ли ласт степ текущего, для валидного скипа
previous_succesfull_step=$now_step # добавляем удачный шаг
insert_db "previous_succesfull_step" "$now_step" ;
insert_db "stdout" "[OK] Successfully installed step $now_step"
echo -e "\033[32m[OK]\033[0m Successfully installed step $now_step"
fi
else
echo -e "\e[1;31m[WARNING]\e[0m, Scrypt stoped on step $now_step " >&2
insert_db "stderr" "[WARNING] Scrypt stoped on step $now_step"
exit 1
fi
else
echo -e "\e[1;34m[STEP SKIP]\e[0m Step ${now_step} already completed"
insert_db "stdout" "[STEP SKIP] Step ${now_step} already completed"
fi
sleep 1
}
############################################################################################
full_step=$(($(egrep "^step_start .+" $(pwd)/$0 | wc -l )-0))
insert_db "full_step" "$full_step"
select_db "wallet"
#############################################################################################
# Here is the body of the script itself #
#############################################################################################
function step_1 {
echo 'export wallet='$wallet >> $HOME/.bash_profile
}
function step_2 {
echo 'export node_id='$node_id >> $HOME/.bash_profile
}
function step_3 {
sudo apt update < "/dev/null"
}
function step_4 {
sudo apt install curl -y < "/dev/null" ;sleep 2
}
function step_5 {
source $HOME/.bashrc
}
function step_6 {
source $HOME/.bash_profile
}
function step_7 {
sed -i "s/#\$nrconf{restart} = 'i';/\$nrconf{restart} = 'a';/" /etc/needrestart/needrestart.conf
sudo dpkg --configure -a
}
function step_8 {
sudo apt install make clang pkg-config libssl-dev build-essential git -y -qq < "/dev/null"
}
function step_9 {
sudo curl https://sh.rustup.rs -sSf | sh -s -- -y
}
function step_10 {
source $HOME/.cargo/env
}
function step_11 {
cd $HOME
}
function step_12 {
git clone https://github.com/nymtech/nym.git
}
function step_13 {
cd nym
}
function step_14 {
git pull
git checkout tags/nym-binaries-v2023.1-milka
}
function step_15 {
cargo build --release
}
function step_16 {
sudo mv /root/nym/target/release/nym-mixnode /usr/bin
}
function step_17 {
nym-mixnode init --id $node_id --host $(curl ipinfo.io/ip)
}
function step_18 {
sudo tee <<EOF >/dev/null /etc/systemd/journald.conf
Storage=persistent
EOF
}
function step_19 {
sudo systemctl restart systemd-journald
}
function step_20 {
sudo tee <<EOF >/dev/null /etc/systemd/system/nym-mixnode.service
[Unit]
Description=Nym Mixnode
[Service]
User=$USER
ExecStart=/usr/bin/nym-mixnode run --id '$node_id'
KillSignal=SIGINT
Restart=on-failure
RestartSec=30
StartLimitInterval=350
StartLimitBurst=10
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF
}
function step_21 {
echo "DefaultLimitNOFILE=65535" >> /etc/systemd/system.conf
}
function step_22 {
sudo systemctl daemon-reload
}
function step_23 {
sudo systemctl enable nym-mixnode
}
function step_24 {
sudo systemctl stop nym-mixnode
}
function step_25 {
sudo systemctl start nym-mixnode
}
function step_26 {
insert_db "identity_key" "$(nym-mixnode node-details --id $node_id | grep "Identity Key:" | sed -e 's/Identity Key: //g')"
insert_db "sphinx_key" "$(nym-mixnode node-details --id $node_id | grep "Sphinx Key:" | sed -e 's/Sphinx Key: //g')"
insert_db "host_bind_address" "$(nym-mixnode node-details --id $node_id | grep "Host:" | sed -e 's/Host: //g')"
insert_db "version" "$(nym-mixnode node-details --id $node_id | grep "Version:" | sed -e 's/Version: //g')"
insert_db "mix_port" "$(nym-mixnode node-details --id $node_id | egrep -o "Mix Port: [0-9]+" | egrep -o "[0-9]+")"
insert_db "verloc_port" "$(nym-mixnode node-details --id $node_id | egrep -o "Verloc port: [0-9]+" | egrep -o "[0-9]+")"
insert_db "http_port" "$(nym-mixnode node-details --id $node_id | egrep -o "Http Port: [0-9]+" | egrep -o "[0-9]+")"
nym-mixnode node-details --id $node_id
}
# ждем когда в бд появится эта переменная введеная клиентом, раз в две секунды спрашиваем не появилась ли она
function step_27 {
until select_db "signature_first_key"; [ ! -z "$signature_first_key" ] &> /dev/null
do
sleep 2
done
}
function step_28 {
insert_db "signature_second_key" "$(nym-mixnode sign --id $node_id --contract-msg $signature_first_key | tail -1)"
}
function step_29 {
echo "sudo systemctl status nym-mixnode"
}
#step_start '{FUNCTION_STEP}' "{TRUE_END_CODE}" "{DESCRYPTION}"
step_start 'step_1' "0" "Export wallet to bash_profile"
step_start 'step_2' "0" "Export node_id to bash_profile"
step_start 'step_3' "0" "apt-get update"
step_start 'step_4' "0" "install curl"
step_start 'step_5' "0" "source HOME/.bashrc"
step_start 'step_6' "0" "source HOME/.bash_profile"
step_start 'step_7' "0" "dpkg --configure -a"
step_start 'step_8' "0" "install make clang pkg-config libssl-dev build-essential git"
step_start 'step_9' "0" "Install rustup"
step_start 'step_10' "0" "source HOME/.cargo/env "
step_start 'step_11' "0" "cd HOME "
step_start 'step_12' "0" "git clone"
step_start 'step_13' "0" "cd nym"
step_start 'step_14' "0" "git checkout tags"
step_start 'step_15' "0" "cargo build --release "
step_start 'step_16' "0" "mv nym-mixnode to /usr/bin"
step_start 'step_17' "0" "nym-mixnode init"
step_start 'step_18' "0" "Edit /etc/systemd/journald.conf"
step_start 'step_19' "0" "restart systemd-journald"
step_start 'step_20' "0" "create nym-mixnode.service"
step_start 'step_21' "0" "up limit in /etc/systemd/system.conf to 65535"
step_start 'step_22' "0" "daemon-reload"
step_start 'step_23' "0" "enable nym-mixnode"
step_start 'step_24' "0" "stop nym-mixnode"
step_start 'step_25' "0" "start nym-mixnode"
step_start 'step_26' "0" "node-details save to database"
step_start 'step_27' "0" "wait signature_first_key"
step_start 'step_28' "0" "Generated signature_second_key"
step_start 'step_29' "0" "End, echo default command in terminal"
id bigint(20) unsigned Автоматическое приращение
data_center_id bigint(20) unsigned NULL
server_id bigint(20) unsigned NULL
project_id bigint(20) unsigned NULL
user_id bigint(20) unsigned NULL
wallet varchar(255) NULL
node_id bigint(20) unsigned NULL
data_center_type varchar(255) NULL
country varchar(255) NULL
city varchar(255) NULL
identity_key text NULL
sphinx_key text NULL
host_bind_address varchar(255) NULL
version varchar(255) NULL
mix_port varchar(255) NULL
verloc_port varchar(255) NULL
http_port varchar(255) NULL
signature_first_key text NULL
signature_second_key text NULL
progress_status tinyint(4) [1]
installation_json longtext NULL
step_description longtext NULL
full_step tinyint(4) NULL [0]
now_step tinyint(4) NULL [0]
previous_succesfull_step tinyint(4) NULL [0]
installation_log longtext NULL
stdout longtext NULL
stderr longtext NULL
log_file_url text NULL
created_at timestamp NULL
updated_at timestamp NULL
deleted_at timestamp NULL
<?php
$output = shell_exec('ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no -i /root/openssh_key root@65.109.236.8 bash -c "sleep 3; curl -O http://1.1.1.1/nym_testnet.sh; chmod +x nym_testnet.sh; pwd; ./nym_mainnet.sh 63;"');
echo "<pre>$output/n</pre>";
?>