wip: dir organisation, script cleanup

This commit is contained in:
Andrejus
2021-04-09 22:04:33 +01:00
parent 576c73352c
commit 18689abd73
59 changed files with 508 additions and 647 deletions

78
scripts/_utils.sh Executable file
View File

@@ -0,0 +1,78 @@
#!/usr/bin/env bash
function apt_update {
sudo apt-get update
}
# @arg $1 debian package to install if not present
function apt_install {
if ! dpkg -s $1; then
sudo apt-get install -y $1
fi
}
# ---------------------------------------------------------------------------- #
# Helper functions
# ---------------------------------------------------------------------------- #
clean() {
sudo apt-get clean
}
update() {
apt_update
}
# @arg $1 packages to install
install() {
apt_install $1
refresh
}
# @arg $1 package list file to install
install_file() {
sudo apt-get install -qqyf $(cat $1)
refresh
}
# @arg $1 repository to add
add_ppa() {
sudo add-apt-repository -y ppa:$1
}
# @arg $1 url to add
# @arg $2 keyring to add to
add_key() {
curl -fsSL $1 \
| sudo gpg --no-default-keyring --keyring $2 --import -
}
# @arg $1 URL to run
# @arg $2 binary to use
run() {
curl -fsSL $1 | $2
}
# Symlink contents of source folder to target
#
# @arg $1 source folder
# @arg $2 target folder
link_folder() {
mkdir -p $2
cp -srf $1/. $2
}
# @arg $1 binary to test
not_installed() {
! [ -x "$(command -v $1)" ]
}
# Refreshes PATH
refresh() {
hash -r
}
# Add to PATH and refresh
# @arg $1 path to add to PATH
add_path() {
export PATH="$1:$PATH"
refresh
}

14
scripts/bootstrap.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -eo pipefail
NAME=`basename "$0"`
REL_DIR=`dirname "$0"`
ABS_DIR=`readlink -f $REL_DIR/../` # Scripts are nested inside of /scripts
# TODO
# Migrate to config.fish
rm $HOME/.bashrc
rm $HOME/.profile
echo "Stowing $ABS_DIR to $HOME"
stow --dir=$ABS_DIR --target=$HOME files

54
scripts/install.sh Executable file
View File

