From 432e36183af9d53c0e8d66846b54b182ad90ef3b Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Thu, 8 Nov 2018 09:34:17 -0600 Subject: [PATCH] Sway stuff and setup scripts overhaul --- de/sway/dm_entry | 5 +++ scripts/setup_helpers.bash | 78 ++++++++++++++++++++++++++++++++++++++ setup | 74 +++++++++--------------------------- shell/bash/bashrc | 56 ++++++++++++++------------- sudo_setup | 21 ++++++++++ 5 files changed, 152 insertions(+), 82 deletions(-) create mode 100644 de/sway/dm_entry create mode 100644 scripts/setup_helpers.bash create mode 100755 sudo_setup diff --git a/de/sway/dm_entry b/de/sway/dm_entry new file mode 100644 index 0000000..db4aca3 --- /dev/null +++ b/de/sway/dm_entry @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=Sway +Comment=SirCmpwn's Wayland window manager +Exec=sway-lytedev +Type=Application diff --git a/scripts/setup_helpers.bash b/scripts/setup_helpers.bash new file mode 100644 index 0000000..330c86a --- /dev/null +++ b/scripts/setup_helpers.bash @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +dfp=$(cd "$(dirname "${BASH_SOURCE[0]}" )/.." && pwd) +source "${dfp}/shell/bash/bashrc" + +USER_DISAGREE_CODE=120 +NO_AGREEMENT_CODE=121 + +_dotfiles_setup_check_agreement() { + local -r lock_file="$1" + + # Let user know that this script will delete their current configuration and + # that they should read this script before running. We'll use a lock file so + # the user only needs to agree once. + if [ -f "$lock_file" ]; then + # User agreed already - do nothing + echo -e "\nLinking files...\n" + else + echo -e "\nRunning this script may delete existing personal configuration files." + echo "Please view this script's source, fully understand it, and backup any" + echo "files before continuing." + echo -e "\nSeriously. Like... entire directories. Just gone. Completely.\n" + read -r -p "Are you sure you want to continue? [y/N] " response + response=${response,,} # to lower case + if [[ $response =~ ^(yes|y)$ ]]; then + echo "agreed" > "$lock_file" + else + return "${USER_DISAGREE_CODE}" + fi + fi +} +export -f _dotfiles_setup_check_agreement + +_dotfiles_setup_link_files() { + local links=("$@") + + source_file="" + for i in "${links[@]}"; do + if [ -n "$source_file" ]; then + if [ -L "$i" ]; then # if symlink exists, delete it + rm -rf "$i" + fi + if [ -f "$i" ]; then # if file exists, delete it + rm -rf "$i" + fi + if [ -d "$i" ]; then # if directory exists, delete it + rm -rf "$i" + fi + # check if the directory that will contain the link exists + DIR_TO_LINK=$(dirname "$i") + if [ -d "$DIR_TO_LINK" ]; then + : + else + mkdir -p "$DIR_TO_LINK" + fi + ln -s "$source_file" "$i" + echo -e " Linking (from/to):\n ~/$(realpath --relative-to="$HOME" "$source_file")\n $i" + source_file="" + else + source_file="$i" + fi + done + echo -e "\nDone.\n" +} +export -f _dotfiles_setup_link_files + +_dotfiles_setup_run_setup() { + local -r lock_file="$1" && shift + + if _dotfiles_setup_check_agreement "$lock_file"; then + _dotfiles_setup_link_files "$@" + else + echo "Quitting due to lack of user agreement." + return "${NO_AGREEMENT_CODE}" + fi + +} +export -f _dotfiles_setup_run_setup diff --git a/setup b/setup index 9be2217..ef97074 100755 --- a/setup +++ b/setup @@ -1,34 +1,10 @@ #!/usr/bin/env bash -if [[ -z "$XDG_CONFIG_HOME" ]]; then - export XDG_CONFIG_HOME="$HOME/.config" -fi +# TODO: ascii art header dfp=$(cd "$(dirname "${BASH_SOURCE[0]}" )/" && pwd) +source "${dfp}/scripts/setup_helpers.bash" -ALERT_AGREEMENT_FILE="$dfp/.agreed-to-erasing-files.lock" - -# Let user know that this script will delete their current configuration and -# that they should read this script before running. We'll use a lock file so -# the user only needs to agree once. -if [ -f "$ALERT_AGREEMENT_FILE" ]; then - # User agreed already - do nothing - echo "Linking..." -else - echo "Running this script may delete existing personal configuration files." - echo "Please view this script's source, fully understand it, and backup any" - echo "files before continuing." - echo "Seriously. Like... entire directories. Just gone." - read -r -p "Are you sure you want to continue? [y/N] " response - response=${response,,} # to lower case - if [[ $response =~ ^(yes|y)$ ]]; then - echo "agreed" > "$ALERT_AGREEMENT_FILE" - else - exit 1 - fi -fi - -# TODO: make sure we have an even number, here links=( # desktop environment files "$dfp/de/sway/config" "$XDG_CONFIG_HOME/sway/config" @@ -54,9 +30,9 @@ links=( "$dfp/scripts/colors/vim" "$XDG_CONFIG_HOME/nvim/colors/base16-donokai.vim" # gtk configuration files - "$dfp/de/gtk/2rc" "$HOME/.gtkrc-2.0" - "$dfp/de/gtk/2rc" "$HOME/.gtkrc" - "$dfp/de/gtk/3settings.ini" "$XDG_CONFIG_HOME/gtk-3.0/settings.ini" + "$dfp/de/gtk/2rc" "$HOME/.gtkrc-2.0" + "$dfp/de/gtk/2rc" "$HOME/.gtkrc" + "$dfp/de/gtk/3settings.ini" "$XDG_CONFIG_HOME/gtk-3.0/settings.ini" # irc files "$dfp/apps/irssi/" "$HOME/.irssi" @@ -98,31 +74,17 @@ links=( "$dfp/shell/user-dirs" "$XDG_CONFIG_HOME/user-dirs.dirs" ) -source="" -for i in "${links[@]}"; do - if [ -n "$source" ]; then - if [ -L "$i" ]; then # if symlink exists, delete it - rm -rf "$i" - fi - if [ -f "$i" ]; then # if file exists, delete it - rm -rf "$i" - fi - if [ -d "$i" ]; then # if directory exists, delete it - rm -rf "$i" - fi - # check if the directory that will contain the link exists - DIR_TO_LINK=$(dirname "$i") - if [ -d "$DIR_TO_LINK" ]; then - : - else - mkdir -p "$DIR_TO_LINK" - fi - ln -s "$source" "$i" - echo "Linked $(basename $source) to $i." - source="" - else - source="$i" - fi -done +_dotfiles_setup_run_setup "$dfp/.agreed-to-erasing-files.lock" "${links[@]}" -echo "Done." +echo -n -e "Do you want to run the sudo_setup script for changes to /etc" +echo -n -e "\nand other root directories?" +read -r -p " [y/N] " response +response=${response,,} # to lower case +if [[ $response =~ ^(yes|y)$ ]]; then + "$dfp/sudo_setup" +else + :: +fi + +echo -e "Dotfiles Installed! Running 'exec bash'...\n" +exec bash diff --git a/shell/bash/bashrc b/shell/bash/bashrc index 842a2f5..1e903ac 100644 --- a/shell/bash/bashrc +++ b/shell/bash/bashrc @@ -1,22 +1,22 @@ #!/usr/bin/env bash -# bashrc is executed when a bash process starts - -# these are all paths used across all the dotfiles and should be assumed to be -# loaded and properly set by every script - this means you are responsible for -# making sure they're loaded! +# these are all paths used across many of the dotfiles and should be assumed to +# be loaded and properly set by every script - this means you are responsible +# for making sure they're loaded! export XDG_CONFIG_HOME="$HOME/.config" export DOTFILES_PATH="$XDG_CONFIG_HOME/dotfiles" NICE_HOME="$HOME" +# TODO: better logic for auto-detecting alternative home directories? +# 1. check dirname(basename $HOME)) matches username +# 2. check /home/$username [[ $(basename "${HOME}") = "usr" ]] && NICE_HOME="$(realpath "$HOME/..")" [[ $(basename "${HOME}") = ".home" ]] && NICE_HOME="$(realpath "$HOME/..")" +# TODO: nice home explicitly definable on a per-device (env) basis export NICE_HOME export NOTES_DIR="$NICE_HOME/doc/notes" -# TODO: nice home on a per-device basis - # set our PATH source "$DOTFILES_PATH/shell/bash/paths" @@ -27,10 +27,10 @@ source "$DOTFILES_PATH/shell/bash/aliases" source "$DOTFILES_PATH/shell/bash/autocompletions" # load our key binds -bind -f "$DOTFILES_PATH/shell/inputrc" - -# less tab size of 2 spaces -LESS="-x2" +case $- in + *i*) bind -f "$DOTFILES_PATH/shell/inputrc";; + *) ;; +esac # stop parsing on a non-interactive shell [ -z "$PS1" ] && return @@ -59,9 +59,26 @@ source "$DOTFILES_PATH/shell/bash/prompt" shopt -s histverify # prevents some Java GUI apps from not working or rendering properly due to -# using bspwm +# using wacky window managers export _JAVA_AWT_WM_NONREPARENTING=1 +LS_COLORS='ow=01;36;40' +export LS_COLORS + +# less tab size of 2 spaces +LESS="-x2" +export LESS + +# set our EDITOR to neovim if we've got it +export EDITOR="vim" +if command -v nvim >/dev/null 2>&1; then + alias vim="nvim" + alias ovim="\\vim" + export EDITOR="nvim" +fi + +export BROWSER="firefox-developer-edition" + # load a per-device config last so anything can be overridden if [ -a "$HOME/.env_bashrc" ]; then source "$HOME/.env_bashrc" @@ -72,22 +89,9 @@ fi # directory where they keep the stuff they actually care about # we only do this if the user is opening a shell at $HOME if [ "$PWD" = "$HOME" ]; then - cd "$NICE_HOME" + cd "$NICE_HOME" || cd || return fi _make_paths -LS_COLORS='ow=01;36;40' -export LS_COLORS - -# set our EDITOR to neovim if we've got it -export EDITOR="vim" -if command -v nvim >/dev/null 2>&1; then - alias vim="nvim" - alias ovim="\\vim" - export EDITOR="nvim" -fi - -export BROWSER="firefox" - [ -f ~/.fzf.bash ] && source ~/.fzf.bash diff --git a/sudo_setup b/sudo_setup new file mode 100755 index 0000000..6123564 --- /dev/null +++ b/sudo_setup @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# TODO: ascii art header + +if [[ $UID -ne 0 ]]; then + echo "Re-running with 'sudo -E'..." + sudo -E "$0" "$@" + exit +fi + +dfp=$(cd "$(dirname "${BASH_SOURCE[0]}" )/" && pwd) +source "${dfp}/scripts/setup_helpers.bash" + +links=( + # display manager configuration files + "$dfp/de/sway/sway-init" "/usr/bin/sway-lytedev" + "$dfp/de/sway/dm_entry" "/usr/share/wayland-sessions/sway-lytedev.desktop" +) + +_dotfiles_setup_run_setup "$dfp/.agreed-to-erasing-root-files.lock" "${links[@]}" +