Skip to content

Commit

Permalink
chore: Add configure script (#3)
Browse files Browse the repository at this point in the history
This commit adds a configure script to the repository. The configure script handles the installation of necessary dependencies and sets up the environment. This commit ensures that the project has all the required dependencies and a proper environment for development.

Signed-off-by: Schubert Anselme <[email protected]>
  • Loading branch information
sanselme authored Oct 30, 2024
1 parent 735cbba commit 07330be
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 86 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/build.yml

This file was deleted.

11 changes: 8 additions & 3 deletions scripts/aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
alias dir="dir --color=auto"
alias vdir="vdir --color=auto"

alias ls="ls -F --color=auto --show-control-chars"
alias ls="ls -G"
alias ll="ls -l"
alias la="ls -A"
alias l="ls -CF"
alias la="ls -lAFh"
alias l="ls -lCF"

alias grep="grep --color=auto"
alias fgrep="fgrep --color=auto"
alias egrep="egrep --color=auto"

alias vbmc="sudo -E vbmc"
alias virsh="sudo -E virsh"
alias virt-install="sudo -E virt-install"
alias virt-manager="sudo -E virt-manager"
50 changes: 0 additions & 50 deletions scripts/config-devos.sh

This file was deleted.

73 changes: 73 additions & 0 deletions scripts/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0

DIR="$(dirname $(realpath $(dirname "${0}")))"
source "${DIR}/scripts/aliases.sh"
source "${DIR}/scripts/environment.sh"

# dependencies
if [[ -n $(command -v "apt-get") ]]; then
commands=(
"curl"
"git"
"gnupg2"
"zsh"
)

sudo apt-get update -y
for command in "${commands[@]}"; do
if [[ -z $(command -v "${command}") ]]; then
sudo apt-get install -y "${command}"
fi
done
fi

# permissions
if [[ -n $(command -v "usermod") ]]; then
groups=(
"docker"
"libvirt"
"plugdev"
"sudo"
)

for g in "${groups[@]}"; do
sudo usermod -aG "${g}" "${USER}" || true
done
fi

# environment
if [[ ! -d "${HOME}/.oh-my-zsh" ]]; then
curl -fsSLo /tmp/ohmyzsh-install.sh https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
bash /tmp/ohmyzsh-install.sh --unattended || true
rm -f /tmp/ohmyzsh-install.sh
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}"

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}/"
done

sudo chsh -s "$(command -v zsh)" "${USER}"

# trunk.io
if [[ -n $(command -v "usermod") ]]; then
trunk fmt
trunk check
fi
36 changes: 31 additions & 5 deletions scripts/environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,41 @@ export GO11MODULE="on"
export SCRIPTS="/workspace/scripts"
export TOOLS="/workspace/tools"

export LOCAL_BIN="${HOME}/.local"

export CARGO_HOME="/usr/local/rust/cargo"
export GOPATH="/usr/local/go"
export KREW_ROOT="/usr/local/krew"
export RUSTUP_HOME="/usr/local/rust/rustup"

export PATH="${KREW_ROOT}/bin:${CARGO_HOME}/bin:${GOPATH}:${TOOLS}${PATH:+:${PATH}}"
export PATH="${LOCAL_BIN}:${KREW_ROOT}/bin:${CARGO_HOME}/bin:${GOPATH}:${TOOLS}${PATH:+:${PATH}}"

# SSH Agent
eval "$(ssh-agent -s)"
ssh-add -l >>/dev/null
exit_code=$?
[[ ! ${exit_code} -eq 0 ]] && ssh-add -k
if ! ssh-add -l >>/dev/null; then
eval "$(ssh-agent -s)"
ssh-add -k
fi

# Functions
cache() {
CACHE_DIR=".cache"

REPO="${1}"
ITEMS="${2}"
VERSION="${3:-main}"

[[ -z "${REPO}" ]] && echo "ERROR: repository is required" && return 1
[[ -z "${ITEMS}" ]] && echo "ERROR: item list is required" && return 1

if [[ ! -d "${CACHE_DIR}" ]]; then
mkdir -p "${CACHE_DIR}"
tmp="$(mktemp -d)"
gh repo clone "${REPO}" "${tmp}" -- --depth 1 --branch "${VERSION}"

for ITEM in ${ITEMS[@]}; do
cp -r "${tmp}/${ITEM}" "${CACHE_DIR}/"
done

rm -rf "${tmp}"
fi
}

0 comments on commit 07330be

Please sign in to comment.