Skip to content

Commit

Permalink
update codebot - ansible_user
Browse files Browse the repository at this point in the history
  • Loading branch information
POPPIN-FUMI committed Jan 16, 2025
1 parent a7a0237 commit e9e9323
Show file tree
Hide file tree
Showing 43 changed files with 1,649 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cli/deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slv/cli",
"version": "0.4.0",
"version": "0.4.1",
"exports": "./dist/exe",
"publish": {
"include": ["src"],
Expand Down
2 changes: 1 addition & 1 deletion cli/src/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ validatorCmd.command('codebot')
const config = parse(fileContent) as Config
for (const validator of config.validators) {
const sshConnection: SSHConnection = {
username: validator.username,
username: 'solv',
ip: validator.ip,
rsa_key_path: validator.rsa_key_path,
}
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build:mac": "deno compile -A --target x86_64-apple-darwin --no-check --output dist/slv-x86_64-apple-darwin-exe cli/src/index.ts && tar -czvf dist/slv-x86_64-apple-darwin-exe.tar.gz dist/slv-x86_64-apple-darwin-exe",
"upload:script": "cd ./sh/ && aws --endpoint-url=https://278a7109e511280594fe6a2ebb778333.r2.cloudflarestorage.com/slv s3 cp install s3://slv/ --content-disposition 'attachment; filename=install'",
"upload:exe": "deno run -A cli/uploadExe.ts",
"upload:template": "tar -czf dist/template.tar.gz ./template/0.4.0 && deno run -A cli/uploadTemplate.ts",
"upload:template": "tar -czf dist/template.tar.gz ./template/0.4.1 && deno run -A cli/uploadTemplate.ts",
"purge:cache": "deno run -A cmn/lib/purgeR2Cache.ts",
"slv-dev": "npm run --prefix website/slv-dev"
},
Expand Down
141 changes: 141 additions & 0 deletions sh/0.4.1/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/bin/bash

set -e

VERSION="0.4.1"
BASE_URL="https://storage.slv.dev/slv"

detect_platform() {
uname_out="$(uname -s)"
case "${uname_out}" in
Linux*) platform="x86_64-unknown-linux-gnu"; osfamily="linux";;
Darwin*) platform="x86_64-apple-darwin"; osfamily="darwin";;
CYGWIN*|MINGW*|MSYS*|Windows*) platform="x86_64-pc-windows-msvc"; osfamily="windows";;
*) echo "Unsupported platform: ${uname_out}" && exit 1;;
esac
}

install_slv() {
echo "Detecting platform..."
detect_platform
echo "Platform detected: $platform"

DOWNLOAD_URL="${BASE_URL}/${VERSION}/${platform}-exe.tar.gz?cachebuster=$(date +%s)"
TEMPLATE_URL="${BASE_URL}/template/${VERSION}/template.tar.gz?cachebuster=$(date +%s)"
INSTALL_DIR="/usr/local/bin"
TEMPLATE_DIR="$HOME/.slv/template"
TEMP_DIR=$(mktemp -d)
mkdir -p "$HOME/.slv"
mkdir -p "$HOME/.slv/keys"

if [ "$platform" == "x86_64-pc-windows-msvc" ]; then
INSTALL_DIR="$HOME/.local/bin"
mkdir -p "$INSTALL_DIR"
fi

echo "Temporary directory: $TEMP_DIR"

echo "Downloading slv from $DOWNLOAD_URL..."
curl -fsSL "$DOWNLOAD_URL" -o "$TEMP_DIR/slv.tar.gz"

echo "Downloading templates from $TEMPLATE_URL..."
curl -fsSL "$TEMPLATE_URL" -o "$HOME/.slv/template.tar.gz"

echo "Extracting slv..."
tar -xzvf "$TEMP_DIR/slv.tar.gz" -C "$TEMP_DIR" --strip-components=1

echo "Extracting templates..."
tar -xzvf "$HOME/.slv/template.tar.gz" -C "$HOME/.slv" --strip-components=1
mkdir -p "$HOME/.slv/template"
echo "Copying templates to $HOME/.slv/template"

SLV_FILE="$TEMP_DIR/slv-x86_64-apple-darwin-exe"
TEMPLATE_DL_DIR="$HOME/.slv/"

if [ ! -f "$SLV_FILE" ]; then
echo "Error: Extracted file not found."
exit 1
fi

echo "Installing slv..."
if [ ! -d "$INSTALL_DIR" ]; then
echo "$INSTALL_DIR does not exist. Creating it..."
sudo mkdir -p "$INSTALL_DIR"
fi

if [ "$platform" == "x86_64-pc-windows-msvc" ]; then
sudo mv "$SLV_FILE" "$INSTALL_DIR/slv.exe"
else
sudo mv "$SLV_FILE" "$INSTALL_DIR/slv"
sudo chmod +x "$INSTALL_DIR/slv"
fi

echo "Cleaning up..."
rm -rf "$TEMP_DIR"
rm -rf "$TEMP_DIR2"
rm -rf "$HOME/.slv/template.tar.gz"

echo "slv has been installed successfully!"
echo "Ensure $INSTALL_DIR is in your PATH."
if [ "$platform" == "x86_64-pc-windows-msvc" ]; then
echo "Windows users, add $INSTALL_DIR to your PATH manually."
fi
mkdir -p ~/.slv/keys
slv -P
}

