Skip to content

Instantly share code, notes, and snippets.

@ViBiOh
Last active February 22, 2022 17:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ViBiOh/e38aeb07d6d56dfa78256b61781478c5 to your computer and use it in GitHub Desktop.
Save ViBiOh/e38aeb07d6d56dfa78256b61781478c5 to your computer and use it in GitHub Desktop.
Dotfiles
#!/usr/bin/env bash
set -o nounset -o pipefail -o errexit
main() {
local INSTALL_PATH="${HOME}/code"
local GITHUB_USER="ViBiOh"
local DOTFILES_NAME="dotfiles"
local DOTFILES_BRANCH="main"
local ARCHIVE_FILENAME="${INSTALL_PATH}/dotfiles.zip"
mkdir -p "${INSTALL_PATH}"
curl --disable --silent --show-error --location --max-time 60 --output "${ARCHIVE_FILENAME}" "https://github.com/${GITHUB_USER}/${DOTFILES_NAME}/archive/${DOTFILES_BRANCH}.zip"
unzip "${ARCHIVE_FILENAME}" -d "${INSTALL_PATH}"
rm -f "${ARCHIVE_FILENAME}"
rm -rf "${INSTALL_PATH:?}/${DOTFILES_NAME}"
mv "${INSTALL_PATH}/${DOTFILES_NAME}-${DOTFILES_BRANCH}" "${INSTALL_PATH}/${DOTFILES_NAME}"
(
cd "${INSTALL_PATH}/${DOTFILES_NAME}"
"./init" -a
git init
git remote add origin "http://github.com/${GITHUB_USER}/${DOTFILES_NAME}.git"
git fetch origin
git checkout --force "${DOTFILES_BRANCH}"
)
}
main "${@}"
#!/usr/bin/env bash
set -o nounset -o pipefail -o errexit
readonly CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
create_symlinks() {
while IFS= read -r -d '' file; do
local BASENAME_FILE
BASENAME_FILE="$(basename "${file}")"
if [[ -n ${FILE_LIMIT} ]] && [[ ${BASENAME_FILE} != "${FILE_LIMIT}" ]]; then
continue
fi
[[ -r ${file} ]] && [[ -e ${file} ]] && rm -f "${HOME}/.${BASENAME_FILE}" && ln -s "${file}" "${HOME}/.${BASENAME_FILE}"
done < <(find "${CURRENT_DIR}/symlinks" -type f -print0)
}
browse_install() {
while IFS= read -r -d '' file; do
local BASENAME_FILE
BASENAME_FILE="$(basename "${file}")"
local UPPERCASE_FILENAME
UPPERCASE_FILENAME="$(printf "%s" "${BASENAME_FILE}" | tr "[:lower:]" "[:upper:]")"
local DISABLE_VARIABLE_NAME="DOTFILES_NO_${UPPERCASE_FILENAME}"
if [[ ${!DISABLE_VARIABLE_NAME:-} == "true" ]]; then
continue
fi
if [[ -r ${file} ]]; then
for action in "${@}"; do
unset -f "${action}"
done
source "${file}"
for action in "${@}"; do
if [[ $(type -t "${action}") == "function" ]]; then
print_title "${action} - ${BASENAME_FILE}"
"${action}"
fi
done
fi
done < <(find "${CURRENT_DIR}/install" -type f -print0 | LC_ALL=C sort --zero-terminated)
}
browse_install clean install
browse_install credentials
create_symlinks
#!/usr/bin/env bash
set -o nounset -o pipefail -o errexit
clean() {
rm -rf "${HOME}/.cache"
sudo rm -rf "${HOME}/opt"
}
install() {
mkdir -p "${HOME}/opt/bin"
}
#!/usr/bin/env bash
set -o nounset -o pipefail -o errexit
install() {
local PACKAGES=("bash" "bash-completion" "make" "htop" "openssl" "curl" "ncdu" "jq")
if [[ ${OSTYPE} =~ ^darwin ]]; then
cat >"${HOME}/.bash_profile" <<END_OF_BASH_PROFILE
#!/usr/bin/env bash
if [[ -f "${HOME}/.bashrc" ]]; then
source "${HOME}/.bashrc"
fi
END_OF_BASH_PROFILE
local SCRIPT_DIR
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if ! command -v brew >/dev/null 2>&1; then
/bin/bash -c "$(curl --disable --silent --show-error --location https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
source "${SCRIPT_DIR}/../sources/_homebrew"
fi
packages_update
packages_install "${PACKAGES[@]}" fswatch jdupes
if [[ $(grep --count "$(brew --prefix)" "/etc/shells") -eq 0 ]]; then
printf "+-------------------------+\n"
printf "| changing shell for user |\n"
printf "+-------------------------+\n"
printf "%s/bin/bash\n" "$(brew --prefix)" | sudo tee -a "/etc/shells" >/dev/null
chsh -s "$(brew --prefix)/bin/bash" -u "$(whoami)"
fi
elif command -v apt-get >/dev/null 2>&1; then
packages_update
packages_install "apt-transport-https"
packages_install "${PACKAGES[@]}" dnsutils jdupes
elif command -v pacman >/dev/null 2>&1; then
packages_update
packages_install "${PACKAGES[@]}" inetutils
fi
}
#!/usr/bin/env bash
if [[ -d "${HOME}/opt/bin" ]]; then
export PATH="${HOME}/opt/bin:${PATH}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment