From 809a7668b1b8e343dc39f62138d5a4da8c597a24 Mon Sep 17 00:00:00 2001 From: Schubert Anselme Date: Sun, 3 Nov 2024 04:22:09 -0500 Subject: [PATCH] chore: Add Docker installation script Signed-off-by: Schubert Anselme --- .commitlintrc | 2 +- .editorconfig | 2 +- .idea | 2 +- .markdownlint.yaml | 2 +- .vscode | 2 +- .yamllint.yaml | 2 +- config/bashrc | 117 ----------------------------------- config/sshconfig | 4 -- config/zshrc | 127 -------------------------------------- scripts/configure.sh | 59 ++++++++++-------- scripts/install/docker.sh | 36 +++++++++++ 11 files changed, 76 insertions(+), 279 deletions(-) delete mode 100644 config/bashrc delete mode 100644 config/sshconfig delete mode 100644 config/zshrc create mode 100755 scripts/install/docker.sh diff --git a/.commitlintrc b/.commitlintrc index 82bd0c0..270ba79 120000 --- a/.commitlintrc +++ b/.commitlintrc @@ -1 +1 @@ -/Users/schubert/Downloads/tooling/modules/dotfiles/.commitlintrc \ No newline at end of file +modules/dotfiles/.commitlintrc \ No newline at end of file diff --git a/.editorconfig b/.editorconfig index 00ca4e4..efbc18b 120000 --- a/.editorconfig +++ b/.editorconfig @@ -1 +1 @@ -/Users/schubert/Downloads/tooling/modules/dotfiles/.editorconfig \ No newline at end of file +modules/dotfiles/.editorconfig \ No newline at end of file diff --git a/.idea b/.idea index 2d9d8f5..9530425 120000 --- a/.idea +++ b/.idea @@ -1 +1 @@ -/Users/schubert/Downloads/tooling/modules/dotfiles/.idea \ No newline at end of file +modules/dotfiles/.idea \ No newline at end of file diff --git a/.markdownlint.yaml b/.markdownlint.yaml index e7de7b4..66a72a6 120000 --- a/.markdownlint.yaml +++ b/.markdownlint.yaml @@ -1 +1 @@ -/Users/schubert/Downloads/tooling/.trunk/configs/.markdownlint.yaml \ No newline at end of file +.trunk/configs/.markdownlint.yaml \ No newline at end of file diff --git a/.vscode b/.vscode index 091322d..69e37ee 120000 --- a/.vscode +++ b/.vscode @@ -1 +1 @@ -/Users/schubert/Downloads/tooling/modules/dotfiles/.vscode \ No newline at end of file +modules/dotfiles/.vscode \ No newline at end of file diff --git a/.yamllint.yaml b/.yamllint.yaml index e7940fc..7df3dab 120000 --- a/.yamllint.yaml +++ b/.yamllint.yaml @@ -1 +1 @@ -/Users/schubert/Downloads/tooling/.trunk/configs/.yamllint.yaml \ No newline at end of file +.trunk/configs/.yamllint.yaml \ No newline at end of file diff --git a/config/bashrc b/config/bashrc deleted file mode 100644 index b488fcc..0000000 --- a/config/bashrc +++ /dev/null @@ -1,117 +0,0 @@ -# ~/.bashrc: executed by bash(1) for non-login shells. -# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) -# for examples - -# If not running interactively, don't do anything -case $- in - *i*) ;; - *) return;; -esac - -# don't put duplicate lines or lines starting with space in the history. -# See bash(1) for more options -HISTCONTROL=ignoreboth - -# append to the history file, don't overwrite it -shopt -s histappend - -# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) -HISTSIZE=1000 -HISTFILESIZE=2000 - -# check the window size after each command and, if necessary, -# update the values of LINES and COLUMNS. -shopt -s checkwinsize - -# If set, the pattern "**" used in a pathname expansion context will -# match all files and zero or more directories and subdirectories. -#shopt -s globstar - -# make less more friendly for non-text input files, see lesspipe(1) -[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" - -# set variable identifying the chroot you work in (used in the prompt below) -if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then - debian_chroot=$(cat /etc/debian_chroot) -fi - -# set a fancy prompt (non-color, unless we know we "want" color) -case "$TERM" in - xterm-color|*-256color) color_prompt=yes;; -esac - -# uncomment for a colored prompt, if the terminal has the capability; turned -# off by default to not distract the user: the focus in a terminal window -# should be on the output of commands, not on the prompt -#force_color_prompt=yes - -if [ -n "$force_color_prompt" ]; then - if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then - # We have color support; assume it's compliant with Ecma-48 - # (ISO/IEC-6429). (Lack of such support is extremely rare, and such - # a case would tend to support setf rather than setaf.) - color_prompt=yes - else - color_prompt= - fi -fi - -if [ "$color_prompt" = yes ]; then - PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' -else - PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' -fi -unset color_prompt force_color_prompt - -# If this is an xterm set the title to user@host:dir -case "$TERM" in -xterm*|rxvt*) - PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" - ;; -*) - ;; -esac - -# enable color support of ls and also add handy aliases -if [ -x /usr/bin/dircolors ]; then - test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" - alias ls='ls --color=auto' - #alias dir='dir --color=auto' - #alias vdir='vdir --color=auto' - - alias grep='grep --color=auto' - alias fgrep='fgrep --color=auto' - alias egrep='egrep --color=auto' -fi - -# colored GCC warnings and errors -#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' - -# some more ls aliases -alias ll='ls -alF' -alias la='ls -A' -alias l='ls -CF' - -# Add an "alert" alias for long running commands. Use like so: -# sleep 10; alert -alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' - -# Alias definitions. -# You may want to put all your additions into a separate file like -# ~/.bash_aliases, instead of adding them here directly. -# See /usr/share/doc/bash-doc/examples in the bash-doc package. - -if [ -f ~/.bash_aliases ]; then - . ~/.bash_aliases -fi - -# enable programmable completion features (you don't need to enable -# this, if it's already enabled in /etc/bash.bashrc and /etc/profile -# sources /etc/bash.bashrc). -if ! shopt -oq posix; then - if [ -f /usr/share/bash-completion/bash_completion ]; then - . /usr/share/bash-completion/bash_completion - elif [ -f /etc/bash_completion ]; then - . /etc/bash_completion - fi -fi diff --git a/config/sshconfig b/config/sshconfig deleted file mode 100644 index c6f91ba..0000000 --- a/config/sshconfig +++ /dev/null @@ -1,4 +0,0 @@ -Host * - AddKeysToAgent yes - IgnoreUnknown UseKeychain - UseKeychain yes diff --git a/config/zshrc b/config/zshrc deleted file mode 100644 index 511adcf..0000000 --- a/config/zshrc +++ /dev/null @@ -1,127 +0,0 @@ -# If you come from bash you might have to change your $PATH. -# export PATH=$HOME/bin:/usr/local/bin:$PATH - -# Path to your oh-my-zsh installation. -export ZSH="${HOME}/.oh-my-zsh" - -# Set name of the theme to load --- if set to "random", it will -# load a random theme each time oh-my-zsh is loaded, in which case, -# to know which specific one was loaded, run: echo $RANDOM_THEME -# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes -ZSH_THEME="ys" - -# Set list of themes to pick from when loading at random -# Setting this variable when ZSH_THEME=random will cause zsh to load -# a theme from this variable instead of looking in $ZSH/themes/ -# If set to an empty array, this variable will have no effect. -# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" ) - -# Uncomment the following line to use case-sensitive completion. -# CASE_SENSITIVE="true" - -# Uncomment the following line to use hyphen-insensitive completion. -# Case-sensitive completion must be off. _ and - will be interchangeable. -# HYPHEN_INSENSITIVE="true" - -# Uncomment the following line to disable bi-weekly auto-update checks. -# DISABLE_AUTO_UPDATE="true" - -# Uncomment the following line to automatically update without prompting. -DISABLE_UPDATE_PROMPT="true" - -# Uncomment the following line to change how often to auto-update (in days). -# export UPDATE_ZSH_DAYS=13 - -# Uncomment the following line if pasting URLs and other text is messed up. -# DISABLE_MAGIC_FUNCTIONS="true" - -# Uncomment the following line to disable colors in ls. -# DISABLE_LS_COLORS="true" - -# Uncomment the following line to disable auto-setting terminal title. -# DISABLE_AUTO_TITLE="true" - -# Uncomment the following line to enable command auto-correction. -# ENABLE_CORRECTION="true" - -# Uncomment the following line to display red dots whilst waiting for completion. -# Caution: this setting can cause issues with multiline prompts (zsh 5.7.1 and newer seem to work) -# See https://github.com/ohmyzsh/ohmyzsh/issues/5765 -# COMPLETION_WAITING_DOTS="true" - -# Uncomment the following line if you want to disable marking untracked files -# under VCS as dirty. This makes repository status check for large repositories -# much, much faster. -# DISABLE_UNTRACKED_FILES_DIRTY="true" - -# Uncomment the following line if you want to change the command execution time -# stamp shown in the history command output. -# You can set one of the optional three formats: -# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" -# or set a custom format using the strftime function format specifications, -# see "man strftime" for details. -# HIST_STAMPS="mm/dd/yyyy" - -# Would you like to use another custom folder than $ZSH/custom? -# ZSH_CUSTOM=/path/to/new-custom-folder - -# Which plugins would you like to load? -# Standard plugins can be found in $ZSH/plugins/ -# Custom plugins may be added to $ZSH_CUSTOM/plugins/ -# Example format: plugins=(rails git textmate ruby lighthouse) -# Add wisely, as too many plugins slow down shell startup. -plugins=( - alias-finder - brew - colorize - common-aliases - docker - dotenv - encode64 - git - git-extras - git-lfs - github - gitignore - golang - helm - jsontools - kubectl - macos - node - otp - sudo - vscode - z -) - -source /etc/profile -source "${ZSH}/oh-my-zsh.sh" - -# User configuration -if type brew &>/dev/null; then - FPATH=$(brew --prefix)/share/zsh-completions:$FPATH - - autoload -Uz compinit - compinit -fi - -# export MANPATH="/usr/local/man:$MANPATH" - -# You may need to manually set your language environment -export LANG=en_CA.UTF-8 - -# Compilation flags -# export ARCHFLAGS="-arch x86_64" - -# Set personal aliases, overriding those provided by oh-my-zsh libs, -# plugins, and themes. Aliases can be placed here, though oh-my-zsh -# users are encouraged to define aliases within the ZSH_CUSTOM folder. -# For a full list of active aliases, run `alias`. -# -# Example aliases -alias zshconfig="code ~/.zshrc" -alias ohmyzsh="code ~/.oh-my-zsh" - -zstyle :omz:plugins:ssh-agent agent-forwarding on -zstyle :omz:plugins:ssh-agent ssh-add-args -A diff --git a/scripts/configure.sh b/scripts/configure.sh index 8b0e1a1..83300ce 100755 --- a/scripts/configure.sh +++ b/scripts/configure.sh @@ -1,9 +1,8 @@ #!/bin/bash # SPDX-License-Identifier: GPL-3.0 -DIR="$(dirname $(realpath $(dirname "${0}")))" -source "${DIR}/scripts/aliases.sh" -source "${DIR}/scripts/environment.sh" +source scripts/aliases.sh +source scripts/environment.sh # dependencies if [[ -n $(command -v "apt-get") ]]; then @@ -14,10 +13,10 @@ if [[ -n $(command -v "apt-get") ]]; then "zsh" ) - sudo apt-get update -y for command in "${commands[@]}"; do - if [[ -z $(command -v "${command}") ]]; then - sudo apt-get install -y "${command}" + if ! grep -qa "${command}" <(apt list --installed); then + echo sudo apt-get update -yq + echo sudo apt-get install -y "${command}" fi done fi @@ -31,9 +30,18 @@ if [[ -n $(command -v "usermod") ]]; then "sudo" ) + # note: always set the user to "devcontainer" if it exists + if [[ "devcontainer" == "$(whoami)" ]]; then + USER="devcontainer" + else + USER="$(whoami)" + fi + for g in "${groups[@]}"; do - sudo usermod -aG "${g}" "${USER}" || true + sudo usermod -aG "${g}" "${USER}" done + + id "${USER}" fi # environment @@ -44,27 +52,28 @@ if [[ ! -d "${HOME}/.oh-my-zsh" ]]; then fi ln -sf \ - "${DIR}/modules/dotfiles/.bashrc" \ - "${DIR}/modules/dotfiles/.zshrc" \ - "${DIR}/modules/dotfiles/.editorconfig" \ - "${DIR}/modules/dotfiles/.commitlintrc" \ - "${DIR}/modules/dotfiles/.idea" \ - "${DIR}/modules/dotfiles/.vscode" \ - "${DIR}/.trunk/configs/."* \ - "${DIR}" + modules/dotfiles/.bashrc \ + modules/dotfiles/.zshrc \ + modules/dotfiles/.editorconfig \ + modules/dotfiles/.commitlintrc \ + modules/dotfiles/.idea \ + modules/dotfiles/.vscode \ + .trunk/configs/.* \ + . -for ITEM in $(echo """ -${DIR}/modules/dotfiles/.devcontainer -${DIR}/modules/dotfiles/.gitignore -${DIR}/modules/dotfiles/.ssh -${DIR}/modules/dotfiles/.trunk -${DIR}/modules/dotfiles/compose-dev.yaml -"""); do - # copy if not present in "${DIR}" - ls -l $(basename "${ITEM}") > /dev/null 2>&1 || cp -r "${ITEM}" "${DIR}/" +ITEMS=( + "modules/dotfiles/.devcontainer" + "modules/dotfiles/.gitignore" + "modules/dotfiles/.ssh" + "modules/dotfiles/.trunk" + "modules/dotfiles/compose-dev.yaml" +) +for ITEM in "${ITEMS[@]}"; do + # copy if not present in the root directory + ls -l $(basename "${ITEM}") > /dev/null 2>&1 || cp -r "${ITEM}" . done -sudo chsh -s "$(command -v zsh)" "${USER}" +echo sudo chsh -s "$(command -v zsh)" "${USER}" # trunk.io if [[ -n $(command -v "usermod") ]]; then diff --git a/scripts/install/docker.sh b/scripts/install/docker.sh new file mode 100755 index 0000000..6b21406 --- /dev/null +++ b/scripts/install/docker.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0 + +OLD_PKGS=( +"docker.io" +"docker-doc" +"docker-compose" +"podman-docker" +"containerd runc" +) + +PKGS=( +"containerd.io" +"docker-buildx-plugin" +"docker-ce-cli" +"docker-ce" +"docker-compose-plugin" +) + +for pkg in "${OLD_PKGS[@]}"; do + apt-get remove -y "${pkg}" +done + +install -m 0755 -d /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg +chmod a+r /etc/apt/keyrings/docker.gpg + +# add docker repository +echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \ + https://download.docker.com/linux/ubuntu \ + $(. /etc/os-release && echo "${VERSION_CODENAME}") stable" | tee /etc/apt/sources.list.d/docker.list >/dev/null + +# install packages +apt-get update -yq +apt-get install -y "${PKGS[@]}"