dotfile setup help
This commit is contained in:
parent
f1db529d2e
commit
3ca6551ce1
1 changed files with 121 additions and 0 deletions
121
dotfiles.sh
Normal file
121
dotfiles.sh
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
{
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
creds=false
|
||||||
|
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
||||||
|
command_exists() {
|
||||||
|
command -v "$@" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
getImports() {
|
||||||
|
local url="$1"
|
||||||
|
local import="$(mktemp)"
|
||||||
|
if command_exists curl; then
|
||||||
|
curl -fsSL $url -o $import
|
||||||
|
elif command_exists wget; then
|
||||||
|
wget -O $import $url
|
||||||
|
else
|
||||||
|
echo "curl/wget is required, but missing.."
|
||||||
|
exit 69
|
||||||
|
fi
|
||||||
|
|
||||||
|
source "$import"
|
||||||
|
|
||||||
|
echo "${BLUE}Sourcing external script:${NC} $url"
|
||||||
|
sleep 0.1
|
||||||
|
rm -f "$import"
|
||||||
|
}
|
||||||
|
|
||||||
|
setup-env() {
|
||||||
|
# WHY:
|
||||||
|
# This import will give you the following variables:
|
||||||
|
# _sudo="sudo -E" <- only if non root user
|
||||||
|
# distro = <distro name, like 'arch', 'debian', 'fedora'..>
|
||||||
|
# arch = bool
|
||||||
|
# fedora = bool
|
||||||
|
# opensuse = bool....
|
||||||
|
# You can then use it for, `if $arch; then`
|
||||||
|
# Also this gives you the _install command, which installs a package pased on the packagemanager/distro used.
|
||||||
|
#
|
||||||
|
# CAUTION:
|
||||||
|
# This only wokrs for generic package names, like neovim, or vim, or tmux etc..
|
||||||
|
# not every package packagemanager has the same packagenames for their packages..
|
||||||
|
#
|
||||||
|
# local beddu=https://git.k4li.de/scripts/beddu/raw/branch/main/dist/beddu.sh
|
||||||
|
# local pika=https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh
|
||||||
|
# dream ~= combined beddu and pika
|
||||||
|
local dream=https://git.k4li.de/scripts/imports/raw/branch/main/dream.sh
|
||||||
|
|
||||||
|
if ! command_exists pkg-install && ! command_exists check-and-install && ! command_exists pen; then
|
||||||
|
getImports $dream
|
||||||
|
fi
|
||||||
|
|
||||||
|
for pkg in git grep; do
|
||||||
|
if ! command_exists $pkg; then
|
||||||
|
pen bold yellow "Installing $pkg for you.."
|
||||||
|
pkg-install $pkg
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -f "$HOME/.git-credentials" ]; then
|
||||||
|
if grep -q -i 'git.k4li.de' "$HOME/.git-credentials"; then
|
||||||
|
creds=true
|
||||||
|
else
|
||||||
|
creds=false
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
creds=false
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
clone-repo-to() {
|
||||||
|
local repo="$1"
|
||||||
|
local path="$2"
|
||||||
|
local url="https://git.k4li.de"
|
||||||
|
|
||||||
|
if [ ! -d "$path" ]; then
|
||||||
|
git clone --depth=1 --recursive "${url}/${repo}" "${path}"
|
||||||
|
else
|
||||||
|
if confirm "The path $path is already present! Do you want to move it now to $HOME/.bak?" </dev/tty; then
|
||||||
|
git clone --depth=1 --recursive "${url}/${repo}" "${path}"
|
||||||
|
else
|
||||||
|
pen bold grey "Did not touch $path"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ask-repo-setup() {
|
||||||
|
choose setup "Which repo should i setup for you?" "hyprdots" "minimal" </dev/tty
|
||||||
|
if $creds; then
|
||||||
|
choose advanced "Do you also want to setup some other dotfiles?" "ssh" "private" "notes" no </dev/tty
|
||||||
|
|
||||||
|
[ -z "$GIT" ] && request GIT "The GIT variable is not set. This variable should identify your preferred git directory. Enter one now (if its not there, it will get created.. Try to use paths in your '$HOME' directory)" </dev/tty
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if $setup is empty, return 69
|
||||||
|
[ -z "$setup" ] && return 69
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
ask-repo-setup
|
||||||
|
|
||||||
|
case "$setup" in
|
||||||
|
hyprdots) clone-repo-to "dotfiles/hyprdots.git" "$HOME/dotfiles" ;;
|
||||||
|
minimal) clone-repo-to "dotfiles/minimal.git" "$HOME/dotfiles" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -n "$advanced" ]; then
|
||||||
|
case "$advanced" in
|
||||||
|
ssh) clone-repo-to "pika/ssh.git" "$GIT/ssh" ;;
|
||||||
|
private) clone-repo-to "pika/private.git" "$GIT/private" ;;
|
||||||
|
notes) clone-repo-to "pika/notes.git" "$HOME/notes" ;;
|
||||||
|
no) return 0 ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if setup-env; then
|
||||||
|
main
|
||||||
|
fi
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue