From ccdde5f4424836fc8e9cc98c204510fed9612e70 Mon Sep 17 00:00:00 2001 From: hc Date: Wed, 25 Jun 2025 19:40:43 +0800 Subject: merged setup and contaienrs --- setup/core/install-packages.sh | 27 +++++++++++ setup/core/packages/install_claude.sh | 8 +++ setup/core/packages/install_rust.sh | 7 +++ setup/core/ssh.sh | 9 ++++ setup/core/vim.sh | 59 +++++++++++++++++++++++ setup/git/set-global_user.sh | 2 + setup/git/tools/git-ssh-wrapper.sh | 2 + setup/git/tools/usefulbutnotthatusefulidkwhattodo | 0 setup/port-forward/persistent-ssh.sh | 35 ++++++++++++++ setup/port-forward/rm_all_ssh_connections.sh | 4 ++ setup/port-forward/ssh-multiport-forward.sh | 44 +++++++++++++++++ setup/port-forward/ssh-port-forward.sh | 19 ++++++++ setup/setup.sh | 30 ++++++++++++ 13 files changed, 246 insertions(+) create mode 100755 setup/core/install-packages.sh create mode 100755 setup/core/packages/install_claude.sh create mode 100755 setup/core/packages/install_rust.sh create mode 100755 setup/core/ssh.sh create mode 100755 setup/core/vim.sh create mode 100755 setup/git/set-global_user.sh create mode 100755 setup/git/tools/git-ssh-wrapper.sh create mode 100644 setup/git/tools/usefulbutnotthatusefulidkwhattodo create mode 100755 setup/port-forward/persistent-ssh.sh create mode 100755 setup/port-forward/rm_all_ssh_connections.sh create mode 100755 setup/port-forward/ssh-multiport-forward.sh create mode 100755 setup/port-forward/ssh-port-forward.sh create mode 100755 setup/setup.sh (limited to 'setup') diff --git a/setup/core/install-packages.sh b/setup/core/install-packages.sh new file mode 100755 index 0000000..dd3e69d --- /dev/null +++ b/setup/core/install-packages.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Install core packages +sudo dnf install -y epel-release +#sudo dnf group install -y "Development Tools" +sudo dnf install -y nc openssl bat autossh tmux htop tar bmon gzip tree wget curl plocate nano vim unzip net-tools git python3 python3-pip make wireguard-tools usbutils yum +sudo dnf install -y xclip + +sudo dnf install -y gcc gcc-c++ +sudo dnf install -y java-latest-openjdk-devel +#sudo dnf install -y asio-devel boost-devel openssl-devel + +# Execute all package installation scripts +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +for script in "$SCRIPT_DIR/packages"/*.sh; do + if [ -f "$script" ]; then + "$script" + fi +done + +#install packages ml +#pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124 +#pip3 install transformers + +#sudo yum install -y python3-openstackclient s3fs-fuse awscli +#pip install jupyterlab python-swiftclient +#sudo dnf update -y diff --git a/setup/core/packages/install_claude.sh b/setup/core/packages/install_claude.sh new file mode 100755 index 0000000..bf47cd2 --- /dev/null +++ b/setup/core/packages/install_claude.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Install Node.js via nvm and Claude Code +curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" +nvm install 22 +npm install -g @anthropic-ai/claude-code \ No newline at end of file diff --git a/setup/core/packages/install_rust.sh b/setup/core/packages/install_rust.sh new file mode 100755 index 0000000..ec484a4 --- /dev/null +++ b/setup/core/packages/install_rust.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# Install Rust and Cargo tools +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +echo '[ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env"' >> ~/.bashrc +source "$HOME/.cargo/env" +cargo install cargo-clone-crate cargo-edit cargo-info evcxr_jupyter bacon du-dust \ No newline at end of file diff --git a/setup/core/ssh.sh b/setup/core/ssh.sh new file mode 100755 index 0000000..c8fb49d --- /dev/null +++ b/setup/core/ssh.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +echo "PasswordAuthentication no" | sudo tee -a /etc/ssh/sshd_config +echo "AllowTcpForwarding yes" | sudo tee -a /etc/ssh/sshd_config +echo "GatewayPorts yes" | sudo tee -a /etc/ssh/sshd_config +echo "AllowAgentForwarding yes" | sudo tee -a /etc/ssh/sshd_config + +git clone https://git.noml.ch/keys ~/keys +~/keys/add-ssh-keys.sh diff --git a/setup/core/vim.sh b/setup/core/vim.sh new file mode 100755 index 0000000..883a75e --- /dev/null +++ b/setup/core/vim.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +cd "$(dirname "${BASH_SOURCE[0]}")" || exit + +cat << EOF >> /etc/vimrc +augroup netcat_clipboard + au! + au TextYankPost * call system("openssl enc -aes-256-cbc -pbkdf2 -pass pass:YourPassword | nc -w 1 p.noml.ch 5023", @") +augroup END + +" Enable line wrapping +set wrap + +" Optional: Make wrapped lines easier to read by indenting them +set breakindent +set breakindentopt=shift:1 + +syntax on +set mouse=a +set expandtab +set shiftwidth=4 +set softtabstop=4 +set tabstop=4 +set noautoindent +set nosmartindent +filetype plugin indent on + +set laststatus=2 " permanent status bar +set statusline=%F " shows full file path + +if (has("termguicolors")) + set termguicolors +endif + +"colorscheme murphy +colorscheme zellner + +" Ctrl+A: Move to the beginning of the line in INSERT mode +inoremap + +" Ctrl+E: Move to the end of the line in INSERT mode +inoremap + +" Ctrl+A: Move to the beginning of the line in NORMAL mode +nnoremap 0 + +" Ctrl+E: Move to the end of the line in NORMAL mode +nnoremap $ + +set number +setlocal regexpengine=2 +set paste +set foldcolumn=12 + + +EOF + + + diff --git a/setup/git/set-global_user.sh b/setup/git/set-global_user.sh new file mode 100755 index 0000000..30e11eb --- /dev/null +++ b/setup/git/set-global_user.sh @@ -0,0 +1,2 @@ +git config --global user.email "hc@email.ch" +git config --global user.name "hc" diff --git a/setup/git/tools/git-ssh-wrapper.sh b/setup/git/tools/git-ssh-wrapper.sh new file mode 100755 index 0000000..dc23334 --- /dev/null +++ b/setup/git/tools/git-ssh-wrapper.sh @@ -0,0 +1,2 @@ +#!/bin/bash +ssh -v -A -o ForwardAgent=yes "$@" diff --git a/setup/git/tools/usefulbutnotthatusefulidkwhattodo b/setup/git/tools/usefulbutnotthatusefulidkwhattodo new file mode 100644 index 0000000..e69de29 diff --git a/setup/port-forward/persistent-ssh.sh b/setup/port-forward/persistent-ssh.sh new file mode 100755 index 0000000..36d14dd --- /dev/null +++ b/setup/port-forward/persistent-ssh.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +echo "selinux command is untested. copy paste systemd file if you want" +echo "reboot afterwards(selinux unset, need reboot to take effect, or just do sudo setenforce 0 for temp unset)" +echo "make sure /root/m exists" +echo "remember to change the remote port or host if needed" + +# disable selinux +sudo sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config + +sudo cat << 'EOF' > /etc/systemd/system/ssh-tunnel.service +[Unit] +Description=Persistent SSH Tunnel +After=network.target +StartLimitIntervalSec=0 + +[Service] +Type=simple +ExecStart=/usr/bin/ssh \ + -i /root/m \ + -o "ExitOnForwardFailure=yes" \ + -o "StrictHostKeyChecking=no" \ + -N -R 24:localhost:22 root@p.0nom.ch +Restart=always +RestartSec=10 +RemainAfterExit=no +KillMode=process + +[Install] +WantedBy=multi-user.target +EOF + +sudo chmod 600 /root/m +sudo systemctl daemon-reload +sudo systemctl enable --now ssh-tunnel diff --git a/setup/port-forward/rm_all_ssh_connections.sh b/setup/port-forward/rm_all_ssh_connections.sh new file mode 100755 index 0000000..f19300d --- /dev/null +++ b/setup/port-forward/rm_all_ssh_connections.sh @@ -0,0 +1,4 @@ +#!/bin/bash +ss -tnp | grep ':22' +ps -ef | grep sshd | grep -v grep | awk '{if($3!=1) print $2}' | xargs kill +#sudo systemctl restart sshd diff --git a/setup/port-forward/ssh-multiport-forward.sh b/setup/port-forward/ssh-multiport-forward.sh new file mode 100755 index 0000000..40d4ef6 --- /dev/null +++ b/setup/port-forward/ssh-multiport-forward.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# Check if at least one argument is provided +if [ $# -lt 1 ]; then + echo "Usage: $0 [additional_ports...]" + echo "Example: $0 5 80 443" + exit 1 +fi + +# First argument is the base number for port range +j=$1 +shift # Remove first argument from the list, leaving only additional ports + +HOST="root@p.0nom.ch" + +# Clean management port +echo "cleaning management port..." +ssh $HOST "ss -tunlp | grep :${j}022 | awk '{print $NF}' | sed 's/.*pid=\([^,]*\).*/\1/' | head -n1 | xargs kill -9" +echo "cleaning attempted." + +# Build the SSH command with all port forwards +SSH_CMD="ssh $HOST" + +# Add range-based port forwards (j000-j005) +for i in $(seq ${j}000 ${j}005); do + SSH_CMD+=" -R $i:localhost:$i" +done + +# Add management port forward +SSH_CMD+=" -R ${j}022:localhost:22" + +# Add additional individual port forwards from remaining arguments +for port in "$@"; do + SSH_CMD+=" -R $port:localhost:$port" +done + +# Execute the SSH command +eval $SSH_CMD + +echo "Port forwards are available on:" +echo "- Ports ${j}000-${j}005" +echo "- Management port ${j}022" +if [ $# -gt 0 ]; then + echo "- Additional ports: $@" +fi diff --git a/setup/port-forward/ssh-port-forward.sh b/setup/port-forward/ssh-port-forward.sh new file mode 100755 index 0000000..4483ef4 --- /dev/null +++ b/setup/port-forward/ssh-port-forward.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# opens 5 ports + +#file will be run from where the user executes the script +j=$1 +HOST="root@p.0nom.ch" + +# get the process holding the specified port and kill it +echo "cleaning management port..." +ssh $HOST "ss -tunlp | grep :${j}022 | awk '{print $NF}' | sed 's/.*pid=\([^,]*\).*/\1/' | head -n1 | xargs kill -9" +echo "cleaning attempted." + +ssh $HOST $(for i in $(seq ${j}000 ${j}005); do echo "-R $i:localhost:$i"; done; echo "-R ${j}022:localhost:22") + +echo "port forward is available on port {j}00x" + +#ideally port forward from 2 onwards, there seems to be a problem for 1000(or just change all to j001) +#jupyter lab --port=2001 --ip=0.0.0.0 diff --git a/setup/setup.sh b/setup/setup.sh new file mode 100755 index 0000000..1aecd1c --- /dev/null +++ b/setup/setup.sh @@ -0,0 +1,30 @@ +#!/bin/bash + + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +cd "$SCRIPT_DIR" || exit + +sudo tee -a /etc/bashrc > /dev/null << 'EOF2' +LS_COLORS=$LS_COLORS:'di=38;5;135:ex=00;32:' ; export LS_COLORS +PS1='[\[\033[01;32m\]\u\[\033[00m\]@\h \[\033[38;5;135m\]\W\[\033[00m\]]\$ ' +EOF2 +source /etc/bashrc + +sudo bash ./core/ssh.sh || { echo "Failed to configure SSH"; exit 1; } +sudo bash ./core/vim.sh || { echo "Failed to configure Vim"; exit 1; } +sudo bash ./core/install-packages.sh || { echo "Failed to install packages"; exit 1; } + +sudo timedatectl set-timezone Asia/Singapore + +# add check fro each component + +# then git clone work directory, or git clone altogether + +sudo dnf install -y ncurses-term nc # nc for vim +echo "export TERM=xterm-256color" >> ~/.bashrc +source ~/.bashrc +tput colors # shld be 256 + + + + -- cgit v1.2.3-70-g09d2