feat: dir, install changes

This commit is contained in:
2024-03-03 21:06:52 +00:00
parent 3c5b255bcf
commit 25cd4dba5e
24 changed files with 127 additions and 206 deletions

View File

@@ -3,3 +3,4 @@ Host *
UseKeychain yes UseKeychain yes
AddKeysToAgent yes AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519 IdentityFile ~/.ssh/id_ed25519

View File

13
home/.zshrc Normal file
View File

@@ -0,0 +1,13 @@
source $HOME/.profile
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="robbyrussell"
zstyle ':omz:update' frequency 13
plugins=(git)
source $ZSH/oh-my-zsh.sh

View File

@@ -1,104 +0,0 @@
# Utility functions for common tasks
ARCH=$(dpkg --print-architecture)
# @arg $1 URL to download
# @arg $2 Path to file
function download_file {
curl \
--silent \
--show-error \
--location \
--output $2 \
$1
}
# @arg $1 URL to run
# @arg $2 binary to use
function download_run {
file=$(mktemp)
download_file $1 $file
cat $file | $2
}
# @arg $1 binary to test
function bin_in_path {
command -v $1
}
# @arg $1 apt package to test
function apt_installed {
dpkg --status $1 >/dev/null
}
function update {
sudo apt-get update -qq
}
# @arg $1 apt package to install if not present
function install {
if ! apt_installed $1; then
sudo apt-get install -qq $1
fi
}
# Add apt repository
# @arg $1 JSON object containing the following keys
# * key - entry key
# * repository - apt repository
# * signingKey - gpg signing key url
# * components - apt components
function add_repository {
key=$(jq -r ".key" <<<"$1")
echo "Updating apt repository ${key}..."
signingKey=$(jq -r ".signingKey" <<<"$1")
repository=$(jq -r ".repository" <<<"$1")
components=$(jq -r ".components" <<<"$1")
signingKeyPath="/etc/apt/keyrings/${key}.gpg"
sourcesListPath="/etc/apt/sources.list.d/${key}.list"
source="deb [signed-by=${signingKeyPath} arch=${ARCH}] ${repository} ${components}"
sudo mkdir -p /etc/apt/keyrings
sudo mkdir -p /etc/apt/sources.list.d
echo "$source" | sudo tee "$sourcesListPath" >/dev/null
wget -O- "$signingKey" |
gpg --dearmor |
sudo tee "$signingKeyPath" >/dev/null
}
# @arg $1 package list file to install
function install_file {
sudo apt-get install -qqf $(cat $1)
}
# @arg $1 JSON object containing the following keys
# * name - apt repository
# * target - gpg signing key url
function stow_package {
name=$(jq -r ".name" <<<"$1")
target=$(jq -r ".target" <<<"$1")
case $target in
HOME)
rm -f $HOME/.bashrc
rm -f $HOME/.profile
target=$HOME
;;
CONFIG)
mkdir -p $HOME/.config
target=$HOME/.config
;;
SSH)
mkdir -p $HOME/.ssh
target=$HOME/.ssh
;;
*) ;;
esac
echo "Stowing $ABS_DIR/files/$name to $target"
sudo stow --dir="$ABS_DIR/files" --target=$target $name
}

View File

