Skip to content

Commit

Permalink
chore: Add initial configuration files and scripts for environment se…
Browse files Browse the repository at this point in the history
…tup (#10)

Signed-off-by: Schubert Anselme <[email protected]>
  • Loading branch information
sanselme authored Nov 4, 2024
1 parent 09a84bc commit fdba721
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 112 deletions.
45 changes: 32 additions & 13 deletions config/versions.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
binaries:
- name: kubectl
url: https://dl.k8s.io/release/v${version}/bin/${os:-linux}/${arch}/kubectl
version: 1.31.1
binary:
- name: helm
checksum: https://get.helm.sh/helm-v3.16.2-darwin-arm64.tar.gz.sha256sum
url: https://get.helm.sh/helm-v${version}-${os}-${arch}.tar.gz
version: 3.16.2
type: archive
archs:
- amd64
- arm64
- name: kubectl
url: https://dl.k8s.io/release/v${version}/bin/${os}/${arch}/kubectl
version: 1.31.1
type: executable
archs:
- amd64
- arm64
- name: yq
url: https://github.com/mikefarah/yq/releases/download/v${version}/yq_${os:-linux}_${arch}
type: executable
url: https://github.com/mikefarah/yq/releases/download/v${version}/yq_${os}_${arch}
version: 4.44.3
packages:
archs:
- amd64
- arm64
package:
add: []
# - name: ""
# keyring: ""
# repo: ""
# type: apt
remove: []
# - name: containerd
# type: apt
group:
- name: docker
keyring: https://download.docker.com/${os:-linux}/ubuntu/gpg
repo: https://download.docker.com/${os:-linux}/ubuntu
keyring: https://download.docker.com/${os}/ubuntu/gpg
repo: https://download.docker.com/${os}/ubuntu
type: apt
add:
- containerd.io
Expand All @@ -28,9 +47,10 @@ packages:
- docker.io
- podman-docker
- runc
plugins:
kubernetes:
krew:
plugin:
- name: kubectl
installer: krew
list:
- access-matrix
- ca-cert
- cert-manager
Expand All @@ -54,7 +74,6 @@ plugins:
- rook-ceph
- view-cert
- view-secret
- view-serviceaccount-kube- config
- view-utilization
- view-webhook
- virt
4 changes: 2 additions & 2 deletions hack/boilerplate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# source scripts/alias.sh
# source scripts/environment.sh

# export $(yq --output-format shell '.' config/versions.yaml | tr -d "'")

export os="$(uname | tr '[:upper:]' '[:lower:]')"
export arch="$(uname -m)"

# export $(getenv <(yq '.' "${CONFIG}"))

echo """
os: ${os}
arch: ${arch}
Expand Down
20 changes: 18 additions & 2 deletions scripts/environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,25 @@ if ! ssh-add -l >>/dev/null; then
fi

# Functions
get_env_var() {
getenv() {
local source="${1}"
yq '.. |(
( select(kind == "scalar" and parent | kind != "seq") | (path | join("_")) + "=''" + . + "''"),
( select(kind == "seq") | (path | join("_")) + "=(" + (map("''" + . + "''") | join(",")) + ")")
)' "${source}"
}

getenval() {
local source="${1}"
local key="${2}"
local delimiter="${3:-=}"
printf "${source}" | grep "${key}" | awk -F "${delimiter}" '{ print $2 }'
}

getenvarval() {
local key="${1}"
env | awk -F "=" "/${key}/ { print \$2 }"
getenval $(env) "${key}" "="
# env | awk -F "=" "/${key}/ { print \$2 }"
}

cache() {
Expand Down
79 changes: 79 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0
# source scripts/alias.sh
source scripts/environment.sh

VERSION_CONFIG="config/versions.yaml"

export arch="$(uname -m)"
export os="$(uname | tr '[:upper:]' '[:lower:]')"

# todo: packages
# note: package groups
package_groups="$(yq '.package.group[] | .name' "${VERSION_CONFIG}")"
for name in ${package_groups[@]}; do
export name="${name}"
export $(getenv <(yq '.package.group[] | select(.name == env(name))' "${VERSION_CONFIG}"))

if [[ -n $(command -v "${name}") ]]; then
echo "${name} is already installed"
continue
elif [[ -n $(command -v "${type}") ]]; then
echo "================== installing ${name} ${version} on ${os} for ${arch}" ==================
sudo apt-get update -yq
sudo apt-get remove -y "$(printf "${remove}" | sed 's/,/ /g' | tr -d '()')"
sudo apt-get install -y "$(printf "${add}" | sed 's/,/ /g' | tr -d '()')"
else
echo "unsupported package manager"
fi
done

# note: binaries
binaries="$(yq '.binary[] | .name' "${VERSION_CONFIG}")"
for name in ${binaries[@]}; do
export name="${name}"
export $(getenv <(yq '.binary[] | select(.name == env(name))' "${VERSION_CONFIG}"))

if [[ -n $(command -v "${name}") ]]; then
echo "${name} is already installed"
continue
elif [[ "${archs[@]}" =~ "${arch}" ]]; then
echo "================== installing ${name} ${version} on ${os} for ${arch}" ==================
export url="$(printf "${url}" | envsubst)"
case "${type}" in
archive)
curl -fsSLo "/tmp/${name}.tgz" "${url}"
tar -xzf "/tmp/${name}.tgz"
install "/tmp/${os}-${arch}/${name}" "/usr/local/bin/${name}"
"${name}" version
;;
executable)
curl -fsSLo "/tmp/${name}" "${url}"
install "/tmp/${name}" "/usr/local/bin/${name}"
"${name}" version
;;
*)
echo "unsupported binary package"
;;
esac
else
echo "unsupported architecture"
fi
done

# note: plugins
plugins="$(yq '.plugin[] | .name' "${VERSION_CONFIG}")"
for name in ${plugins[@]}; do
export name="${name}"
installer="$(yq '.plugin[] | select(.name == env(name)) | .installer' "${VERSION_CONFIG}")"

if [[ -z $(command -v "${name}") ]]; then
echo "{name} is not installed"
elif "${name}" "${installer}" &>/dev/null; then
echo "================== installing ${name} plugins ================="
list=$(yq '.plugin[] | select(.name == env(name)) | .list[]' "${VERSION_CONFIG}")
"${name}" "${installer}" install ${list[*]} || true
else
echo "unsupported plugin installer"
fi
done
41 changes: 0 additions & 41 deletions scripts/install/docker.sh

This file was deleted.

34 changes: 0 additions & 34 deletions scripts/install/helm.sh

This file was deleted.

20 changes: 0 additions & 20 deletions scripts/install/kubernetes.sh

This file was deleted.

0 comments on commit fdba721

Please sign in to comment.