(feat) Update dotfile scripts & tooling
- Update & split scripts - Main package install script - Fish / environment install script - Dockerfile for testing locally
This commit is contained in:
4
.dockerignore
Normal file
4
.dockerignore
Normal file
@ -0,0 +1,4 @@
|
||||
.vscode
|
||||
workspace.code-workspace
|
||||
.git
|
||||
.venv
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,2 @@
|
||||
.vscode
|
||||
twaiceAWS.fish
|
||||
workspace.code-workspace
|
||||
64
1_main_setup.sh
Executable file
64
1_main_setup.sh
Executable file
@ -0,0 +1,64 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# run as root/sudo
|
||||
if [ "$EUID" -ne 0 ]
|
||||
then echo "Please run as root / sudo"
|
||||
exit
|
||||
fi
|
||||
|
||||
DOCKER_COMPOSE_VERSION=v2.23.0
|
||||
|
||||
# Update sources
|
||||
apt-get update
|
||||
|
||||
#tzdata region settings
|
||||
TZ_REGION=Europe
|
||||
TZ_ZONE=Berlin
|
||||
# make tzdata noninteractive on docker...
|
||||
echo "tzdata tzdata/Areas select $TZ_REGION" | debconf-set-selections
|
||||
echo "tzdata tzdata/Zones/$TZ_REGION select $TZ_ZONE" | debconf-set-selections
|
||||
DEBIAN_FRONTEND="noninteractive" apt install tzdata -y
|
||||
|
||||
# Upgrade System:
|
||||
apt-get upgrade -y
|
||||
|
||||
# install env packages
|
||||
apt-get install git fish build-essential jq vim curl sudo unzip fzf htop -y
|
||||
|
||||
# pyenv dependencies
|
||||
apt-get install python3-dev python3-setuptools python3-pip python3-venv python3-smbus pipx liblzma-dev libffi-dev libssl-dev openssl zlib1g-dev libsqlite3-dev tk-dev libreadline-dev libbz2-dev -y
|
||||
|
||||
# install docker stable, if this failes try below
|
||||
curl -fsSLo- https://get.docker.com | sh
|
||||
#curl -fsSLo- https://test.docker.com | sh
|
||||
|
||||
# install docker-compose
|
||||
curl -L https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
|
||||
chmod +x /usr/local/bin/docker-compose
|
||||
|
||||
# aws cli
|
||||
cd /tmp
|
||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
|
||||
unzip awscliv2.zip
|
||||
./aws/install
|
||||
rm awscliv2.zip
|
||||
rm -rf ./aws
|
||||
|
||||
# session manager plugin
|
||||
curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb" -o "session-manager-plugin.deb"
|
||||
dpkg -i session-manager-plugin.deb
|
||||
cd -
|
||||
|
||||
read -p "User that will be used after installation complete: " NEW_USER
|
||||
passwd $NEW_USER
|
||||
|
||||
# give user docker permissions
|
||||
usermod -aG docker $NEW_USER
|
||||
|
||||
echo "######################################"
|
||||
echo "# Changing default shell to fish now #"
|
||||
echo "# Please call ./2_fish_setup.sh #"
|
||||
echo "######################################"
|
||||
chsh $NEW_USER -s /usr/bin/fish
|
||||
sudo -i -u $NEW_USER fish
|
||||
72
2_fish_setup.sh
Executable file
72
2_fish_setup.sh
Executable file
@ -0,0 +1,72 @@
|
||||
#!/bin/fish
|
||||
|
||||
set PYTHON_VERSION 3.11.6
|
||||
set NODE_VERSION lts/hydrogen
|
||||
|
||||
# dont run as root/sudo
|
||||
if [ "$EUID" -eq 0 ]
|
||||
then echo "Please do not run as root / sudo"
|
||||
exit 1
|
||||
end
|
||||
|
||||
# install rust toolchain
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
||||
|
||||
# install pyenv
|
||||
git clone https://github.com/pyenv/pyenv.git $HOME/.pyenv
|
||||
|
||||
# install nvm
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
|
||||
|
||||
# install fzf from source
|
||||
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
|
||||
bash ~/.fzf/install --no-update-rc --completion --key-bindings
|
||||
|
||||
# install fisher
|
||||
curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install jorgebucaran/fisher
|
||||
|
||||
# copy fish config
|
||||
if test -f "~/.config/fish/functions/config.fish"; then
|
||||
echo "config.fish already exist, please rename to continue."
|
||||
exit 1
|
||||
end
|
||||
cp fish/config.fish ~/.config/fish/
|
||||
|
||||
# copy fishfile
|
||||
if test -f "~/.config/fish/fish_plugins"; then
|
||||
echo "fish_plugins already exist, please rename to continue."
|
||||
exit 1
|
||||
end
|
||||
cp fish/fish_plugins ~/.config/fish/
|
||||
|
||||
# setup pyenv, cargo + local bin paths in fish
|
||||
mkdir $HOME/.local/bin
|
||||
set -Ux PYENV_ROOT $HOME/.pyenv
|
||||
fish_add_path $PYENV_ROOT/bin
|
||||
fish_add_path $HOME/.local/bin
|
||||
fish_add_path $HOME/.cargo/bin
|
||||
|
||||
# install packages from fishfile
|
||||
fisher update
|
||||
|
||||
cp -R fish/theme-t31m/functions/* ~/.config/fish/functions/
|
||||
|
||||
# install node via nvm
|
||||
nvm install $NODE_VERSION
|
||||
nvm alias default $NODE_VERSION
|
||||
|
||||
# Install Python
|
||||
pyenv install $PYTHON_VERSION
|
||||
# pip install --upgrade pip
|
||||
|
||||
# Install pipx for future non-user local packages
|
||||
pipx ensurepath
|
||||
|
||||
# pipx completions
|
||||
pipx completions
|
||||
register-python-argcomplete --shell fish pipx >~/.config/fish/completions/pipx.fish
|
||||
|
||||
# cp vimrc
|
||||
echo "Installing .vimrc"
|
||||
cp dot.vimrc $HOME/.vimrc
|
||||
|
||||
18
Dockerfile
Normal file
18
Dockerfile
Normal file
@ -0,0 +1,18 @@
|
||||
FROM ubuntu:mantic
|
||||
|
||||
ARG USER=testuser
|
||||
|
||||
RUN apt-get update && apt-get upgrade -y && \
|
||||
apt-get install git fish build-essential jq vim curl sudo unzip fzf htop \
|
||||
python3-dev python3-setuptools python3-pip python3-venv python3-smbus pipx liblzma-dev libffi-dev \
|
||||
libssl-dev openssl zlib1g-dev libsqlite3-dev tk-dev libreadline-dev libbz2-dev locales -y \
|
||||
&& rm -rf /var/lib/apt/lists/* && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
|
||||
|
||||
ENV LANG en_US.utf8
|
||||
|
||||
RUN useradd -m -s /usr/bin/bash $USER
|
||||
RUN usermod -aG sudo $USER
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ENTRYPOINT [ "/bin/bash" ]
|
||||
@ -11,6 +11,13 @@ T31M Dotfiles Repository
|
||||
### Contents ###
|
||||
* FiSH Shell Setup & Configuration
|
||||
* Theme/Prompt Based heavily on: omf/theme-sushi check it out
|
||||
* NVM + NVM FiSH support
|
||||
* NVM + Pyenv / PipX / AWS FiSH support
|
||||
* edc/bass
|
||||
* fzf
|
||||
|
||||
### Test in Docker
|
||||
|
||||
There are some runtime issues due to mounting of .git folder when executing container for test installation !
|
||||
|
||||
* `docker build --build-arg USER=*your user* -t fish-test .`
|
||||
* `docker run --rm -it -v (pwd):/app --mount type=volume,dst=/app/.git --name fish-test fish-test`
|
||||
@ -1,7 +1,8 @@
|
||||
set -Ux PYENV_ROOT $HOME/.pyenv
|
||||
set -Ux fish_user_paths $PYENV_ROOT/bin $fish_user_paths
|
||||
if status is-interactive
|
||||
# Commands to run in interactive sessions can go here
|
||||
|
||||
# pyenv init
|
||||
if command -v pyenv 1>/dev/null 2>&1
|
||||
pyenv init - | source
|
||||
end
|
||||
end
|
||||
@ -1,4 +1,3 @@
|
||||
jorgebucaran/fisher
|
||||
edc/bass
|
||||
jethrokuan/fzf
|
||||
FabioAntunes/fish-nvm
|
||||
|
||||
4
fish/theme-t31m/functions/cdk2.fish
Normal file
4
fish/theme-t31m/functions/cdk2.fish
Normal file
@ -0,0 +1,4 @@
|
||||
# Defined in - @ line 1
|
||||
function cdk --wraps='npx aws-cdk@2.x' --description 'alias cdk=npx aws-cdk@2.x'
|
||||
npx aws-cdk@2.x $argv;
|
||||
end
|
||||
12
fish/theme-t31m/functions/envsource.fish
Normal file
12
fish/theme-t31m/functions/envsource.fish
Normal file
@ -0,0 +1,12 @@
|
||||
# Place this in your Fish functions folder to make it available immediately
|
||||
# e.g. ~/.config/fish/functions/envsource.fish
|
||||
#
|
||||
# Usage: envsource <path/to/env>
|
||||
|
||||
function envsource
|
||||
for line in (cat $argv | grep -v '^#')
|
||||
set item (string split -m 1 '=' $line)
|
||||
set -gx $item[1] $item[2]
|
||||
echo "Exported key $item[1]"
|
||||
end
|
||||
end
|
||||
@ -18,7 +18,7 @@ function ssm_tunnel --description 'Access private AWS ressources via native SSM
|
||||
--query "Reservations[].Instances[?State.Name == 'running'].InstanceId[]"\
|
||||
--output text)
|
||||
|
||||
# AWS Remote host i.e internal.s.twaice / dualstack.internal-stg-s-inter-9ov8h1o4saoa-793915940.eu-west-1.elb.amazonaws.com
|
||||
# AWS Remote host i.e AWS Remote host i.e internal.x.yourdns / xxx.eu-west-1.elb.amazonaws.com
|
||||
set REMOTE_HOST (string split -f1 : $argv[1])
|
||||
set REMOTE_PORT (string split -f2 : $argv[1])
|
||||
# Local port to bind for forwarding
|
||||
@ -36,9 +36,8 @@ function ssm_tunnel --description 'Access private AWS ressources via native SSM
|
||||
echo "Tunneling Session Exited."
|
||||
end
|
||||
|
||||
# This function is for Platform Admin / Infrastructure users only.
|
||||
# @TODO: It still utilized the old style of ssm tunneling -> needs c&p of new style as well
|
||||
function ssm_tunnel_admin --description 'access private AWS ressources via Bastion Host'
|
||||
# This function is for custom & higher privileged users only.
|
||||
function ssm_tunnel_admin --description 'Access private AWS ressources via native SSM port forwarding through bastion'
|
||||
|
||||
if test (count $argv) -lt 2
|
||||
echo "Provide an Host:Port Mapping & an Local Port"
|
||||
@ -56,28 +55,20 @@ function ssm_tunnel_admin --description 'access private AWS ressources via Basti
|
||||
--query "Reservations[].Instances[?State.Name == 'running'].InstanceId[]"\
|
||||
--output text)
|
||||
|
||||
# AWS Remote host i.e elastic.aws.com:80
|
||||
set REMOTE_HOST $argv[1]
|
||||
|
||||
# Ports to bind for forwarding
|
||||
# AWS Remote host i.e internal.x.yourdns / xxx.eu-west-1.elb.amazonaws.com
|
||||
set REMOTE_HOST (string split -f1 : $argv[1])
|
||||
set REMOTE_PORT (string split -f2 : $argv[1])
|
||||
# Local port to bind for forwarding
|
||||
set LOCAL_PORT $argv[2]
|
||||
set REM_PORT (math (random) % 65535 + 2000)
|
||||
set TIMEOUT 21600 #seconds until forwarding session times out (48h max)
|
||||
|
||||
# make sure jq is installed
|
||||
# Start socat on the remote server
|
||||
set CMD "'sudo socat TCP4-LISTEN:$REM_PORT,reuseaddr,fork TCP4:$REMOTE_HOST'"
|
||||
set CMD_INVOC_ID (aws ssm send-command --instance-ids $INSTANCE_ID \
|
||||
--document-name 'AWS-RunShellScript' \
|
||||
--parameters "commands=$CMD,executionTimeout=$TIMEOUT" --output json | jq -r '.Command.CommandId')
|
||||
# Seconds until forwarding session times out (6h max)
|
||||
set TIMEOUT 21600
|
||||
|
||||
# Start tunnel session
|
||||
echo "Starting Tunnel"
|
||||
aws ssm start-session --target $INSTANCE_ID \
|
||||
--document-name "AWS-StartPortForwardingSession" \
|
||||
--parameters "portNumber=$REM_PORT,localPortNumber=$LOCAL_PORT"
|
||||
--document-name "AWS-StartPortForwardingSessionToRemoteHost" \
|
||||
--parameters "host=[$REMOTE_HOST],portNumber=[$REMOTE_PORT],localPortNumber=[$LOCAL_PORT]"
|
||||
|
||||
# stop socat on the bastion
|
||||
aws ssm cancel-command --command-id $CMD_INVOC_ID
|
||||
echo "Command Cancelled Successfully."
|
||||
echo "Tunneling Session Exited."
|
||||
end
|
||||
@ -1,46 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
|
||||
# install nvm
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
|
||||
|
||||
# install pyenv
|
||||
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
|
||||
|
||||
# install fzf from source
|
||||
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
|
||||
bash ~/.fzf/install --no-update-rc --completion --key-bindings
|
||||
|
||||
# install fisher
|
||||
curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher $plugins
|
||||
|
||||
# copy fish config
|
||||
if test -f "~/.config/fish/functions/config.fish"; then
|
||||
echo "config.fish already exist, please rename to continue."
|
||||
exit 1
|
||||
fi
|
||||
cp fish/config.fish ~/.config/fish/functions/
|
||||
|
||||
# copy fishfile
|
||||
if test -f "~/.config/fish/fish_plugins"; then
|
||||
echo "fish_plugins already exist, please rename to continue."
|
||||
exit 1
|
||||
fi
|
||||
cp fish/fish_plugins ~/.config/fish/
|
||||
|
||||
echo "set --export PYENV_ROOT $HOME/.pyenv" > ~/.config/fish/conf.d/pyenv.fish
|
||||
|
||||
# install packages from fishfile
|
||||
fish -c "fisher install jorgebucaran/fisher"
|
||||
fish -c "fisher install (pwd)/fish/theme-t31m"
|
||||
fish -c "fisher install FabioAntunes/fish-nvm"
|
||||
fish -c "fisher update"
|
||||
|
||||
# set fish default shell
|
||||
echo "Change your default Shell to FiSH: chsh -s /usr/bin/fish"
|
||||
|
||||
# cp vimrc
|
||||
echo "Installing .vimrc"
|
||||
cp dot.vimrc ~/.vimrc
|
||||
|
||||
27
main.sh
27
main.sh
@ -1,27 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
USER=t31m
|
||||
|
||||
# update repos + system
|
||||
apt-get update && apt-get upgrade
|
||||
|
||||
# install env packages
|
||||
apt-get install git fish fzf build-essential jq vim curl -y
|
||||
|
||||
# pyenv dependencies ?
|
||||
apt-get install python3-dev python3-setuptools python3-pip python3-smbus libffi-dev libssl-dev openssl zlib1g-dev libsqlite3-dev tk-dev libreadline-dev libbz2-dev -y
|
||||
|
||||
# install docker stable, if this failes try below
|
||||
curl -fsSL https://get.docker.com | sh
|
||||
#curl -fsSL https://test.docker.com | sh
|
||||
|
||||
# install docker-compose
|
||||
# v1
|
||||
# curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
|
||||
# v2
|
||||
curl -L https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
|
||||
chmod +x /usr/local/bin/docker-compose
|
||||
|
||||
usermod -aG docker t31m
|
||||
|
||||
echo "Initial Setup Complete. Please run fish_setup.sh for env setup"
|
||||
Reference in New Issue
Block a user