From 9b414552ce384b3d51e8210767141ac350614b47 Mon Sep 17 00:00:00 2001 From: Andrejus Date: Fri, 24 Feb 2023 23:45:11 +0000 Subject: [PATCH] feat: uuid fallback, apt setup on Ubuntu --- Dockerfile | 2 +- README.md | 2 -- script/_utils.sh | 20 +++++++++++--------- script/install | 2 +- script/install_config.json | 13 ++++++++++--- script/test | 2 +- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1a9e8a3..996107b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selectio ENV DEBIAN_FRONTEND noninteractive RUN apt-get -qq update RUN apt-get -qq install --no-install-recommends \ - software-properties-common sudo uuid-runtime + software-properties-common sudo # Create user with sudo priviledge RUN useradd -r -u 1001 --create-home -m "test-user" diff --git a/README.md b/README.md index aea43a2..36a2c52 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,8 @@ to be installed by running: # Dependencies if running on Debian sudo apt update && sudo apt install --no-install-recommends --yes \ software-properties-common \ - uuid-runtime \ wget - # Inspect source wget https://raw.githubusercontent.com/andrejusk/dotfiles/HEAD/script/setup -qO - | less diff --git a/script/_utils.sh b/script/_utils.sh index ef722fb..6696bde 100755 --- a/script/_utils.sh +++ b/script/_utils.sh @@ -46,18 +46,20 @@ function install { # 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") repository=$(jq -r ".repository" <<<"$1") - if ! grep -q "^deb .*${repository}" /etc/apt/sources.list; then - signingKey=$(jq -r ".signingKey" <<<"$1") - components=$(jq -r ".components" <<<"$1") - curl -fsSL $signingKey | sudo apt-key add - - source="deb [arch=$(dpkg --print-architecture)] ${repository} ${components}" - sudo add-apt-repository --yes "$source" - fi + signingKey=$(jq -r ".signingKey" <<<"$1") + components=$(jq -r ".components" <<<"$1") + source="deb [arch=$(dpkg --print-architecture)] ${repository} ${components}" + echo "$source" | sudo tee "/etc/apt/sources.list.d/${key}.list" >/dev/null + wget -O- "$signingKey" | + gpg --dearmor | + sudo tee "/etc/apt/keyrings/${key}.gpg" >/dev/null } # @arg $1 package list file to install @@ -79,11 +81,11 @@ function stow_package { target=$HOME ;; CONFIG) - mkdir $HOME/.config + mkdir -p $HOME/.config target=$HOME/.config ;; SSH) - mkdir $HOME/.ssh + mkdir -p $HOME/.ssh target=$HOME/.ssh ;; *) ;; diff --git a/script/install b/script/install index b8f4cfd..065d857 100755 --- a/script/install +++ b/script/install @@ -7,7 +7,7 @@ set -eo pipefail # TIME=${TIME:-$(date)} -UUID=${UUID:-$(uuidgen)} +UUID=${UUID:-$(cat /proc/sys/kernel/random/uuid)} HOST=${HOST:-$(hostname)} NAME=$(basename "$0") diff --git a/script/install_config.json b/script/install_config.json index e07410c..09df6d7 100644 --- a/script/install_config.json +++ b/script/install_config.json @@ -1,36 +1,43 @@ { "apt_repositories": [ { + "key": "hashicorp", "signingKey": "https://apt.releases.hashicorp.com/gpg", "repository": "https://apt.releases.hashicorp.com", - "components": "buster main" + "components": "bullseye main" }, { + "key": "yarn", "signingKey": "https://dl.yarnpkg.com/debian/pubkey.gpg", "repository": "https://dl.yarnpkg.com/debian", "components": "stable main" }, { + "key": "google-cloud", "signingKey": "https://packages.cloud.google.com/apt/doc/apt-key.gpg", "repository": "https://packages.cloud.google.com/apt", "components": "cloud-sdk main" }, { + "key": "google-k8s", "signingKey": "https://packages.cloud.google.com/apt/doc/apt-key.gpg", "repository": "https://apt.kubernetes.io/", "components": "kubernetes-xenial main" }, { + "key": "docker", "signingKey": "https://download.docker.com/linux/debian/gpg", "repository": "https://download.docker.com/linux/debian", - "components": "buster 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", "signingKey": "https://cli.github.com/packages/githubcli-archive-keyring.gpg", "repository": "https://cli.github.com/packages", "components": "stable main" @@ -64,7 +71,7 @@ "lsb-release", "make", "net-tools", - "netcat", + "netcat-traditional", "openssh-client", "openssh-server", "redis-tools", diff --git a/script/test b/script/test index ef086f8..c854cf4 100755 --- a/script/test +++ b/script/test @@ -2,7 +2,7 @@ set -euo pipefail IMAGE=${IMAGE:-"andrejusk/dotfiles"} -tag=${TAG:-uuidgen} +tag=${TAG:-$(cat /proc/sys/kernel/random/uuid)} docker build . \ --build-arg UUID=$tag \