Last active
February 19, 2024 13:00
-
-
Save kriipke/f70919d5a4a1096011f4e7f2fa7dbe05 to your computer and use it in GitHub Desktop.
Ubuntu-bootstrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eux | |
ENV_DIR=/etc/profile.d | |
ENV_RC=/etc/profile.d/sh.local | |
ZSH_CUSTOM_DIR=/etc/zsh/custom | |
ZSH_SHARED_DIR=/usr/share/zsh | |
VIM_RUNTIME=/usr/share/vim/vimfiles | |
ID_LIKE=$(. /etc/os-release; echo ${ID_LIKE:-$ID}) | |
if echo $ID_LIKE | grep -qE '(fedora|rhel|centos)' ; then | |
PKG_CMD="$(command -v dnf || command -v yum)" | |
elif echo $ID_LIKE | grep -qE '(debian|ubuntu)'; then | |
PKG_CMD="$(command -v apt || command -v apt-get)" | |
else | |
PKG_CMD= | |
fi | |
command -v tput &>/dev/null || $PKG_CMD install -y ncurses | |
PS4='$(tput setaf 4)$(printf "%-12s\\t%.3fs\\t@line\\t%-10s" $(date +%T) $(echo $(date "+%s.%3N")-'$(date "+%s.%3N")' | bc ) $LINENO)$(tput sgr 0)' | |
ensure () { | |
if [ $? -eq 2 ]; then | |
COMMAND=$1 | |
PACKAGE=$2 | |
elif [ $? -eq 1 ]; then | |
COMMAND=$1 | |
PACKAGE=$1 | |
fi | |
command -v ${COMMAND:?} 2>/dev/null \ | |
|| ${PKG_CMD:?} install -y ${PACKAGE:?} | |
} | |
get_binary_path () { | |
# Usage: get_binary_path vim | |
if [ $? -eq 1 ]; then | |
COMMAND=$1 | |
PACKAGE=$1 | |
command -v $1 2>/dev/null || true | |
fi | |
} | |
# | |
# [START] CONFIGURE VIRTUAL TERMINAL | |
# | |
# make sure you're not in a docker container before calling systemctl | |
if ! [ -f /.dockerenv ]; then | |
if [ -f /usr/lib/kbd/consolefonts/Lat2-Terminus16* ]; then | |
cat > /etc/vconsole.conf <<EOF | |
KEYMAP="us" | |
FONT="Lat2-Terminus16" | |
EOF | |
systemctl restart systemd-vconsole-setup | |
fi | |
fi | |
# | |
# Configure: vim | |
# | |
echo 'Configuring vim.' | |
ensure vim | |
VIM_POLYGLOT_RELEASE='v4.17.0' | |
VIM_POLYGLOT_REPO='https://github.com/sheerun/vim-polyglot' | |
TEST_CMD="vim -c ':set t_ti= t_te= nomore' -c 'scriptnames|q!' 2>/dev/null| grep -q vim-polyglot" | |
VIM_PLUG_DIR=/usr/share/vim/vimfiles/pack/plugins | |
printf "Installing vim plugin: vim-polyglot (%s)\n" "${VIM_POLYGLOT_RELEASE:?}" | |
( | |
mkdir -p $VIM_PLUG_DIR/start/vim-polyglot | |
cd $VIM_PLUG_DIR/start/vim-polyglot || exit 1 | |
curl -sSL "$VIM_POLYGLOT_REPO/archive/$VIM_POLYGLOT_RELEASE.tar.gz" \ | |
| tar xvz --strip=1 | |
) | |
cat >> /etc/vimrc <<'EOD' | |
set belloff=all | |
if &t_Co > 2 || has ("gui_running") | |
colorscheme default | |
syntax on | |
endif | |
filetype on | |
EOD | |
cat >> "${ENV_RC:?}" <<'EOD' | |
export EDITOR=vim | |
export VISUAL=vim | |
EOD | |
eval "$TEST_CMD" || { | |
printf "Failed to install vim-polyglot plugin (%s) for vim\n:" "$VIM_POLYGLOT_RELEASE" | |
printf "Command '%s' failed with status %s.\n" "$TEST_CMD" "$?" | |
exit 1 | |
} | |
# | |
# Install: fzf | |
# | |
# curl -sSLO https://github.com/junegunn/fzf/releases/download/0.32.1/fzf-0.32.1-linux_armv7.tar.gz | |
VIM_PLUG_DIR=/usr/share/vim/vimfiles/pack/plugins | |
mkdir -p $VIM_PLUG_DIR | |
FZF_VIM_DIR="$VIM_PLUG_DIR/start/fzf/plugin" | |
mkdir -p $FZF_VIM_DIR | |
ZSH_SHARED_DIR=${ZSH_SHARED_DIR:-/usr/share/zsh/site-functions} | |
ZSH_CUSTOM_DIR=${ZSH_CUSTOM_DIR:-/etc/zsh/custom} | |
mkdir -p $ZSH_CUSTOM_DIR $ZSH_SHARED_DIR | |
FZF_RELEASE='0.39.0' | |
FZF_REPO='https://github.com/junegunn/fzf' | |
TEST_CMD_FZF='fzf --version' | |
TEST_CMD_TMUX='fzf-tmux --version' | |
if [ `arch` == 'aarch64' ]; then | |
FZF_ARCHIVE="fzf-$FZF_RELEASE-linux_arm64.tar.gz" | |
else | |
FZF_ARCHIVE="fzf-$FZF_RELEASE-linux_amd64.tar.gz" | |
fi | |
printf "Installing command: fzf (%s)\n" "$FZF_RELEASE" | |
( | |
cd /tmp | |
curl -L "$FZF_REPO/releases/download/$FZF_RELEASE/$FZF_ARCHIVE" | tar xvz | |
install fzf /usr/bin | |
) | |
printf "Installing command: fzf-tmux (%s)\n" "$FZF_RELEASE" | |
( | |
curl -L "${FZF_REPO}/archive/refs/tags/${FZF_RELEASE}.tar.gz" | tar xvz | |
cd /tmp | |
curl -L "$FZF_REPO/archive/$FZF_RELEASE.tar.gz" | tar xvz \ | |
&& cd "fzf-$FZF_RELEASE" \ | |
&& install bin/fzf-tmux /usr/bin | |
eval "$TEST_CMD_TMUX" | grep -q "$FZF_RELEASE" || { | |
printf "\nFailed to install fzf-tmux (%s):\n" "$FZF_RELEASE" | |
printf "Command '%s' failed with status %s.\n\n" "$TEST_CMD_TMUX" "$?" | |
exit 1 | |
} | |
) | |
printf "Installing integrations: vim & zsh plugins for fzf (%s)\n" "$FZF_RELEASE" | |
( | |
cd /tmp/fzf-$FZF_RELEASE | |
cp ./plugin/fzf.vim $FZF_VIM_DIR/ | |
cp ./shell/completion.zsh ${ZSH_SHARED_DIR:?}/vendor-completions/_fzf | |
cp ./shell/key-bindings.zsh ${ZSH_CUSTOM_DIR:?}/fzf.zsh | |
install ./bin/fzf-tmux /usr/bin | |
cat > /etc/profile.d/fzf.sh <<'EOF' | |
export FZF_TMUX_OPTS="-d 40%" | |
export FZF_CTRL_R_OPTS="--margin 15%,5%" | |
EOF | |
) | |
# | |
# zsh configration | |
# | |
ensure zsh | |
ZSH_CUSTOM_DIR=${ZSH_CUSTOM_DIR:-/etc/zsh/custom} | |
mkdir -p $ZSH_CUSTOM_DIR | |
cat >> /etc/zsh/zshrc <<'EOF' | |
unsetopt BEEP | |
setopt autocd | |
setopt autopushd | |
autoload -U history-search-end | |
zle -N history-beginning-search-backward-end history-search-end | |
zle -N history-beginning-search-forward-end history-search-end | |
bindkey "^[[A" history-beginning-search-backward-end | |
bindkey "^[[B" history-beginning-search-forward-end | |
fpath+=( /etc/zsh/custom ) | |
autoload -U n | |
# Basic auto/tab complete: | |
autoload -U compinit | |
zstyle ':completion:*' menu select | |
zmodload zsh/complist | |
compinit | |
_comp_options+=(globdots) # Include hidden files. | |
autoload -U +X bashcompinit && bashcompinit | |
source /etc/bash_completion.d | |
source /usr/share/bash-completion/completions | |
# configure history retention | |
HISTSIZE=10000 # How many lines of history to keep in memory | |
SAVEHIST=10000 # Number of history entries to save to disk | |
HISTFILE=~/.zsh_history # Where to save history to disk | |
setopt appendhistory # Append history to the history file (no overwriting) | |
setopt sharehistory # Share history across terminals, e.g. when using tmux | |
setopt incappendhistory # Immediately append to the history file, not just when a term is killed | |
# Edit line in vim with ctrl-v: | |
autoload edit-command-line; zle -N edit-command-line | |
bindkey '^[v' edit-command-line | |
export LANG=en_US.UTF-8 | |
PROMPT='%n%F{cyan}@%m%f:%3~%F{cyan}%# %f' | |
. /etc/zsh/aliases.zsh | |
. /etc/zsh/complete.zsh | |
. ${ZSH_CUSTOM}/** | |
EOF | |
cat > /etc/zsh/aliases.zsh <<'EOF' | |
alias ll='ls -lh -F --group-directories-first --color=auto' | |
alias ls='ls -F --color=auto' | |
alias l='ls -F --color=auto' | |
alias vi='vim' | |
alias -g G='| grep -i' | |
alias -g H='| grep -zi' | |
alias -g L='| less' | |
alias d='dirs -v | head -10' | |
alias 1='cd -' | |
alias 2='cd -2' | |
alias 3='cd -3' | |
alias 4='cd -4' | |
alias 5='cd -5' | |
alias 6='cd -6' | |
alias 7='cd -7' | |
alias 8='cd -8' | |
alias 9='cd -9' | |
EOF | |
echo "# /etc/zsh/complete.zsh" > /etc/zsh/complete.zsh | |
usermod -s /usr/bin/zsh "$(whoami)" | |
touch /root/.zshrc | |
touch /etc/skel/.zshrc | |
# | |
# TMUX | |
# | |
# Configures tmux to automatically attach session upon login | |
# and detach session upon running "exit" with only a single | |
# pane/window open OR upon running "logout" with any amount | |
# of panes/windows open. | |
# | |
# To disable this functionality set TMUX_AUTO_ATTACH to any | |
# value other than 1. | |
# | |
echo 'Configuring tmux.' | |
command -v tmux 2>/dev/null || dnf install -y tmux | |
echo 'Enabling tmux auto-attach.' | |
for file in /root/.zprofile /etc/skel/.zprofile; do | |
cat >> "$file" <<'EOF' | |
## BEGIN TMUX AUTO-ATTACH FUNCTIONALITY | |
# | |
# The lines below cause a tmux session to automatically attach upon login. | |
# If a tmux session does not exist then one will automatically be created. | |
# | |
# For debugging and to prevent lock-out this feature is only enabled on tty1 | |
# by default. To change this, remove/modify the last condition in the if | |
# statement. | |
# | |
# The functionality provided by the code below is complemented by code | |
# placed in ~/.zshrc which logs the user off in a way that leaves the current | |
# tmux session intact, detached, and available for automatic attachment by the | |
# code below on next login. | |
# | |
# To disable the functionality provided by this code and the complementary | |
# code in ~/.zshrc either set TMUX_AUTO_ATTACH to a value other than 1 in | |
# ~/.zprofile below. If these files are inaccessible because the user is not | |
# logged in, log in on a tty other than tty1 and edit ~/.zprofile as mentioned. | |
TMUX_AUTO_ATTACH=1 | |
if [ -z "$TMUX" ] && [ "$TMUX_AUTO_ATTACH" -eq 1 ] && [ `tty` = '/dev/tty1' ]; then | |
[ -n "$SSH_CONNECTION" ] && TMUX_SESSION="ssh" || TMUX_SESSION="local" | |
tmux attach-session -t $TMUX_SESSION || tmux new -s $TMUX_SESSION | |
fi | |
## END TMUX AUTO-ATTACH FUNCTIONALITY | |
EOF | |
done | |
echo 'Configuring zsh to exit in a way that leaves tmux session intact.' | |
for file in /root/.zshrc /etc/skel/.zshrc; do | |
cat >> "$file" <<'EOF' | |
## BEGIN TMUX AUTO-ATTACH FUNCTIONALITY | |
# | |
# The lines below cause a tmux session to detach before a user logs off, | |
# allowing the tmux session to be to automatically attach upon logging back in. | |
# | |
# For debugging and to prevent lock-out this feature is only enabled on tty1 | |
# by default. To change this, remove/modify the last condition in the if | |
# statement. | |
# The code below over-writes some zsh defaults which control how, a shell is | |
# exited in such a way that the current tmux session is left intact. Namely, | |
# the complementary code over-writes the operation of CTRL-D as well as the | |
# zsh builtins 'logout' & 'exit' | |
# | |
# To disable the functionality provided by this code and the complementary | |
# code in ~/.zshrc either set TMUX_AUTO_ATTACH to a value other than 1 in | |
# ~/.zprofile below. If these files are inaccessible because the user is not | |
# logged in, log in on a tty other than tty1 and edit ~/.zprofile as mentioned. | |
# | |
if [ ${TMUX_AUTO_ATTACH:-0} = 1 ] && [ `tty` = '/dev/tty1' ]; then | |
function logoff { | |
tmux detach -P | |
} | |
function exit() { | |
if [ "$TMUX" ] && [ ${TMUX_AUTO_ATTACH:-0} = 1 ]; then | |
n_panes="$( tmux list-panes | wc -l )" | |
n_windows="$( tmux list-windows | wc -l )" | |
if [ $n_panes -gt 1 ] || [ $n_windows -gt 1 ]; then | |
unset -f exit && exit | |
else | |
logoff | |
fi | |
else | |
unset -f exit && exit | |
fi | |
} | |
zle -N exit | |
stty -a | tr ';' '\012' | grep -q 'eof = \^D' && stty eof undef | |
bindkey "^D" exit | |
fi | |
# | |
## END TMUX AUTO-ATTACH FUNCTIONALITY | |
EOF | |
done | |
cat > /etc/tmux.conf <<'EOF' | |
set -g status off | |
set -g pane-active-border-fg 'cyan' | |
set -g status-bg 'cyan' | |
EOF | |
# | |
# Install: grc | |
# * make sure zsh is installed first | |
# | |
GRC_RELEASE='1.13' | |
( | |
cd /tmp | |
curl -sL https://github.com/garabik/grc/archive/refs/tags/v$GRC_RELEASE.tar.gz | tar xfz - | |
cd grc-$GRC_RELEASE && ./install.sh | |
printf '\n%s' '[[ -s "/etc/grc.zsh" ]] && source /etc/grc.zsh' >> /etc/zshrc | |
printf '\n%s' 'GRC_ALIASES=true' '[[ -s "/etc/profile.d/grc.sh" ]] && source /etc/grc.sh' >> /c | |
) | |
# | |
# Install: nnn | |
# | |
ZSH_SHARED_DIR=${ZSH_SHARED_DIR:-/usr/share/zsh/site-functions} | |
ZSH_CUSTOM_DIR=${ZSH_CUSTOM_DIR:-/etc/zsh/custom} | |
mkdir -p $ZSH_CUSTOM_DIR | |
NNN_RELEASE='4.0' | |
NNN_REPO='https://github.com/jarun/nnn' | |
NNN_ARCHIVE="nnn-static-${NNN_RELEASE:?}.x86_64.tar.gz" | |
NNN_ENV_FILE=${ENV_DIR:-/etc/profile.d}/nnn.sh | |
NNN_ZSH_FILE=${ZSH_CUSTOM_DIR:?}/n.zsh | |
ADD_CONFIG_TO_SKEL=1 | |
TEST_CMD='n -V' | |
touch $NNN_ENV_FILE | |
chmod 0644 $NNN_ENV_FILE | |
chown root:root $NNN_ENV_FILE | |
printf "Installing command: nnn (%s)\n" "$NNN_RELEASE" | |
( | |
cd /tmp | |
curl -L "$NNN_REPO/releases/download/v$NNN_RELEASE/$NNN_ARCHIVE" | tar xvz | |
install nnn-static /usr/bin/nnn | |
) | |
cat > "$NNN_ENV_FILE" <<'EOF' | |
export NNN_OPENER NNN_OPTS \ | |
NNN_PLUG NNN_COLORS NNN_TRASH | |
USER_CFG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" | |
PLUGIN_DIR="${USER_CFG_HOME}/nnn/plugins" | |
NNN_COLORS="6138" | |
NNN_OPTS="adEPp" | |
NNN_PLUG='t:treeview;z:fzz;p:preview-tui' | |
# Set nuke as default file opener when using nnn | |
# also available as a standalone command | |
NNN_OPENER="${PLUGIN_DIR}/nuke" | |
# -c option tells NNN to not user an GUI opener | |
[ "$NNN_OPTS" != "${NNN_OPTS/*c*}" ] \ | |
&& NNN_OPTS="${NNN_OPTS}c" | |
EOF | |
cat >> "$NNN_ZSH_FILE" <<'EOF' | |
n () | |
{ | |
# Block nesting of nnn in subshells | |
if [ -n $NNNLVL ] && [ "${NNNLVL:-0}" -ge 1 ]; then | |
echo "nnn is already running" | |
return | |
fi | |
# The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set) | |
# To cd on quit only on ^G, remove the "export" as in: | |
# NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd" | |
# NOTE: NNN_TMPFILE is fixed, should not be modified | |
export NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd" | |
# Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn | |
# stty start undef | |
# stty stop undef | |
# stty lwrap undef | |
# stty lnext undef | |
nnn -${NNN_OPTS} "$@" | |
if [ -f "$NNN_TMPFILE" ]; then | |
source "$NNN_TMPFILE" | |
rm -f "$NNN_TMPFILE" > /dev/null | |
fi | |
} | |
zle -N n | |
bindkey '^[f' n | |
EOF | |
printf "Installing integrations: vim & zsh plugins for nnn (%s)\n" "$NNN_RELEASE" | |
( | |
cd /tmp | |
curl -L "$NNN_REPO/releases/download/v$NNN_RELEASE/nnn-v$NNN_RELEASE.tar.gz" | tar xz | |
cd "nnn-$NNN_RELEASE" | |
chmod 644 ./misc/auto-completion/zsh/_nnn | |
chown root.root ./misc/auto-completion/zsh/_nnn | |
cp ./misc/auto-completion/zsh/_nnn $ZSH_SHARED_DIR/vendor-completions | |
chmod 644 ./misc/quitcd/quitcd.bash_zsh | |
chown root.root ./misc/quitcd/quitcd.bash_zsh | |
cp ./misc/quitcd/quitcd.bash_zsh ${NNN_ZSH_FILE:?} | |
) | |
printf "Installing plugins: nnn (%s)\n" "$NNN_RELEASE" | |
( | |
cd /tmp/nnn-$NNN_RELEASE/plugins | |
sh ./getplugs | |
mkdir -pm 0700 "$HOME"/.local/bin | |
echo 'PATH=$PATH:~/.local/bin' >> "$HOME"/.zprofile | |
NNN_PLUGIN_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins" | |
ln -sf "$NNN_PLUGIN_DIR"/nuke "$HOME"/.local/bin/ | |
) | |
cat >> $NNN_ENV_FILE <<'EOF' | |
# configure z integration with nnn | |
export NNN_PLUG="z:fzz;${NNN_PLUG}" | |
# configure nuke as file opener | |
export NNN_OPTS="${NNN_OTS}c" | |
export NNN_OPENER="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke" | |
EOF | |
zsh -c 'eval $TEST_CMD || { | |
printf "\nFailed to install nnn (%s):\n" "$NNN_RELEASE" | |
printf "Command %%s failed with status %s.\n\n" "$TEST_CMD" "$?" | |
exit 1 | |
}' || exit 1 | |
# | |
# Install: bat | |
# | |
# NOTE: | |
#- The musl version of the release is included below for security reasons, as | |
#- it is a fully linked version of the binary while the the glibc binary is | |
#- self described as 'a "mostly" statically linked' binary, opening the door | |
#- for shared-object injection attacks. | |
BAT_RELEASE='0.18.0' | |
BAT_REPO='https://github.com/sharkdp/bat' | |
TEST_CMD='bat -V' | |
if [ `arch` == 'aarch64' ];then | |
BAT_ARCHIVE="bat-v$BAT_RELEASE-aarch64-unknown-linux-gnu.tar.gz" | |
else | |
BAT_ARCHIVE="bat-v$BAT_RELEASE-x86_64-unknown-linux-musl.tar.gz" | |
fi | |
printf "Installing command: bat (%s)\n" "$BAT_RELEASE" | |
( | |
cd /tmp | |
curl -sSL "$BAT_REPO/releases/download/v$BAT_RELEASE/$BAT_ARCHIVE" | tar xvz | |
cd "${BAT_ARCHIVE%.tar.gz}" | |
install bat /usr/bin/ | |
chmod 644 ./autocomplete/bat.zsh | |
chown root:root ./autocomplete/bat.zsh | |
mv ./autocomplete/bat.zsh /usr/share/zsh/site-functions/_bat | |
) | |
eval "$TEST_CMD" | grep -q "$BAT_RELEASE" || { | |
printf "\nFailed to install bat (%s):\n" "$BAT_RELEASE" | |
printf "Command '%s' failed with status %s.\n\n" "$TEST_CMD" "$?" | |
exit 1 | |
} | |
# | |
# | |
# Install: croc | |
# | |
echo "Installing croc." | |
CROC_RELEASE='9.1.1' | |
CROC_REPO='https://github.com/schollz/croc' | |
TEST_CMD='croc --version' | |
if [ `arch` == 'aarch64' ];then | |
CROC_ARCHIVE="croc_${CROC_RELEASE}_Linux-ARM64.tar.gz" | |
else | |
CROC_ARCHIVE="croc_${CROC_RELEASE}_Linux-64bit.tar.gz" | |
fi | |
printf "Installing command: croc (%s)\n" "$CROC_RELEASE" | |
( | |
cd /tmp | |
curl -sSL "$CROC_REPO/releases/download/v$CROC_RELEASE/$CROC_ARCHIVE" | tar xvz \ | |
&& install croc /usr/bin | |
) | |
eval "$TEST_CMD" | grep -q "$CROC_RELEASE" || { | |
printf "\nFailed to install croc (%s):\n" "$CROC_RELEASE" | |
printf "Command '%s' failed with status %s.\n\n" "$TEST_CMD" "$?" | |
exit 1 | |
} | |
# | |
# Install: fd | |
# | |
FD_RELEASE='8.4.0' | |
FD_REPO='https://github.com/sharkdp/fd' | |
TEST_CMD='fd -V' | |
if [ `arch` == 'aarch64' ];then | |
FD_ARCHIVE="fd-v$FD_RELEASE-aarch64-unknown-linux-gnu.tar.gz" | |
else | |
FD_ARCHIVE="fd-v$FD_RELEASE-x86_64-unknown-linux-gnu.tar.gz" | |
fi | |
printf "Installing command: fd (%s)\n" "$FD_RELEASE" | |
( | |
cd /tmp | |
curl -sSL "$FD_REPO/releases/download/v$FD_RELEASE/$FD_ARCHIVE" | tar xvz | |
cd fd-v$FD_RELEASE-*-unknown-linux-gnu | |
install fd /usr/bin/ | |
chmod 644 ./autocomplete/_fd | |
chown root.root ./autocomplete/_fd | |
mv ./autocomplete/_fd /usr/share/zsh/site-functions/ | |
) | |
eval "$TEST_CMD" | grep -q "$FD_RELEASE" || { | |
printf "\nFailed to install fd (%s):\n" "$FD_RELEASE" | |
printf "Command '%s' failed with status %s.\n\n" "$TEST_CMD" "$?" | |
} | |
# | |
# Install: lnav | |
# | |
# NOTE: | |
#- The musl version of the release is included below for security reasons, as | |
#- it is a fully linked version of the binary while the the glibc binary is | |
#- self described as 'a "mostly" statically linked' binary, opening the door | |
#- for shared-object injection attacks. | |
LNAV_RELEASE='0.9.0' | |
LNAV_REPO='https://github.com/tstack/lnav' | |
LNAV_BIN_ARCHIVE="lnav-$LNAV_RELEASE-musl-64bit.zip" | |
LNAV_SRC_ARCHIVE="lnav-$LNAV_RELEASE.tar.gz" | |
INSTALL_ADDITIONAL_FORMATS=1 | |
ADD_CONFIG_TO_SKEL=1 | |
TEST_CMD='lnav -V' | |
printf "Installing command: lnav (%s)\n" "$LNAV_RELEASE" | |
( | |
TMP_DIR=$(mktemp -d) | |
cd "$TMP_DIR" | |
curl -sSLO "$LNAV_REPO/releases/download/v$LNAV_RELEASE/$LNAV_BIN_ARCHIVE" | |
command -v unzip || $PKG_CMD install -y unzip | |
unzip -jod "$TMP_DIR" $LNAV_BIN_ARCHIVE lnav-$LNAV_RELEASE/lnav | |
install "$TMP_DIR"/lnav /usr/bin/ | |
mkdir -pm 0700 /root/.config/lnav | |
curl -sSL "$LNAV_REPO/releases/download/v$LNAV_RELEASE/$LNAV_SRC_ARCHIVE" \ | |
| tar -xvz --directory "$TMP_DIR" --strip=1 lnav-$LNAV_RELEASE/lnav.1 | |
install "$TMP_DIR"/lnav.1 /usr/share/man/man1/ | |
) | |
eval "$TEST_CMD" | grep -q `echo "${LNAV_RELEASE//./\\\.}"` || { | |
printf "Failed to install lnav (%s)\n:" "$LNAV_RELEASE" | |
printf "Command '%s' failed with status %s.\n" "$TEST_CMD" "$?" | |
exit 1 | |
} | |
if [ $INSTALL_ADDITIONAL_FORMATS -eq 1 ]; then | |
LNAV_FMTS_COMMIT='ac531c10d2c12c2f144e272af25d3a4768f4c861' | |
LNAV_FMTS_REPO='https://github.com/PaulWay/lnav-formats' | |
LNAV_FMTS_ARCHIVE="$LNAV_FMTS_COMMIT.zip" | |
FMTS_DIR=/root/.config/lnav/formats/installed | |
FMTS_TEST_CMD="find $FMTS_DIR/ -type f" | |
printf "Installing: PaulWay's lnav formats (%s)\n" "$LNAV_FMTS_COMMIT" | |
( | |
cd /tmp | |
curl -sSLo lnav_fmts.zip "$LNAV_FMTS_REPO/archive/$LNAV_FMTS_ARCHIVE" | |
unzip -jod /root/.config/lnav/formats/installed/ lnav_fmts.zip '*.json' | |
chown root.root $FMTS_DIR/* | |
mkdir -pm 0700 $FMTS_DIR | |
chmod 0600 $FMTS_DIR/* | |
eval "$FMTS_TEST_CMD" || { | |
printf "Failed to install lnav extra log formats (%s)\n:" "$LNAV_FMTS_COMMIT" | |
printf "Command '%s' failed with status %s.\n" "$FMTS_TEST_CMD" "$?" | |
exit 1 | |
} | |
if [ $ADD_CONFIG_TO_SKEL -eq 1 ]; then | |
FMTS_SKEL_DIR=/etc/skel/.config/lnav/formats/installed | |
FMTS_SKEL_TEST_CMD="find $FMTS_DIR/ -type f" | |
mkdir -pm 0700 $FMTS_SKEL_DIR | |
cd $FMTS_DIR | |
cp *.json $FMTS_SKEL_DIR | |
eval "$FMTS_SKEL_TEST_CMD" || { | |
printf "\nFailed to copy lnav extra log formats to /etc/skel (%s):\n" | |
printf "Command '%s' failed with status %s.\n\n" "$FMTS_TEST_CMD" "$?" | |
exit 1 | |
} | |
fi | |
) | |
fi | |
# | |
# NEW SCRIPT | |
# | |
# | |
# Install: ripgrep (rg) | |
# | |
# | |
RG_RELEASE='12.1.1' | |
RG_REPO='https://github.com/BurntSushi/ripgrep' | |
RG_ARCHIVE="ripgrep-$RG_RELEASE-x86_64-unknown-linux-musl.tar.gz" | |
TEST_CMD='rg -V' | |
printf "Installing command: rg (%s)\n" "$RG_RELEASE" | |
( | |
cd /tmp | |
curl -sSL "$RG_REPO/releases/download/$RG_RELEASE/$RG_ARCHIVE" | tar xvz | |
cd "ripgrep-$RG_RELEASE-x86_64-unknown-linux-musl" | |
install rg /usr/bin/ | |
chmod 644 ./complete/_rg | |
chown root.root ./complete/_rg | |
mv ./complete/_rg /usr/share/zsh/site-functions/ | |
) | |
eval $TEST_CMD | grep -q "$RG_RELEASE" || { | |
printf "\nFailed to install rg (%s):\n" "$RG_RELEASE" | |
printf "Command '%s' failed with status %s.\n\n" "$TEST_CMD" "$?" | |
exit 1 | |
} | |
# Install: z | |
Z_RELEASE='1.11' | |
Z_REPO_ROOT="https://raw.githubusercontent.com/rupa/z/v$Z_RELEASE" | |
Z_TARGET_DIR=/usr/share/z | |
TEST_CMD="test -f $HOME/.z" | |
printf "Installing command: z (%s)\n" "$Z_RELEASE" | |
( | |
cd /tmp | |
mkdir -p $Z_TARGET_DIR | |
curl -Lo $Z_TARGET_DIR/z.sh $Z_REPO_ROOT/z.sh | |
curl -Lo /usr/share/man/man1/z\.1 $Z_REPO_ROOT/z.1 | |
echo ". $Z_TARGET_DIR" >> "$HOME/.zshrc" | |
) | |
command -v git 2>/dev/null || dnf install -y git | |
curl -sSLO https://raw.github.com/petervanderdoes/gitflow/develop/contrib/gitflow-installer.sh | |
chmod +x gitflow-installer.sh | |
./gitflow-installer.sh install stable | |
# | |
# Cleanup | |
# | |
echo "remove the contents of /tmp and /var/tmp" | |
rm -rf /tmp/* /var/tmp/* | |
#echo "Force a new random seed to be generated" | |
#rm -f /var/lib/systemd/random-seed | |
#echo "Wipe netplan machine-id (DUID) so machines get unique ID generated on boot" | |
#truncate -s 0 /etc/machine-id | |
#echo "Clear the history so our install commands aren't there" | |
#rm -f /root/.wget-hsts | |
# # | |
# # Run AIDE to document the current state of the | |
# # system for reference later, run `aide --check` | |
# # to show what files have been added, removed | |
# # or modified since the image was created. | |
# # | |
# | |
# command -v aide 2>/dev/null || dnf install -y aide | |
# aide --init | |
# mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment