install: remove stow
dependency and reorganize repo
This commit is contained in:
parent
2cbdf5607a
commit
f131f81c51
25 changed files with 122 additions and 135 deletions
2
.gitattributes
vendored
2
.gitattributes
vendored
|
@ -1,2 +1,2 @@
|
||||||
home/.ssh/config filter=git-crypt diff=git-crypt
|
ssh/config filter=git-crypt diff=git-crypt
|
||||||
|
|
||||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,7 +3,7 @@
|
||||||
# .gitignore.
|
# .gitignore.
|
||||||
.git/
|
.git/
|
||||||
|
|
||||||
config.local
|
config.sh
|
||||||
config/nvim/plugin/packer_compiled.lua
|
config/nvim/plugin/packer_compiled.lua
|
||||||
config/zsh/.zcompcache
|
config/zsh/.zcompcache
|
||||||
config/zsh/.zcompdump
|
config/zsh/.zcompdump
|
||||||
|
|
|
@ -12,7 +12,7 @@ $ ./unlock.sh # decrypt the SSH configuration
|
||||||
```
|
```
|
||||||
|
|
||||||
If you are not me, then you won't have the password to use in the last step.
|
If you are not me, then you won't have the password to use in the last step.
|
||||||
Just `git rm unlock.sh home/.ssh/config` and add your own.
|
Just `git rm unlock.sh ssh/config` and add your own.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
|
|
7
config.def.sh
Normal file
7
config.def.sh
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# Where to install the dotfiles, usually $HOME.
|
||||||
|
DESTDIR="$HOME"
|
||||||
|
|
||||||
|
# Git user information.
|
||||||
|
GIT_USER="Fernando Schauenburg"
|
||||||
|
GIT_EMAIL="dev@schauenburg.me"
|
||||||
|
|
|
@ -51,6 +51,7 @@ done <<EOL
|
||||||
$LOCAL_PREFIX/opt/gnu-tar/libexec/gnubin
|
$LOCAL_PREFIX/opt/gnu-tar/libexec/gnubin
|
||||||
$LOCAL_PREFIX/opt/coreutils/libexec/gnubin
|
$LOCAL_PREFIX/opt/coreutils/libexec/gnubin
|
||||||
$HOME/.local/bin
|
$HOME/.local/bin
|
||||||
|
$HOME/.bin
|
||||||
EOL
|
EOL
|
||||||
export PATH
|
export PATH
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
IPython.CodeCell.options_default.cm_config.autoCloseBrackets = false;
|
|
|
@ -1,11 +0,0 @@
|
||||||
{
|
|
||||||
"Notebook": {
|
|
||||||
"Header": false,
|
|
||||||
"Toolbar": false
|
|
||||||
},
|
|
||||||
"CodeCell": {
|
|
||||||
"cm_config": {
|
|
||||||
"lineNumbers": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
231
install.sh
231
install.sh
|
@ -1,106 +1,91 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
# shellcheck disable=SC1090,SC1091
|
||||||
|
|
||||||
DOTFILES="$(dirname "$(realpath "$0")")"
|
dotfiles="$(dirname "$(realpath "$0")")"
|
||||||
TARGET="$HOME"
|
|
||||||
|
|
||||||
# shellcheck disable=SC1091 # don't complain about following config.local
|
if [ -t 1 ]; then
|
||||||
[ -r "$DOTFILES/config.local" ] && . "$DOTFILES/config.local"
|
sgr0="$(printf '\033[0m')"
|
||||||
|
red="$(printf '\033[31m')"
|
||||||
|
green="$(printf '\033[32m')"
|
||||||
|
yellow="$(printf '\033[33m')"
|
||||||
|
blue="$(printf '\033[34m')"
|
||||||
|
# magenta="$(printf '\033[35m')"
|
||||||
|
cyan="$(printf '\033[36m')"
|
||||||
|
else
|
||||||
|
sgr0=''
|
||||||
|
red=''
|
||||||
|
green=''
|
||||||
|
yellow=''
|
||||||
|
blue=''
|
||||||
|
# magenta=''
|
||||||
|
cyan=''
|
||||||
|
fi
|
||||||
|
|
||||||
GIT_USER="${GIT_USER:-Fernando Schauenburg}"
|
error() {
|
||||||
GIT_EMAIL="${GIT_EMAIL:-dev@schauenburg.me}"
|
printf "${red}ERROR:$sgr0 %s\n" "$1"
|
||||||
|
exit 1
|
||||||
main() {
|
|
||||||
IS_DRY_RUN=yes
|
|
||||||
while getopts 'fht:' opt; do case "$opt" in
|
|
||||||
f) unset IS_DRY_RUN;;
|
|
||||||
t) TARGET="$OPTARG";;
|
|
||||||
h) usage; exit 0;;
|
|
||||||
*) usage; exit 1;;
|
|
||||||
esac done
|
|
||||||
|
|
||||||
check_dependencies
|
|
||||||
greeting
|
|
||||||
make_dirs
|
|
||||||
stow_home
|
|
||||||
link_config
|
|
||||||
git_user_config
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_dependencies() {
|
heading(){
|
||||||
for cmd in stow readlink; do
|
echo "${blue}===== $1 ==========$sgr0";
|
||||||
if ! command -v "$cmd" >/dev/null 2>&1; then
|
}
|
||||||
error "Dependency \`$cmd\` not found."
|
|
||||||
exit 1
|
load_config() {
|
||||||
fi
|
defconfig="$dotfiles/config.def.sh"
|
||||||
done
|
config="$dotfiles/config.sh"
|
||||||
|
{ [ -r "$config" ] || cp -v "$defconfig" "$config"; } || error "can't create config.sh"
|
||||||
|
. "$config"
|
||||||
|
}
|
||||||
|
|
||||||
|
is_dry_run() { [ "$DRY_RUN" = "yes" ]; }
|
||||||
|
|
||||||
|
move_aside() {
|
||||||
|
backup="$1.$(date +%s)"
|
||||||
|
echo "${red}WARNING:$sgr0 moving '$1' to '$backup'"
|
||||||
|
is_dry_run || mv "$1" "$backup"
|
||||||
}
|
}
|
||||||
|
|
||||||
greeting() {
|
greeting() {
|
||||||
dry_run && {
|
is_dry_run && {
|
||||||
warn "Performing dry run (use -f to actually make changes)."
|
echo "${yellow}Performing dry run (use -f to actually make changes).$sgr0"
|
||||||
warn
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
info "Deploying dotfiles:"
|
echo "Deploying dotfiles:"
|
||||||
info " Source: $cyan$DOTFILES$rst"
|
echo " Source: $cyan$dotfiles$sgr0"
|
||||||
info " Target: $cyan$TARGET$rst"
|
echo " Destination: $cyan$DESTDIR$sgr0"
|
||||||
info " Git user: $green$GIT_USER <$GIT_EMAIL>$rst"
|
echo " Git user: $green$GIT_USER <$GIT_EMAIL>$sgr0"
|
||||||
|
|
||||||
if [ -t 0 ] && [ -t 1 ]; then
|
if [ -t 0 ] && [ -t 1 ]; then
|
||||||
info
|
echo
|
||||||
info "Press ENTER to continue (CTRL-C to cancel)..."
|
echo "Press ENTER to continue (CTRL-C to cancel)..."
|
||||||
read -r
|
read -r
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
make_dirs() {
|
make_dir() {
|
||||||
heading 'create auxiliary directories'
|
if [ -d "$1" ]; then
|
||||||
while read -r item; do
|
echo "${green}OK:$sgr0 $1"
|
||||||
dir="$TARGET/$item"
|
else
|
||||||
if [ ! -d "$dir" ]; then
|
echo "${yellow}MKDIR:$sgr0 $1"
|
||||||
echo "${yellow}MKDIR:$rst $dir"
|
is_dry_run || mkdir -vp "$1"
|
||||||
dry_run || mkdir -p "$dir"
|
|
||||||
fi
|
|
||||||
done <<EOF
|
|
||||||
.local/share/less/
|
|
||||||
.local/share/python/
|
|
||||||
.local/share/nvim/shada/
|
|
||||||
.local/share/zsh/
|
|
||||||
.local/etc/git/
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
link_config() {
|
|
||||||
heading 'link .config directory'
|
|
||||||
|
|
||||||
link="$TARGET/.config"
|
|
||||||
dotfiles_config="$DOTFILES/config"
|
|
||||||
backup="$TARGET/old_dot_config"
|
|
||||||
|
|
||||||
if [ "$(readlink "$link")" != "$dotfiles_config" ]; then
|
|
||||||
if [ -d "$link" ]; then
|
|
||||||
echo "${red}WARNING:$rst moving existing '$link' to '$backup'"
|
|
||||||
dry_run || mv "$link" "$backup"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "${yellow}LINK:$rst $link $blue=>$rst $dotfiles_config"
|
|
||||||
dry_run || ln -s "$dotfiles_config" "$link"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
stow_home() {
|
make_link() {
|
||||||
heading 'stow home directory'
|
link="$1"
|
||||||
stow -v${IS_DRY_RUN:+n} --no-folding -d "$DOTFILES" -t "$TARGET" home 2>&1 \
|
target="$2"
|
||||||
| sed -E \
|
if [ -e "$link" ] && [ "$(realpath "$link")" = "$target" ]; then
|
||||||
-e "s/^(WARNING:)/$red\1$rst/" \
|
echo "${green}OK:$sgr0 $link $blue->$sgr0 $target"
|
||||||
-e "s/^([^:]+:)/$yellow\1$rst/" \
|
else
|
||||||
-e "s/=>/$blue=>$rst/"
|
[ -e "$link" ] && move_aside "$link"
|
||||||
|
echo "${yellow}LINK:$sgr0 $link $blue->$sgr0 $target"
|
||||||
|
is_dry_run || ln -sf "$target" "$link"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
git_user_config() {
|
make_git_user_config() {
|
||||||
heading 'git user configuration'
|
user_config="$DESTDIR/.local/etc/git/config.user"
|
||||||
config_file="$TARGET/.local/etc/git/config.user"
|
|
||||||
temp_git="$(mktemp)"
|
temp_git="$(mktemp)"
|
||||||
cat >"$temp_git" <<EOF
|
cat >"$temp_git" <<EOF
|
||||||
# *************************************
|
# *************************************
|
||||||
|
@ -113,54 +98,60 @@ git_user_config() {
|
||||||
# ~/.local/etc/git/config
|
# ~/.local/etc/git/config
|
||||||
#
|
#
|
||||||
EOF
|
EOF
|
||||||
git config -f "$temp_git" user.name "${GIT_USER}"
|
git config -f "$temp_git" user.name "$GIT_USER"
|
||||||
git config -f "$temp_git" user.email "${GIT_EMAIL}"
|
git config -f "$temp_git" user.email "$GIT_EMAIL"
|
||||||
|
|
||||||
if ! diff "$config_file" "$temp_git" >/dev/null 2>&1; then
|
if diff "$user_config" "$temp_git" >/dev/null 2>&1; then
|
||||||
if [ -f "$config_file" ]; then action=OVERWRITE; else action=CREATE; fi
|
echo "${green}OK:$sgr0 $user_config has '$GIT_USER <$GIT_EMAIL>'"
|
||||||
echo "$yellow$action:$rst $config_file with contents of $temp_git:"
|
else
|
||||||
echo "$cyan"
|
[ -f "$user_config" ] && move_aside "$user_config"
|
||||||
cat "$temp_git"
|
echo "${yellow}WRITE:$sgr0 $user_config with '$GIT_USER <$GIT_EMAIL>'"
|
||||||
echo "$rst"
|
is_dry_run || cp -f "$temp_git" "$user_config"
|
||||||
dry_run || cp -f "$temp_git" "$config_file"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Helper Functions
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
if [ -t 1 ]; then
|
|
||||||
rst="$(printf '\033[0m')"
|
|
||||||
red="$(printf '\033[31m')"
|
|
||||||
green="$(printf '\033[32m')"
|
|
||||||
yellow="$(printf '\033[33m')"
|
|
||||||
blue="$(printf '\033[34m')"
|
|
||||||
# magenta="$(printf '\033[35m')"
|
|
||||||
cyan="$(printf '\033[36m')"
|
|
||||||
else
|
|
||||||
rst=''
|
|
||||||
red=''
|
|
||||||
green=''
|
|
||||||
yellow=''
|
|
||||||
blue=''
|
|
||||||
# magenta=''
|
|
||||||
cyan=''
|
|
||||||
fi
|
|
||||||
|
|
||||||
dry_run() { [ -n "$IS_DRY_RUN" ]; }
|
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: $(basename "$0") [-h] [-f] [-t <target>]"
|
echo "Usage: $(basename "$0") [-h] [-f]"
|
||||||
echo ""
|
echo ""
|
||||||
echo " -h print this help and exit"
|
echo " -h print this help and exit"
|
||||||
echo " -f modify filesystem rather than dry run"
|
echo " -f modify filesystem rather than dry run"
|
||||||
echo " -t set <target> directory (default: \$HOME)"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
heading() { echo "${blue}===== $1 ==========${rst}"; }
|
main() {
|
||||||
info() { echo "$*"; }
|
DRY_RUN=yes
|
||||||
warn() { echo "${yellow}$*${rst}"; }
|
while getopts 'fh' opt; do case "$opt" in
|
||||||
error() { echo "${red}$*${rst}"; }
|
f) DRY_RUN=no;;
|
||||||
|
h) usage; exit 0;;
|
||||||
|
*) usage; exit 1;;
|
||||||
|
esac done
|
||||||
|
|
||||||
|
load_config || error "could not load config.sh"
|
||||||
|
|
||||||
|
[ -n "$DESTDIR" ] || error "\$DESTDIR must be set in config.sh"
|
||||||
|
[ -n "$GIT_USER" ] || error "\$GIT_USER must be set in config.sh"
|
||||||
|
[ -n "$GIT_EMAIL" ] || error "\$GIT_EMAIL must be set in config.sh"
|
||||||
|
|
||||||
|
greeting
|
||||||
|
|
||||||
|
heading 'create required directories'
|
||||||
|
make_dir "$DESTDIR/.ssh/"
|
||||||
|
make_dir "$DESTDIR/.local/etc/git/"
|
||||||
|
make_dir "$DESTDIR/.local/share/less/"
|
||||||
|
make_dir "$DESTDIR/.local/share/python/"
|
||||||
|
make_dir "$DESTDIR/.local/share/nvim/shada/"
|
||||||
|
make_dir "$DESTDIR/.local/share/zsh/"
|
||||||
|
|
||||||
|
heading 'create links'
|
||||||
|
make_link "$DESTDIR/.hushlogin" "$dotfiles/home/.hushlogin"
|
||||||
|
make_link "$DESTDIR/.XCompose" "$dotfiles/home/.XCompose"
|
||||||
|
make_link "$DESTDIR/.zshenv" "$dotfiles/home/.zshenv"
|
||||||
|
make_link "$DESTDIR/.bin" "$dotfiles/bin"
|
||||||
|
make_link "$DESTDIR/.config" "$dotfiles/config"
|
||||||
|
make_link "$DESTDIR/.ssh/config" "$dotfiles/ssh/config"
|
||||||
|
|
||||||
|
heading 'git user configuration'
|
||||||
|
make_git_user_config
|
||||||
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue