From c772724cacc7501a70bbac5764c7ba29a9e4218e Mon Sep 17 00:00:00 2001 From: DuckDuckWhale Date: Sun, 19 Mar 2023 22:14:45 -0700 Subject: [PATCH] Misc: Rust, Helix, tmux underline, bash, rg, ... Add: - Rust and Helix install/configure scripts - tmux curly underline with colors - Rocky SSH & Mosh setup - `asciinema` and `rg` - Mosh PPA for old Ubuntu systems - VirtualBox USB devices group - Add `~/.local/bin/` to path in .bashrc Update: - Use `~/.bash_login` instead of `~/.profile` for tmux on login and exec it - Rename `gnome-todo` to `endeavour` - Use new sshd alias - Reload instead of restarting sshd Remove: - Vim colorschemes and plugins - `.sh` extensions on executable scripts --- auto/{auto.sh => auto} | 18 ++--- auto/bash/{bash.sh => bash} | 13 +++- auto/git/{git.sh => git} | 0 auto/gnome/{gnome.sh => gnome} | 0 auto/home-chmod/{home-chmod.sh => home-chmod} | 0 auto/readline/{readline.sh => readline} | 0 auto/ssh/{ssh.sh => ssh} | 0 auto/tmux/.tmux.conf | 4 ++ auto/tmux/{tmux.sh => tmux} | 0 auto/vim/.vimrc | 7 -- auto/vim/vim | 2 + auto/vim/vim.sh | 4 -- manual/helix/helix | 65 +++++++++++++++++++ manual/rust/rust | 32 +++++++++ manual/rust/rust-configure | 64 ++++++++++++++++++ setup/rocky-setup.md | 8 +++ setup/ubuntu-setup.md | 12 ++-- system/sshd/sshd_config | 6 +- system/sshd/sshd_config-rhel | 16 +++++ 19 files changed, 221 insertions(+), 30 deletions(-) rename auto/{auto.sh => auto} (56%) rename auto/bash/{bash.sh => bash} (73%) rename auto/git/{git.sh => git} (100%) rename auto/gnome/{gnome.sh => gnome} (100%) rename auto/home-chmod/{home-chmod.sh => home-chmod} (100%) rename auto/readline/{readline.sh => readline} (100%) rename auto/ssh/{ssh.sh => ssh} (100%) rename auto/tmux/{tmux.sh => tmux} (100%) create mode 100755 auto/vim/vim delete mode 100755 auto/vim/vim.sh create mode 100755 manual/helix/helix create mode 100755 manual/rust/rust create mode 100755 manual/rust/rust-configure create mode 100644 setup/rocky-setup.md create mode 100644 system/sshd/sshd_config-rhel diff --git a/auto/auto.sh b/auto/auto similarity index 56% rename from auto/auto.sh rename to auto/auto index 8ee9086..a93521b 100755 --- a/auto/auto.sh +++ b/auto/auto @@ -1,32 +1,32 @@ -#!/bin/sh +#!/bin/sh -e cd ssh -./ssh.sh +./ssh cd .. cd bash -./bash.sh +./bash cd .. cd git -./git.sh +./git cd .. cd vim -./vim.sh +./vim cd .. cd gnome -./gnome.sh +./gnome cd .. cd readline -./readline.sh +./readline cd .. cd tmux -./tmux.sh +./tmux cd .. cd home-chmod -./home-chmod.sh +./home-chmod cd .. diff --git a/auto/bash/bash.sh b/auto/bash/bash similarity index 73% rename from auto/bash/bash.sh rename to auto/bash/bash index e02595e..d23a444 100755 --- a/auto/bash/bash.sh +++ b/auto/bash/bash @@ -9,6 +9,10 @@ export EDITOR='vim' export VISUAL='vim' export GPG_TTY=$(tty) +if [[ -d "$HOME/.local/bin" && ":$PATH:" != *":$HOME/.local/bin:"* ]]; then + PATH="$HOME/.local/bin:$PATH" +fi + # cool colored command prompt PS1='${debian_chroot:+($debian_chroot)}\[\e[01;38;5;11m\]\u\[\e[00;38;5;208m\]@\[\e[01;38;5;27m\]\h\[\e[00m\]:\[\e[00;38;5;45m\]\w\[\e[0m\]\$ ' @@ -32,20 +36,23 @@ popd() { cd . } EOF -cat >> ~/.profile << 'EOF' +if [ -f ~/.bash_profile ]; then + mv ~/.bash_profile ~/.bash_login +fi +cat >> ~/.bash_login << 'EOF' # custom if [ -z "$TMUX" ] && [ -n "$SSH_TTY" ]; then tput sc tput smso - echo -n 'tmux: space - shell: any key' + echo -n 'tmux: space / shell: any key' tput sgr0 read -rsN1 input tput rc tput el if [ "$input" = ' ' ]; then - tmux new -As default + exec tmux new -As default fi fi EOF diff --git a/auto/git/git.sh b/auto/git/git similarity index 100% rename from auto/git/git.sh rename to auto/git/git diff --git a/auto/gnome/gnome.sh b/auto/gnome/gnome similarity index 100% rename from auto/gnome/gnome.sh rename to auto/gnome/gnome diff --git a/auto/home-chmod/home-chmod.sh b/auto/home-chmod/home-chmod similarity index 100% rename from auto/home-chmod/home-chmod.sh rename to auto/home-chmod/home-chmod diff --git a/auto/readline/readline.sh b/auto/readline/readline similarity index 100% rename from auto/readline/readline.sh rename to auto/readline/readline diff --git a/auto/ssh/ssh.sh b/auto/ssh/ssh similarity index 100% rename from auto/ssh/ssh.sh rename to auto/ssh/ssh diff --git a/auto/tmux/.tmux.conf b/auto/tmux/.tmux.conf index 4c90caa..a907b3e 100644 --- a/auto/tmux/.tmux.conf +++ b/auto/tmux/.tmux.conf @@ -2,6 +2,10 @@ set -g clock-mode-style 12 set -g default-command "${SHELL}" set -g default-terminal "tmux-256color" set -as terminal-features ",xterm-256color:RGB" +# curly underline support +set -as terminal-overrides ',*:Smulx=\E[4::%p1%dm' +# underline colors - needs tmux-3.0 +set -as terminal-overrides ',*:Setulc=\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m' set -g history-limit 10000 set -g prefix C-q set -sg escape-time 25 diff --git a/auto/tmux/tmux.sh b/auto/tmux/tmux similarity index 100% rename from auto/tmux/tmux.sh rename to auto/tmux/tmux diff --git a/auto/vim/.vimrc b/auto/vim/.vimrc index 6c692f7..6ccf078 100644 --- a/auto/vim/.vimrc +++ b/auto/vim/.vimrc @@ -1,10 +1,3 @@ -" vim-plug -call plug#begin() -Plug 'chriskempson/base16-vim' -Plug 'dhruvasagar/vim-table-mode' -call plug#end() - -colorscheme base16-default-dark filetype plugin indent on syntax on diff --git a/auto/vim/vim b/auto/vim/vim new file mode 100755 index 0000000..9a06602 --- /dev/null +++ b/auto/vim/vim @@ -0,0 +1,2 @@ +#!/bin/sh +cp -i .vimrc ~ diff --git a/auto/vim/vim.sh b/auto/vim/vim.sh deleted file mode 100755 index 37b33ae..0000000 --- a/auto/vim/vim.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -cp -i .vimrc ~ -curl -Lo ~/.vim/autoload/plug.vim --create-dirs \ - https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim diff --git a/manual/helix/helix b/manual/helix/helix new file mode 100755 index 0000000..48c9a64 --- /dev/null +++ b/manual/helix/helix @@ -0,0 +1,65 @@ +#!/bin/sh -e +if ! command -v cargo > /dev/null; then + echo "Error: cargo not found" + exit 1 +fi +if ! command -v c++ > /dev/null; then + echo "Error: c++ not found" + exit 1 +fi +git clone https://github.com/helix-editor/helix helix-git +cd helix-git +cargo install --locked --path helix-term +mkdir -p ~/.config/helix +rm -rf runtime/grammars/sources +mv runtime ~/.config/helix +rm -rf helix-git +cat > ~/.config/helix/config.toml << 'EOF' +theme = "monokai_pro_ristretto" + +[editor] +auto-pairs = false +bufferline = "multiple" +rulers = [101] + +[editor.statusline] +left = ["mode", "spinner", "file-name"] +center = ["position-percentage"] +right = ["diagnostics", "selections", "position", "file-encoding", "file-line-ending"] + +[keys.normal] +space.z = ":reflow 100" + +[editor.soft-wrap] +enable = true +EOF +cat > ~/.config/helix/languages.toml << 'EOF' +[editor] +auto-pairs = false + +[[language]] +name = 'rust' +indent.unit = "\t" +indent.tab-width = 4 +config.checkOnSave = { command = "clippy" } + +[[language]] +name = "c" +indent = { tab-width = 4, unit = "\t" } + +[[language]] +name = "cpp" +indent = { tab-width = 4, unit = "\t" } + +[[language]] +name = 'java' +indent.unit = "\t" +indent.tab-width = 4 + +[[language]] +name = "markdown" +language-server = { command = "ltex-ls" } +file-types = ["md"] +scope = "source.markdown" +roots = [] +EOF diff --git a/manual/rust/rust b/manual/rust/rust new file mode 100755 index 0000000..8392463 --- /dev/null +++ b/manual/rust/rust @@ -0,0 +1,32 @@ +#!/bin/sh -e +if [ $# -gt 2 ]; then + echo "Usage: $0 [-f]" + exit 1 +fi +if [ "$1" = '-f' ]; then + force=true +fi +if ! command -v curl > /dev/null; then + echo "Error: curl not found" + exit 1 +fi +if command -v cargo > /dev/null && [ "$force" != true ]; then + echo "Error: rust already installed; use -f to force" + exit 1 +fi +curl --proto '=https' --tlsv1.3 -sSf https://sh.rustup.rs | sh -s -- -y +. "$HOME/.cargo/env" +rustup component add rust-analyzer +cat >> ~/.cargo/config.toml << 'EOF' +[registries.crates-io] +protocol = "sparse" +EOF +mkdir -p ~/.local/bin +cat >> ~/.local/bin/rust-analyzer << 'EOF' +#!/bin/sh +$(rustup which rust-analyzer) "$@" +EOF +chmod +x ~/.local/bin/rust-analyzer +cargo install cargo-auditable +cargo install --force cargo-auditable rust-script +./rust-configure diff --git a/manual/rust/rust-configure b/manual/rust/rust-configure new file mode 100755 index 0000000..4ad29b0 --- /dev/null +++ b/manual/rust/rust-configure @@ -0,0 +1,64 @@ +#!/usr/bin/env rust-script +//! ```cargo +//! [dependencies] +//! anyhow = "1.0.69" +//! dirs = "4.0.0" +//! ``` + +use anyhow::Context; + +use std::{ + fs::{self, File}, + io::{BufRead, BufReader}, +}; + +const ENV: &str = r#". "$HOME/.cargo/env""#; + +fn main() -> anyhow::Result<()> { + let home = dirs::home_dir().context("can't find home directory")?; + let mut login_path = home.clone(); + login_path.push(".bash_login"); + let login = BufReader::new(File::open(&login_path).context("failed to read ~/.bash_login")?); + let mut bashrc_path = home.clone(); + bashrc_path.push(".bashrc"); + let bashrc = BufReader::new(File::open(&bashrc_path).context("failed to read ~/.bashrc")?); + + let mut empty = false; + let mut new_bashrc = String::new(); + for line in bashrc.lines() { + let line = line.context("failed to read line in ~/.bashrc")?; + if line.is_empty() && empty { + continue; + } + empty = line.is_empty(); + if line != ENV { + new_bashrc.push_str(&line); + new_bashrc.push('\n'); + } + } + + let mut empty = false; + let mut new_login = String::new(); + for line in login.lines() { + let line = line.context("failed to read line in ~/.bash_login")?; + if line.is_empty() && empty { + continue; + } + empty = line.is_empty(); + if line != ENV { + new_login.push_str(&line); + new_login.push('\n'); + } + if line == "# custom" { + new_login.push('\n'); + new_login.push_str(ENV); + new_login.push_str("\n\n"); + empty = true; + } + } + + fs::write(bashrc_path, &new_bashrc).context("failed to write new .bashrc")?; + fs::write(login_path, &new_login).context("failed to write new .bash_login")?; + + Ok(()) +} diff --git a/setup/rocky-setup.md b/setup/rocky-setup.md new file mode 100644 index 0000000..ec860e0 --- /dev/null +++ b/setup/rocky-setup.md @@ -0,0 +1,8 @@ +# Rocky 9 Setup + +## OpenSSH Server & Mosh + +Same as Ubuntu, but: +- `s/apt/dnf/g` +- `s/sshd_config/sshd_config-rhel/g` +- `s/OpenSSH/SSH/g` diff --git a/setup/ubuntu-setup.md b/setup/ubuntu-setup.md index dd8fbea..16f984d 100644 --- a/setup/ubuntu-setup.md +++ b/setup/ubuntu-setup.md @@ -5,13 +5,13 @@ Here's my personal Ubuntu 22.10 setup. (Make sure to enable Wayland on Nvidia!) - Set font size in Terminal to 15 and initial column count to 85 - Must haves: - `sudo apt install curl ddcutil deja-dup earlyoom ffmpeg flatpak git gnome-boxes gnome-clocks \ - gnome-software-plugin-flatpak gnome-sound-recorder gnome-todo gnome-weather goldendict gparted \ + gnome-software-plugin-flatpak gnome-sound-recorder endeavour gnome-weather goldendict gparted \ keepassxc mosh mpv needrestart obs-studio shadowsocks-libev sshfs synaptic tmux trash-cli ufw \ - vim-gtk3 vlc wl-clipboard` + vim-gtk3 vlc wl-clipboard rg - Optional: - `sudo apt install gnome-firmware gnome-games gnome-nettool gnome-packagekit gnome-passwordsafe \ gnome-shell-pomodoro gnome-usage gthumb mkvtoolnix-gui openjdk-17-jdk pulseeffectsqpdf ranger \ - syncplay virtualbox-qt heif-gdk-pixbuf heif-thumbnailer` + syncplay virtualbox-qt heif-gdk-pixbuf heif-thumbnailer asciinema` - Remove all snaps: - ``` # if this command fails, unmount the snap mounts as reported by `mount` and try again @@ -49,6 +49,8 @@ Here's my personal Ubuntu 22.10 setup. (Make sure to enable Wayland on Nvidia!) - Cross compiling (?) - `gcc-aarch64-linux-gnu` - `gcc-arm-linux-gnueabihf` +- Virtualbox + - `sudo usermod -aG vboxusers $(whoami)` ## UFW @@ -228,6 +230,8 @@ sudo chmod -R 700 /opt/grub ## OpenSSH Server & Mosh ``` +# trusted PPA from mosh developer for truecolor support +# sudo add-apt-repository ppa:keithw/mosh-dev sudo apt install -y openssh-server mosh sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak sudo cp ../system/sshd/sshd_config /etc/ssh/sshd_config @@ -240,7 +244,7 @@ chmod 600 ~/.ssh/authorized_keys # insert your SSH public keys into the file sudo ufw limit OpenSSH sudo ufw allow 60001:60999/udp -sudo systemctl restart ssh +sudo systemctl reload sshd ``` ## See logs as admin diff --git a/system/sshd/sshd_config b/system/sshd/sshd_config index f990a91..f5f25b4 100644 --- a/system/sshd/sshd_config +++ b/system/sshd/sshd_config @@ -4,9 +4,9 @@ Port 22 PermitRootLogin no PubkeyAuthentication yes PasswordAuthentication no -# would be deprecated soon by -# KbdInteractiveAuthentication no -ChallengeResponseAuthentication no +# deprecated alias: +# ChallengeResponseAuthentication no +KbdInteractiveAuthentication no UsePAM yes AllowTcpForwarding yes X11Forwarding yes diff --git a/system/sshd/sshd_config-rhel b/system/sshd/sshd_config-rhel new file mode 100644 index 0000000..b87afb9 --- /dev/null +++ b/system/sshd/sshd_config-rhel @@ -0,0 +1,16 @@ +Include /etc/ssh/sshd_config.d/*.conf +AllowGroups ssh-users +Port 22 +PermitRootLogin no +PubkeyAuthentication yes +PasswordAuthentication no +# deprecated alias: +# ChallengeResponseAuthentication no +KbdInteractiveAuthentication no +AuthorizedKeysFile .ssh/authorized_keys +UsePAM yes +AllowTcpForwarding yes +X11Forwarding yes +PrintMotd no +AcceptEnv LANG LC_* COLORTERM +Subsystem sftp /usr/libexec/openssh/sftp-server