install_dependencies() {
if ! command -v python3 >/dev/null 2>&1; then
echo "Python3 not found. Installing..."
if [ "$osfamily" = "linux" ]; then
# Distribution check
# Ubuntu/Debian
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y python3 python3-pip
# RHEL/CentOS
elif command -v yum >/dev/null 2>&1; then
sudo yum install -y python3 python3-pip
else
echo "No known package manager found. Please install Python3 manually."
exit 1
fi
elif [ "$osfamily" = "darwin" ]; then
# macOS
if command -v brew >/dev/null 2>&1; then
brew update
brew install python3
else
echo "Homebrew not found. Please install Homebrew or Python3 manually."
exit 1
fi
elif [ "$osfamily" = "windows" ]; then
echo "Windows environment detected. Please install Python3 manually (e.g. via choco)."
# Windows coming soon
fi
else
echo "Python3 is already installed."
fi

if ! command -v pip3 >/dev/null 2>&1; then
echo "pip3 not found. Please ensure python3-pip is installed."
exit 1
fi


if ! command -v ansible >/dev/null 2>&1; then
echo "Ansible not found. Installing via pip3..."
pip3 install --user ansible
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.profile
source ~/.profile
else
echo "Ansible is already installed."
fi

echo "Python3 and Ansible installation completed."
}

install_dependencies
install_slv
cp -r ~/.slv/template/$VERSION/jinja/testnet-validator ~/.slv/testnet-validator

77 changes: 70 additions & 7 deletions sh/install
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

VERSION="0.4.0"
VERSION="0.4.1"
BASE_URL="https://storage.slv.dev/slv"

