feat: debian install, docker tests

This commit is contained in:
2024-03-08 11:34:37 +00:00
parent d9283511a3
commit 02afe496d5
24 changed files with 201 additions and 326 deletions

17
script/docker-run Executable file
View File

@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail
# --------------------------------------------------------------------
# This script is used to run the install script in a docker container.
#
tag=$(cat /proc/sys/kernel/random/uuid)
docker build . \
--build-arg UUID=$tag \
--tag dotfiles:$tag \
--target install
docker run \
-v "$(pwd)"/logs:/home/test-user/.dotfiles/logs \
dotfiles:$tag \
/bin/bash

View File

@@ -9,13 +9,15 @@ printf "\n\t <<< dots installer >>>\n"
printf "\t========================\n\n\n"
# Prevent running as root
if [[ $EUID -eq 0 ]]; then
if [[ $EUID -eq 0 && -z "$SKIP_SUDO_CHECK" ]]; then
echo "Failed: Running as sudo. Please run as user"
exit 1
fi
# Ensure sudo credentials are cached
sudo -v
if [[ -z "$SKIP_SUDO_CHECK" ]]; then
sudo -v
fi
# Set up directory variables
dir=$(dirname "$0")

View File

@@ -8,7 +8,7 @@
if [[ "$OSTYPE" == "darwin"* ]]; then
sw_vers
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
lsb_release -a
cat /etc/os-release
else
echo "Unknown OS: $OSTYPE"
fi

View File

@@ -5,18 +5,21 @@
# Print SSH key.
#
ssh_method="ed25519"
# skip if SKIP_SSH_CONFIG is set
if [ -z "$SKIP_SSH_CONFIG" ]; then
ssh_method="ed25519"
ssh_target="${HOME}/.ssh"
ssh_key="${ssh_target}/id_${ssh_method}"
ssh_pub="${ssh_key}.pub"
if [ ! -f $ssh_key ]; then
ssh-keygen \
-t $ssh_method \
-f $ssh_key \
-C "$(whoami)@$(hostname)-$(date -I)"
ssh_target="${HOME}/.ssh"
ssh_key="${ssh_target}/id_${ssh_method}"
ssh_pub="${ssh_key}.pub"
if [ ! -f $ssh_key ]; then
ssh-keygen \
-t $ssh_method \
-f $ssh_key \
-C "$(whoami)@$(hostname)-$(date -I)"
fi
cat $ssh_pub
unset ssh_method ssh_target ssh_key ssh_pub
fi
cat $ssh_pub
unset ssh_method ssh_target ssh_key ssh_pub

View File

@@ -10,12 +10,11 @@ if command -v apt-get &> /dev/null; then
curl
gnupg
gnupg2
wget
)
sudo apt-get update -qq
if [ ${#apt_packages[@]} -gt 0 ]; then
sudo apt-get install -qq "${apt_packages[@]}"
fi
sudo apt-get install -qq "${apt_packages[@]}"
unset apt_packages
else
@@ -23,4 +22,3 @@ else
fi
apt --version
echo "Last updated: $(ls -l /var/lib/apt/periodic/update-success-stamp | awk '{print $6" "$7" "$8}')"

View File

@@ -28,6 +28,6 @@ rm -f $HOME/.ssh/config
mkdir -p $HOME/.config
mkdir -p $HOME/.ssh
sudo stow --dir="$root_dir" --target="$HOME" home
sudo stow --dir="$root_dir" --target="$HOME/.config" dot-config
sudo stow --dir="$root_dir" --target="$HOME/.ssh" dot-ssh
sudo stow --dir="$root_dir/files" --target="$HOME" home
sudo stow --dir="$root_dir/files" --target="$HOME/.config" dot-config
sudo stow --dir="$root_dir/files" --target="$HOME/.ssh" dot-ssh

View File

@@ -5,29 +5,16 @@
# Configure pyenv.
#
if ! command -v "pyenv" &> /dev/null; then
export PYENV_ROOT="$HOME/.pyenv"
if ! echo $PATH | grep -q "$PYENV_ROOT"; then
export PATH="$PYENV_ROOT/bin:$PATH"
fi
if ! command -v "pyenv" &>/dev/null; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# see https://github.com/pyenv/pyenv/wiki/common-build-problems
ppyenv_packages=(
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
)
if [ ${#pyenv_packages[@]} -gt 0 ]; then
sudo apt-get install -qq "${pyenv_packages[@]}"
fi
# https://github.com/pyenv/pyenv/wiki#suggested-build-environment
sudo apt-get install -qq build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
# see https://github.com/pyenv/pyenv-installer
bash -c "$(curl -fsSL https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer)"
@@ -49,8 +36,6 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
unset virtualenv_path
fi
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv init --path)"
pyenv --version

View File

@@ -1,11 +1,4 @@
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Description:
# (Ubuntu only) Configure docker.
#
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if [[ "$OSTYPE" == "linux-gnu"* && -z "$SKIP_DOCKER_CONFIG" ]]; then
docker --version
readonly docker_group="docker"

View File

@@ -11,8 +11,8 @@ if ! command -v gh &>/dev/null; then
sudo mkdir -p -m 755 /etc/apt/keyrings && wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg >/dev/null &&
sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg &&
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list >/dev/null &&
sudo apt update &&
sudo apt install gh -y
sudo apt-get update -qq &&
sudo apt-get install -qq gh
elif [[ "$OSTYPE" == "darwin"* ]]; then
brew install gh
fi

View File

@@ -7,7 +7,11 @@
if ! command -v "terraform" &>/dev/null; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt-get install -qq terraform
wget -qO- https://apt.releases.hashicorp.com/gpg | sudo tee /etc/apt/keyrings/hashicorp-keyring.gpg >/dev/null &&
sudo chmod go+r /etc/apt/keyrings/hashicorp-keyring.gpg &&
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/hashicorp-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list >/dev/null &&
sudo apt-get update -qq &&
sudo apt-get install -qq terraform
elif [[ "$OSTYPE" == "darwin"* ]]; then
brew tap hashicorp/tap
brew install hashicorp/tap/terraform

View File

@@ -7,7 +7,7 @@
if ! command -v "neofetch" &>/dev/null; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt-get install neofetch -qq
sudo apt-get install -qq neofetch &>/dev/null
elif [[ "$OSTYPE" == "darwin"* ]]; then
brew install neofetch
fi

View File

@@ -23,12 +23,6 @@
"signingKey": "https://download.docker.com/linux/debian/gpg",
"repository": "https://download.docker.com/linux/debian",
"components": "bullseye stable"
},
{
"key": "github",
"signingKey": "https://cli.github.com/packages/githubcli-archive-keyring.gpg",
"repository": "https://cli.github.com/packages",
"components": "stable main"
}
],
"apt_dependencies": [
@@ -46,7 +40,6 @@
"fonts-nanum",
"fortune-mod",
"fzf",
"gh",
"git",
"google-cloud-sdk",
"kubectl",

20
script/test Executable file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail
# --------------------------------------------------------------------
# This script is used to run the install script in a docker container
# and then run the test script.
#
IMAGE=${IMAGE:-"andrejusk/dotfiles"}
tag=${TAG:-$(cat /proc/sys/kernel/random/uuid)}
docker build . \
--build-arg UUID=$tag \
--cache-from $IMAGE \
--tag $IMAGE:$tag \
--target test
docker run \
-v "$(pwd)"/logs:/home/test-user/.dotfiles/logs \
$IMAGE:$tag