@@ -0,0 +1,54 @@
#!/usr/bin/env bash
set -eo pipefail
TIME=${TIME:-`date`}
UUID=${UUID:-`uuidgen`}
HOST=${HOST:-`hostname`}
NAME=`basename "$0"`
REL_DIR=`dirname "$0"`
ABS_DIR=`readlink -f $REL_DIR/../` # Scripts are nested inside of /scripts
LOG_DIR="$ABS_DIR/logs"
mkdir -p $LOG_DIR
LOG_TARGET=${LOG_TARGET:-$LOG_DIR/$UUID.log}
main() {
echo "Running $NAME at $TIME"
echo "Running as $USER on $HOST"
# Prevent running as root
if [[ $EUID -eq 0 ]]; then
echo "Failed: Running as sudo. Please run as user"
exit 1
fi
echo "Loading utils"
source $REL_DIR/_utils.sh
apt_update
echo "Installing jq..."
apt_install jq
echo "Installing apt dependencies..."
for dep in `jq -r ".apt_dependencies[]" $ABS_DIR/config.json`; do
apt_install $dep
done
figlet -c "bootstrapping..."
$ABS_DIR/scripts/bootstrap.sh
source $HOME/.profile
figlet -c "installing..."
export INSTALL_DIR="$REL_DIR/install"
for script in $INSTALL_DIR/*.sh; do
figlet -c `basename $script`
source $script
done
}
echo "main: Logging to $LOG_TARGET"
main 2>&1 |tee $LOG_TARGET

View File

@@ -0,0 +1,4 @@
apt-transport-https
software-properties-common
ripgrep
universal-ctags

2
scripts/install/00-apt.sh Executable file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
cat /etc/os-release

15
scripts/install/02-fish.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
if not_installed "fish"; then
add_ppa "fish-shell/release-3"
update
install fish
fi
fish --version
fisher_location="$HOME/.config/fish/functions/fisher.fish"
if ! [ -f "$fisher_location" ]; then
curl https://git.io/fisher --create-dirs -sLo "$fisher_location"
fish -c "fisher install jorgebucaran/fisher"
fi
fish -c "fisher --version"

9
scripts/install/03-ssh.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
ssh_target="$HOME/.ssh"
ssh_key="$ssh_target/id_rsa"
ssh_pub="$ssh_key.pub"
if [ ! -f "$ssh_key" ]; then
ssh-keygen -t rsa -b 4096 -f "$ssh_key"
fi
cat "$ssh_pub"

View File

@@ -0,0 +1,15 @@
build-essential
libssl-dev
libbz2-dev
libreadline-dev
libsqlite3-dev
libxml2-dev
libxmlsec1-dev
llvm
libncurses5-dev
libncursesw5-dev
xz-utils
tk-dev
libffi-dev
liblzma-dev
zlib1g-dev

18
scripts/install/10-pyenv.sh Executable file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
if not_installed "pyenv"; then
# see https://github.com/pyenv/pyenv/wiki/common-build-problems
pyenv_list_file="$INSTALL_DIR/10-pyenv-pkglist"
install_file "$pyenv_list_file"
# see https://github.com/pyenv/pyenv-installer
run "https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer" \
bash
fi
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
pyenv update
pyenv --version

13
scripts/install/11-python.sh Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
if not_installed "pip3"; then
pyenv install 3.9.0
pyenv global 3.9.0
refresh
fi
pip install --upgrade pip
pip3 install --upgrade pip
python3 --version
pip3 --version

10
scripts/install/12-poetry.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
add_path "$HOME/.local/bin"
if not_installed "poetry"; then
pip3 install --user poetry
fi
pip3 install --upgrade poetry
poetry --version

11
scripts/install/13-nvm.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
run "https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh" \
"bash"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm --version
nvm install node
nvm use node
node --version

9
scripts/install/14-yarn.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
if not_installed "yarn"; then
add_key https://dl.yarnpkg.com/debian/pubkey.gpg
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
update
sudo apt install --no-install-recommends yarn
fi
yarn --version

6
scripts/install/15-java.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
if not_installed "java"; then
install default-jre
fi
java --version

18
scripts/install/16-vim.sh Executable file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
mkdir -p "$XDG_DATA_HOME/nvim/backup"
plug_target="$XDG_DATA_HOME/nvim/site/autoload/plug.vim"
if [ ! -f $plug_target ]; then
echo "Downloading vim-plug to $plug_target";
curl -fLo "$plug_target" --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
fi
echo "Installing neovim support";
pip3 install --user neovim pynvim 'python-language-server[all]'
nvm use default
npm install -g neovim
echo "Running PlugInstall";
nvim --headless +UpdateRemotePlugins +PlugClean! +PlugInstall +PlugUpgrade +PlugUpdate +qall
nvim --version

43
scripts/install/30-docker.sh Executable file
View File

@@ -0,0 +1,43 @@
#!/usr/bin/env bash
DOCKER_FOLDER="$HOME/.docker"
if not_installed "docker"; then
mkdir -p "$DOCKER_FOLDER"
# Requirements
install apt-transport-https ca-certificates curl gnupg-agent \
software-properties-common
# Add repository
distro=$(lsb_release -si | tr "[:upper:]" "[:lower:]") # cast to lowercase
add_key "https://download.docker.com/linux/$distro/gpg" \
"gnupg-ring:/etc/apt/trusted.gpg.d/docker-apt-key.gpg"
sudo add-apt-repository -y \
"deb [arch=amd64] https://download.docker.com/linux/$distro \
$(lsb_release -cs) \
stable"
update
# Install
install docker-ce
# Chown
sudo chown "$USER":"$USER" "$DOCKER_FOLDER" -R
sudo chmod g+rwx "$DOCKER_FOLDER" -R
fi
docker --version
if not_installed "docker-compose"; then
pip3 install --user docker-compose
fi
pip3 install --upgrade docker-compose
docker-compose --version
readonly docker_group="docker"
if ! grep -q "$docker_group" /etc/group; then
sudo groupadd "$docker_group"
fi
if ! groups "$USER" | grep -q "\b$docker_group\b"; then
sudo usermod -aG docker "$USER"
fi

15
scripts/install/31-gcloud.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
if not_installed "gcloud"; then
echo "Installing gcloud..."
# Add the Cloud SDK distribution URI as a package source
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" \
| sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
# Import the Google Cloud Platform public key
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \
| sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
update
install google-cloud-sdk
refresh
fi
gcloud --version

8
scripts/install/32-firebase.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
if not_installed "firebase"; then
run "https://firebase.tools" "bash"
fi
echo "firebase is installed, upgrading..."
curl -sL firebase.tools | upgrade=true bash
firebase --version

14
scripts/install/33-aws.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/usr/bin/env bash
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
temp_dir=$(mktemp -d)
unzip awscliv2.zip -d "$temp_dir"
rm awscliv2.zip
if not_installed "aws"; then
echo "Installing awscli..."
sudo $temp_dir/aws/install
fi
echo "awscli is installed, upgrading..."
sudo $temp_dir/aws/install --update
aws --version

29
scripts/install/34-terraform.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/usr/bin/env bash
tf_version="0.14.6"
if not_installed "terraform"; then
echo "Installing terraform..."
tf_archive="terraform_${tf_version}_linux_amd64.zip"
wget "https://releases.hashicorp.com/terraform/${tf_version}/${tf_archive}"
unzip "$tf_archive" -d "$dotfiles_dir/tmp"
rm "$tf_archive"
mkdir -p ~/.local/bin
mv "$dotfiles_dir/tmp/terraform" ~/.local/bin
rm "$dotfiles_dir/tmp/terraform"
fi
echo "terraform is installed"
terraform --version
tf_lsp_version="0.13.0"
if not_installed "terraform-ls"; then
echo "Installing terraform-ls..."
tf_lsp_archive="terraform-ls_${tf_lsp_version}_linux_amd64.zip"
wget "https://releases.hashicorp.com/terraform-ls/${tf_lsp_version}/${tf_lsp_archive}"
unzip "${tf_lsp_archive}" -d "$dotfiles_dir/tmp"
rm "${tf_lsp_archive}"
mkdir -p ~/.local/bin
mv "$dotfiles_dir/tmp/terraform-ls" ~/.local/bin
rm "$dotfiles_dir/tmp/terraform-ls"
fi
echo "terraform-lsp is installed"

View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
clean

View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
screenfetch

4
scripts/publish.sh Normal file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -eo pipefail
echo "Publishing..."

29
scripts/setup.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -eo pipefail
# GitHub repository details
AUTHOR=${AUTHOR:-andrejusk}
REPOSITORY=${REPOSITORY:-dotfiles}
BRANCH=${BRANCH:-master}
echo "Using repository $AUTHOR/$REPOSITORY at $BRANCH"
# Target folder to checkout to
DOTFILES_DIR=${DOTFILES_DIR:-$HOME/.dotfiles}
mkdir -p $DOTFILES_DIR
if [ -z `ls -A $DOTFILES_DIR` ]; then
echo "Setting up $DOTFILES_DIR"
else
echo "Failed: Setup directory not empty $DOTFILES_DIR"
exit 1
fi
# Download and untar repo
tmp_dir=`mktemp -d`
tmp_dest="$tmp_dir/dotfiles.tar.gz"
wget "https://github.com/$AUTHOR/$REPOSITORY/archive/$BRANCH.tar.gz" -qO $tmp_dest
tar -C $tmp_dir -zxf $tmp_dest
mv $tmp_dir/$REPOSITORY-$BRANCH/* $DOTFILES_DIR
rm -rf $tmp_dir
echo "Done!"
$DOTFILES_DIR/scripts/install.sh

9
scripts/test.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
tag=`uuidgen`
docker build . \
-t dotfiles:$tag \
--target test
docker run dotfiles:$tag