detect_platform() {
Expand All @@ -28,6 +28,11 @@ install_slv() {
mkdir -p "$HOME/.slv"
mkdir -p "$HOME/.slv/keys"

if [ "$platform" == "x86_64-pc-windows-msvc" ]; then
INSTALL_DIR="$HOME/.local/bin"
mkdir -p "$INSTALL_DIR"
fi

echo "Temporary directory: $TEMP_DIR"

echo "Downloading slv from $DOWNLOAD_URL..."
Expand All @@ -45,9 +50,6 @@ install_slv() {
echo "Copying templates to $HOME/.slv/template"

SLV_FILE="$TEMP_DIR/slv-x86_64-apple-darwin-exe"
if [ "$platform" = "x86_64-unknown-linux-gnu" ]; then
SLV_FILE="$TEMP_DIR/slv-x86_64-unknown-linux-gnu-exe"
fi
TEMPLATE_DL_DIR="$HOME/.slv/"

if [ ! -f "$SLV_FILE" ]; then
Expand All @@ -61,8 +63,12 @@ install_slv() {
sudo mkdir -p "$INSTALL_DIR"
fi

sudo mv "$SLV_FILE" "$INSTALL_DIR/slv"
sudo chmod +x "$INSTALL_DIR/slv"
if [ "$platform" == "x86_64-pc-windows-msvc" ]; then
sudo mv "$SLV_FILE" "$INSTALL_DIR/slv.exe"
else
sudo mv "$SLV_FILE" "$INSTALL_DIR/slv"
sudo chmod +x "$INSTALL_DIR/slv"
fi

echo "Cleaning up..."
rm -rf "$TEMP_DIR"
Expand All @@ -71,8 +77,65 @@ install_slv() {

echo "slv has been installed successfully!"
echo "Ensure $INSTALL_DIR is in your PATH."
if [ "$platform" == "x86_64-pc-windows-msvc" ]; then
echo "Windows users, add $INSTALL_DIR to your PATH manually."
fi
mkdir -p ~/.slv/keys
slv -P
}

install_slv
install_dependencies() {
if ! command -v python3 >/dev/null 2>&1; then
echo "Python3 not found. Installing..."
if [ "$osfamily" = "linux" ]; then
# Distribution check
# Ubuntu/Debian
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y python3 python3-pip
# RHEL/CentOS
elif command -v yum >/dev/null 2>&1; then
sudo yum install -y python3 python3-pip
else
echo "No known package manager found. Please install Python3 manually."
exit 1
fi
elif [ "$osfamily" = "darwin" ]; then
# macOS
if command -v brew >/dev/null 2>&1; then
brew update
brew install python3
else
echo "Homebrew not found. Please install Homebrew or Python3 manually."
exit 1
fi
elif [ "$osfamily" = "windows" ]; then
echo "Windows environment detected. Please install Python3 manually (e.g. via choco)."
# Windows coming soon
fi
else
echo "Python3 is already installed."
fi

if ! command -v pip3 >/dev/null 2>&1; then
echo "pip3 not found. Please ensure python3-pip is installed."
exit 1
fi


if ! command -v ansible >/dev/null 2>&1; then
echo "Ansible not found. Installing via pip3..."
pip3 install --user ansible
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.profile
source ~/.profile
else
echo "Ansible is already installed."
fi

echo "Python3 and Ansible installation completed."
}

install_dependencies
install_slv
cp -r ~/.slv/template/$VERSION/jinja/testnet-validator ~/.slv/testnet-validator

69 changes: 69 additions & 0 deletions template/0.4.1/ansible/cmn/create_user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
- name: Create solv user with specific password and configure SSH access
hosts: all
become: yes
vars:
home_paths_authorized_keys: /home/solv/.ssh/authorized_keys
ansible_remote_tmp: /tmp/ansible_tmp
local_public_key_path: "{{ lookup('env', 'HOME') + '/.ssh/id_rsa.pub' }}"
vars_files:
- ~/.slv/config.pwd.yml
tasks:
- name: Ensure solv user exists
user:
name: solv
password: "{{ encrypted_password }}"
state: present
shell: /bin/bash

- name: Ensure .ssh directory exists for solv user
file:
path: /home/solv/.ssh
state: directory
owner: solv
group: solv
mode: "0700"

- name: Add local public key to authorized_keys
lineinfile:
path: "{{ home_paths_authorized_keys }}"
line: "{{ lookup('file', local_public_key_path) }}"
create: yes
owner: solv
group: solv
mode: "0600"

- name: Generate SSH key for solv user if not exists
shell: su - solv -c "ssh-keygen -t rsa -b 4096 -N '' -f /home/solv/.ssh/id_rsa"
args:
creates: /home/solv/.ssh/id_rsa

- name: Ensure correct permissions for .ssh directory
file:
path: /home/solv/.ssh
state: directory
owner: solv
group: solv
mode: "0700"

- name: Ensure correct permissions for authorized_keys
file:
path: "{{ home_paths_authorized_keys }}"
state: file
owner: solv
group: solv
mode: "0600"

- name: Add solv user to sudoers group
user:
name: solv
groups: sudo
append: yes

- name: Configure sudoers file for solv user (no password required)
lineinfile:
path: /etc/sudoers
state: present
regexp: '^solv ALL=\(ALL\) NOPASSWD:ALL'
line: "solv ALL=(ALL) NOPASSWD:ALL"
validate: "visudo -cf %s"
13 changes: 13 additions & 0 deletions template/0.4.1/ansible/cmn/find_unmounted_disks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

find_unmounted_nvme_disks() {
lsblk -nr -o NAME,TYPE,SIZE,MOUNTPOINT | awk '
$2 == "disk" &&
$1 ~ /^nvme/ &&
(($3 ~ /G$/ && substr($3, 1, length($3)-1) + 0 >= 800) ||
($3 ~ /T$/ && substr($3, 1, length($3)-1) + 0 >= 0.8)) &&
($4 == "" || $4 ~ /^[[:space:]]*$/) &&
system("lsblk -nr -o TYPE /dev/" $1 " | grep -q part") != 0 {print $1}'
}

find_unmounted_nvme_disks
27 changes: 27 additions & 0 deletions template/0.4.1/ansible/cmn/install_agave.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
- name: Install Agave
hosts: all
become: true
vars_files:
- ~/.slv/inventory.testnet.validators.yml
vars:
solana_bin_dir: '/home/solv/.local/share/solana/install/active_release/bin'
tasks:
- name: Install Agave from the specified version
shell: |
tag=v{{ hostvars[inventory_hostname].solana_version }}
curl -sSfL https://release.anza.xyz/${tag}/install | sh
args:
executable: /bin/bash
environment:
PATH: '{{ solana_bin_dir }}:{{ ansible_env.PATH }}'
HOME: '/home/solv'

- name: Verify Solana installation
shell: '{{ solana_bin_dir }}/solana --version'
register: solana_version_check
failed_when: solana_version_check.rc != 0

- name: Debug Solana version check
debug:
var: solana_version_check.stdout
Loading

0 comments on commit e9e9323

Please sign in to comment.