@@ -2,69 +2,47 @@
set -eo pipefail set -eo pipefail
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Script that installs system dependencies specified in a config, # Script to run all install scripts contained in install.d
# and runs all post-install scripts contained in a subdirectory.
# #
uuid=${UUID:-$(cat /proc/sys/kernel/random/uuid)} # Prevent running as root and check sudo access
dir=$(dirname "$0") if [[ $EUID -eq 0 ]]; then
utils="${dir}/_utils.sh" echo "Failed: Running as sudo. Please run as user"
config="${dir}/install_config.json" exit 1
install_dir="${dir}/install.d" fi
log_dir="${dir}/logs" sudo -v
# Create log directory if it doesn't exist dir=$(dirname "$0")
# and the log path hasn't been overridden install_dir="$dir/install.d"
if [[ -z "$LOG_TARGET" ]]; then
mkdir -p "$log_dir" if [[ -z "$LOG_TARGET" ]]; then
timestamp=$(date +%Y-%m-%dT%H:%M:%S)
uuid=$(
uuidgen 2> /dev/null \
|| cat /proc/sys/kernel/random/uuid 2> /dev/null \
|| echo $RANDOM
)
log_dir="$dir/logs"
mkdir -p "$log_dir"
log_target=${LOG_TARGET:-"$log_dir/$uuid.log"}
elif
log_target="$LOG_TARGET"
fi fi
log_target=${LOG_TARGET:-"${log_dir}/${uuid}.log"}
install() { install() {
echo "Running \"$(basename "$0")\" at \"$(date)\"" echo "Running \"$(basename "$0")\" at \"$(date)\""
echo "Running as \"$(whoami)\" on \"$(hostname)\"" echo "Running as \"$(whoami)\" on \"$(hostname)\""
# Prevent running as root
if [[ $EUID -eq 0 ]]; then
echo "Failed: Running as sudo. Please run as user"
exit 1
fi
# Load installer dependencies
source "$utils"
update
install jq
for dep in $(jq -r ".apt_core_dependencies[]" "$config"); do
install "$dep"
done
# Add apt repositories
for i in $(jq ".apt_repositories | keys | .[]" "$config"); do
value=$(jq -r ".apt_repositories[$i]" "$config")
add_repository "$value"
done
update
# Install apt dependencies
for dep in $(jq -r ".apt_dependencies[]" "$config"); do
install "$dep"
done
# Install dotfiles on system and load them
figlet -c "Stowing..."
for i in $(jq ".stow_packages | keys | .[]" "$config"); do
value=$(jq -r ".stow_packages[$i]" "$config")
stow_package "$value"
done
source "$HOME/.profile"
# Run custom installer scripts
figlet -c "Installing..."
for script in $install_dir/*.sh; do for script in $install_dir/*.sh; do
figlet -c "$(basename $script)" script_name=$(basename $script)
printf "\n\n<<< $script_name:\n"
source $script source $script
printf "\n\n>>> $script_name\n"
unset script_name
done done
} }
echo "install: Logging to \"$log_target\"" echo "install: Logging to \"$log_target\""
install 2>&1 | tee "$log_target" install 2>&1 | tee "$log_target"
unset uuid dir install_dir log_dir log_target

0
script/install.d/00-os_info.sh Executable file → Normal file
View File

0
script/install.d/01-ssh.sh Executable file → Normal file
View File

7
script/install.d/02-brew.sh Executable file → Normal file
View File

@@ -7,12 +7,11 @@
if [[ "$OSTYPE" == "darwin"* ]]; then if [[ "$OSTYPE" == "darwin"* ]]; then
export NONINTERACTIVE=1 export NONINTERACTIVE=1
if ! bin_in_path brew; then if ! command -v brew &> /dev/null; then
download_run https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh /bin/bash bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
brew update
fi fi
brew update
brew --version brew --version
unset NONINTERACTIVE unset NONINTERACTIVE

View File

@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Description:
# (distros with apt only) Install core apt packages.
#
if command -v apt-get &> /dev/null; then
apt_packages=(
curl
gnupg
gnupg2
)
sudo apt-get update
sudo apt-get install -qq "${apt_packages[@]}"
sudo apt-get autoremove
sudo apt-get autoclean
unset apt_packages
fi

View File

@@ -11,10 +11,12 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
font-fira-code-nerd-font font-fira-code-nerd-font
) )
if ! brew list "${fonts_list[@]}" &> /dev/null; then
brew tap homebrew/cask-fonts brew tap homebrew/cask-fonts
for font in "${fonts_list[@]}"; do for font in "${fonts_list[@]}"; do
brew install --cask "$font" brew install --cask "$font"
done done
fi
unset fonts_list unset fonts_list
fi fi

View File

@@ -1,14 +0,0 @@
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Description:
# Configure zsh shell.
#
if ! bin_in_path zsh; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
install zsh
fi
fi
zsh --version

View File

@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Description:
# Configure zsh shell.
#
if ! command -v zsh &> /dev/null; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt-get install -qq zsh
elif [[ "$OSTYPE" == "darwin"* ]]; then
brew install zsh
fi
fi
zsh --version
# check if oh-my-zsh is installed
if [[ ! -d "$HOME/.oh-my-zsh" ]]; then
bash -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi

View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Description:
# Install and run stow.
#
if ! command -v stow &> /dev/null; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt-get install -qq stow
elif [[ "$OSTYPE" == "darwin"* ]]; then
brew install stow
fi
fi
stow --version
root_dir=$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")
rm -f $HOME/.bash_profile
rm -f $HOME/.bashrc
rm -f $HOME/.gitconfig
rm -f $HOME/.profile
rm -f $HOME/.zshrc
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

0
script/install.d/10-pyenv.sh Executable file → Normal file
View File

0
script/install.d/11-python.sh Executable file → Normal file
View File

0
script/install.d/12-node.sh Executable file → Normal file
View File

0
script/install.d/20-docker.sh Executable file → Normal file
View File

0
script/install.d/98-clean.sh Executable file → Normal file
View File

0
script/install.d/99-screenfetch.sh Executable file → Normal file
View File

View File

@@ -30,12 +30,6 @@
"repository": "https://download.docker.com/linux/debian", "repository": "https://download.docker.com/linux/debian",
"components": "bullseye stable" "components": "bullseye stable"
}, },
{
"key": "fish",
"signingKey": "https://download.opensuse.org/repositories/shells:fish/Debian_10/Release.key",
"repository": "https://download.opensuse.org/repositories/shells:/fish/Debian_10/",
"components": "/"
},
{ {
"key": "github", "key": "github",
"signingKey": "https://cli.github.com/packages/githubcli-archive-keyring.gpg", "signingKey": "https://cli.github.com/packages/githubcli-archive-keyring.gpg",
@@ -43,11 +37,6 @@
"components": "stable main" "components": "stable main"
} }
], ],
"apt_core_dependencies": [
"curl",
"gnupg",
"gnupg2"
],
"apt_dependencies": [ "apt_dependencies": [
"apt-transport-https", "apt-transport-https",
"ca-certificates", "ca-certificates",
@@ -60,7 +49,6 @@
"emacs", "emacs",
"fd-find", "fd-find",
"figlet", "figlet",
"fish",
"fonts-nanum", "fonts-nanum",
"fortune-mod", "fortune-mod",
"fzf", "fzf",
@@ -76,13 +64,11 @@
"openssh-server", "openssh-server",
"redis-tools", "redis-tools",
"screenfetch", "screenfetch",
"stow",
"terraform-ls", "terraform-ls",
"terraform", "terraform",
"tmux", "tmux",
"unzip", "unzip",
"yarn", "yarn"
"zsh"
], ],
"node_dependencies": [ "node_dependencies": [
"firebase-tools", "firebase-tools",
@@ -97,19 +83,5 @@
"poetry", "poetry",
"python-language-server[all]", "python-language-server[all]",
"pyvim" "pyvim"
],
"stow_packages": [
{
"name": "config",
"target": "CONFIG"
},
{
"name": "home",
"target": "HOME"
},
{
"name": "ssh",
"target": "SSH"
}
] ]
} }