From 4527c3c87c603398876c6441395c66535311af46 Mon Sep 17 00:00:00 2001
From: Daniel Flanagan
Date: Tue, 1 Feb 2022 17:10:13 -0600
Subject: [PATCH] Add nginx public share stuff - should probably move some
stuff to ansible?
---
common/bin/dotfiles-init | 81 ++++++++++---------
common/envs | 1 +
common/fish/functions.fish | 2 +-
common/fish/vars.fish | 2 +
common/htop/rc | 2 +-
common/neovim/coc-settings.json | 54 ++++++++++++-
common/tmux/conf | 70 ++++++++--------
.../.nginx-autoindex-after.html | 1 +
.../.nginx-autoindex-before.html | 60 ++++++++++++++
.../nginx-user-public/dotfiles-setup.d.fish | 11 +++
.../nginx-user-public/user-public-http.conf | 13 +++
.../nginx-user-public/user-public-server.conf | 13 +++
host/layer/personal/dotfiles-setup.d.fish | 8 ++
13 files changed, 240 insertions(+), 78 deletions(-)
create mode 100644 host/layer/nginx-user-public/.nginx-autoindex-after.html
create mode 100644 host/layer/nginx-user-public/.nginx-autoindex-before.html
create mode 100644 host/layer/nginx-user-public/dotfiles-setup.d.fish
create mode 100644 host/layer/nginx-user-public/user-public-http.conf
create mode 100644 host/layer/nginx-user-public/user-public-server.conf
create mode 100644 host/layer/personal/dotfiles-setup.d.fish
diff --git a/common/bin/dotfiles-init b/common/bin/dotfiles-init
index 3594349..e9b8718 100755
--- a/common/bin/dotfiles-init
+++ b/common/bin/dotfiles-init
@@ -8,52 +8,55 @@ export CURDIR
dfp="$(realpath "$(dirname "$0")"/../..)"
detect_os() {
- # NixOS
- if head /etc/os-release --lines 1 | grep 'NixOS$' >/dev/null 2>&1; then
- ln -s "$dfp/os/linux/nix" "$ENV_PATH/os-linux-nix" >/dev/null 2>&1
- return
- fi
+ # NixOS
+ if head /etc/os-release --lines 1 | grep 'NixOS$' > /dev/null 2>&1; then
+ ln -s "$dfp/os/linux/nix" "$ENV_PATH/os-linux-nix" > /dev/null 2>&1
+ return
+ fi
- # Arch Linux
- if head /etc/os-release --lines 1 | grep 'Arch Linux' >/dev/null 2>&1; then
- ln -s "$dfp/os/linux/arch" "$ENV_PATH/os-linux-arch" >/dev/null 2>&1
- return
- fi
+ # Arch Linux
+ if head /etc/os-release --lines 1 | grep 'Arch Linux' > /dev/null 2>&1; then
+ ln -s "$dfp/os/linux/arch" "$ENV_PATH/os-linux-arch" > /dev/null 2>&1
+ return
+ fi
- # Pacman-based
- if command -v pacman; then
- ln -s "$dfp/os/linux/arch" "$ENV_PATH/os-linux-arch" >/dev/null 2>&1
- return
- fi
+ # Pacman-based
+ if command -v pacman; then
+ ln -s "$dfp/os/linux/arch" "$ENV_PATH/os-linux-arch" > /dev/null 2>&1
+ return
+ fi
- # TODO: Debian
+ # TODO: Debian
- echo "Failed to auto-detect your OS! Please setup your environments and run this script again."
- exit 3
+ echo "Failed to auto-detect your OS! Please setup your environments and run this script again."
+ exit 3
}
-if command -v git >/dev/null 2>&1; then
- if [ -f "$dfp/common/envs" ]; then
- # TODO: more shared init stuff?
- mkdir -p $ENV_PATH
- detect_os
- ls -la -R $ENV_PATH/*
- find "$ENV_PATH" | while read -r s; do
- f="$s/dotfiles-init.d.sh"
- if [ -f "$f" ]; then
- CURDIR="$s"
- . "$f"
- fi
- done
- $dfp/common/bin/dotfiles-setup
- else
- git clone "https://git.lyte.dev/lytedev/dotfiles.git" "$XDG_CONFIG_HOME/lytedev-dotfiles"
- cd "$XDG_CONFIG_HOME/lytedev-dotfiles" || { echo "Could not cd to dotfiles dir"; exit 2; }
- . ./common/bin/dotfiles-init
- fi
+if command -v git > /dev/null 2>&1; then
+ if [ -f "$dfp/common/envs" ]; then
+ # TODO: more shared init stuff?
+ mkdir -p "$ENV_PATH"
+ detect_os
+ ls -la -R "$ENV_PATH/*"
+ find "$ENV_PATH" | while read -r s; do
+ f="$s/dotfiles-init.d.sh"
+ if [ -f "$f" ]; then
+ CURDIR="$s"
+ . "$f"
+ fi
+ done
+ $dfp/common/bin/dotfiles-setup
+ else
+ git clone "https://git.lyte.dev/lytedev/dotfiles.git" "$XDG_CONFIG_HOME/lytedev-dotfiles"
+ cd "$XDG_CONFIG_HOME/lytedev-dotfiles" || {
+ echo "Could not cd to dotfiles dir"
+ exit 2
+ }
+ . ./common/bin/dotfiles-init
+ fi
else
- echo "git not installed"
- exit 1
+ echo "git not installed"
+ exit 1
fi
# TODO: run provision script
diff --git a/common/envs b/common/envs
index 4b3a558..c14dd3d 100644
--- a/common/envs
+++ b/common/envs
@@ -22,3 +22,4 @@ host/laptop/postmates-macbook
host/laptop/uber-macbook
host/laptop/val-macbook
host/layer/personal
+host/layer/nginx-user-public
diff --git a/common/fish/functions.fish b/common/fish/functions.fish
index 10b868e..e32d927 100644
--- a/common/fish/functions.fish
+++ b/common/fish/functions.fish
@@ -142,7 +142,7 @@ alias cdltl "cd (ltld)"
alias p "ping 8.8.8.8"
function pp --description "Keeps trying to ping 8.8.8.8 forever"
- while not ping -n 1 -t 5 8.8.8.8
+ while not ping -n 1 -w 5 8.8.8.8
sleep 1
end
end
diff --git a/common/fish/vars.fish b/common/fish/vars.fish
index 2b0e249..6514e7f 100644
--- a/common/fish/vars.fish
+++ b/common/fish/vars.fish
@@ -25,4 +25,6 @@ else if command --search --quiet vi
set --export --universal VISUAL vi
end
+set --export --universal SOPS_AGE_KEY_FILE "$XDG_CONFIG_HOME/sops/age/keys.txt"
+
# has_command fd && set -Ux FZF_DEFAULT_COMMAND 'fd --type f --hidden --follow --exclude .git'
diff --git a/common/htop/rc b/common/htop/rc
index b1cd180..da3a701 100644
--- a/common/htop/rc
+++ b/common/htop/rc
@@ -3,7 +3,7 @@
htop_version=3.1.2
config_reader_min_version=2
fields=0 48 17 18 38 39 40 2 46 47 49 1
-sort_key=47
+sort_key=46
sort_direction=-1
tree_sort_key=0
tree_sort_direction=1
diff --git a/common/neovim/coc-settings.json b/common/neovim/coc-settings.json
index d4195fd..9461396 100644
--- a/common/neovim/coc-settings.json
+++ b/common/neovim/coc-settings.json
@@ -1,5 +1,5 @@
{
- "coc.preferences.formatOnSaveFiletypes": ["elixir", "ex", "exs", "typescript", "css", "markdown"],
+ "coc.preferences.formatOnSaveFiletypes": ["elixir", "ex", "exs", "typescript", "css", "markdown", "sh", "bash"],
"languageserver": {
"nim": {
"command": "nimlsp",
@@ -17,9 +17,55 @@
},
"elixir.pathToElixirLS": "~/.elixir-ls/release/language_server.sh",
"rust-analyzer.checkOnSave.command": "clippy",
- "diagnostic-languageserver.filetypes": {
- "elixir": ["mix_credo", "mix_credo_compile"],
- "eelixir": ["mix_credo", "mix_credo_compile"]
+ "diagnostic-languageserver": {
+ "enable": true,
+ "mergeConfig": true,
+ "linters": {
+ "shellcheck": {
+ "command": "shellcheck",
+ "debounce": 100,
+ "args": [
+ "-x",
+ "--format",
+ "json1",
+ "-"
+ ],
+ "sourceName": "shellcheck",
+ "parseJson": {
+ "errorsRoot": "comments",
+ "line": "line",
+ "column": "column",
+ "endLine": "endLine",
+ "endColumn": "endColumn",
+ "message": "${message} [${code}]",
+ "security": "level"
+ },
+ "securities": {
+ "error": "error",
+ "warning": "warning",
+ "info": "info",
+ "style": "hint"
+ }
+ }
+ },
+ "filetypes": {
+ "elixir": ["mix_credo", "mix_credo_compile"],
+ "eelixir": ["mix_credo", "mix_credo_compile"],
+ "sh": "shellcheck",
+ "bash": "shellcheck"
+ },
+ "formatters": {
+ "shfmt": {
+ "command": "shfmt",
+ "args": ["-i", "2", "-bn", "-ci", "-sr", "-kp"]
+ }
+ },
+ "formatFiletypes": {
+ "elixir": "mix_format",
+ "eelixir": "mix_format",
+ "sh": "shfmt",
+ "bash": "shfmt"
+ }
}
}
diff --git a/common/tmux/conf b/common/tmux/conf
index 5530295..1203785 100644
--- a/common/tmux/conf
+++ b/common/tmux/conf
@@ -1,26 +1,28 @@
unbind C-b
set -g prefix C-s
-bind-key s send-prefix
+bind s send-prefix
-bind-key v split-window -h
-bind-key b split-window
-bind-key T source-file "$HOME/.tmux.conf" \; display-message "Reloaded $HOME/.tmux.conf"
-bind-key O display-message "#(tmux-save-buffer '#S')"
-bind-key H set -s status
-bind-key -n C-l select-pane -R
-bind-key -n C-k select-pane -U
-bind-key -n C-j select-pane -D
-bind-key -n C-h select-pane -L
-bind-key -n C-t new-window
-bind-key Tab next-window
-bind-key -n C-Tab next-window
-bind-key -n C-S-Tab previous-window
+bind v split-window -h
+bind b split-window
+bind T source-file "$HOME/.tmux.conf" \; display-message "Reloaded $HOME/.tmux.conf"
+bind O display-message "#(tmux-save-buffer '#S')"
+bind D attach-session -t . -c '#{pane_current_path}' \; display-message "Set session path to #{pane_current_path}"
+bind H set -s status
+bind -n C-l select-pane -R
+bind -n C-k select-pane -U
+bind -n C-j select-pane -D
+bind -n C-h select-pane -L
+bind -n C-t new-window
+bind Tab next-window
+bind -n C-Tab next-window
+bind -n C-S-Tab previous-window
bind s run "tmux split-window -l 12 'tmuxswitcher'"
bind M-l source-file "$XDG_CONFIG_HOME/tmux/layouts/dev.tmux"
set -g update-environment "WAYLAND_DISPLAY DISPLAY"
+# TODO: check if kitty is installed?
set -g default-terminal "kitty"
set -g mouse on
set -g escape-time 0
@@ -42,7 +44,11 @@ set -g window-status-separator ""
set -g window-status-current-format " #W"
set -g status-left "#h:#S #W"
set -g status-right-length 280
-set -g status-right "#(kubeline && printf ' ')#{pane_current_path} #(cd '#{pane_current_path}' && git rev-parse --abbrev-ref --sq HEAD | tr -d \"'\")#{pane_current_command}"
+set -g status-right "#(kubeline && printf ' ')"
+ set -ag status-right "#(pwd | $XDG_CONFIG_HOME/lytedev-dotfiles/common/bin/glancepath) "
+ set -ag status-right "#(cd '#{pane_current_path}' && git rev-parse --abbrev-ref --sq HEAD | tr -d \"'\")"
+ set -ag status-right "#{pane_current_command}"
+
set -g message-style "fg=colour7 bg=colour18"
set -g pane-active-border-style bg=black,fg=blue
set -g pane-border-style bg=black,fg=colour18
@@ -54,29 +60,27 @@ set -g window-status-current-format ""
# present a menu of urls to open from the visible pane
# TODO: fzf-ify this
-bind-key u capture-pane \;\
- save-buffer /tmp/tmux-buffer \;\
- split-window -l 10 "urlscan /tmp/tmux-buffer"
+# bind u capture-pane \;\
+# save-buffer /tmp/tmux-buffer \;\
+# split-window -l 10 "urlscan /tmp/tmux-buffer"
-bind-key -T copy-mode-vi "y" send-keys -X copy-pipe-and-cancel 'wl-copy'
-bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel 'wl-copy'; \
+bind -T copy-mode-vi "y" send-keys -X copy-pipe-no-clear 'wl-copy' \; display-message 'Copied to clipboard!'
+bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-no-clear 'wl-copy' \; display-message 'Copied to clipboard!'
-bind-key K kill-pane
-bind-key C-S-k kill-window
+bind K kill-pane
+bind C-S-k kill-window
# TODO: handle tmux nesting by being able to toggle the prefix (and indicate in status bar?)
-# bind -T root F12 \
-# set prefix None \;\
-# set key-table off \;\
-# set status off \
-# if -F "#{pane_in_mode}" "send-keys -X cancel" \;\
-# refresh-client -S \;\
+# TODO: styles after `set -u key-table`
+#if -F '#{pane_in_mode}' 'send-keys -X cancel' \;\
+bind -T root F12 set -g prefix None \; set -g key-table off \; display-message "Keys OFF" \; refresh-client -S
-# bind -T off F12 \
-# set -u prefix \;\
-# set -u key-table \;\
-# set status on \;\
-# refresh-client -S
+# TODO: styles after `set -u key-table`
+bind -T off F12 \
+ set -g -u prefix \;\
+ set -g -u key-table \;\
+ display-message "Keys ON" \;\
+ refresh-client -S
source-file "$ENV_PATH/*/tmux.d.conf"
diff --git a/host/layer/nginx-user-public/.nginx-autoindex-after.html b/host/layer/nginx-user-public/.nginx-autoindex-after.html
new file mode 100644
index 0000000..a446d53
--- /dev/null
+++ b/host/layer/nginx-user-public/.nginx-autoindex-after.html
@@ -0,0 +1 @@
+
diff --git a/host/layer/nginx-user-public/dotfiles-setup.d.fish b/host/layer/nginx-user-public/dotfiles-setup.d.fish
new file mode 100644
index 0000000..15ea258
--- /dev/null
+++ b/host/layer/nginx-user-public/dotfiles-setup.d.fish
@@ -0,0 +1,11 @@
+#!/usr/bin/env fish
+set me (status -f)
+set dfp $argv[1]
+set h $argv[2]
+set c $argv[3]
+
+pushd (dirname $me)
+sudo ln -s (pwd)/user-public-http.conf /etc/nginx/user-public-http.conf
+sudo ln -s (pwd)/user-public-server.conf /etc/nginx/user-public-server.conf
+sudo ln -s (pwd)/.nginx-autoindex-before.html /usr/share/nginx/html/.nginx-autoindex-before.html
+sudo ln -s (pwd)/.nginx-autoindex-after.html /usr/share/nginx/html/.nginx-autoindex-after.html
diff --git a/host/layer/nginx-user-public/user-public-http.conf b/host/layer/nginx-user-public/user-public-http.conf
new file mode 100644
index 0000000..5b63a87
--- /dev/null
+++ b/host/layer/nginx-user-public/user-public-http.conf
@@ -0,0 +1,13 @@
+disable_symlinks off;
+
+# for wasm games
+types {
+ application/octet-stream clr;
+ application/octet-stream pdb;
+}
+
+gzip on;
+gzip_min_length 10240;
+gzip_proxied expired no-cache no-store private auth;
+gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/json application/xml application/wasm;
+gzip_disable msie6;
diff --git a/host/layer/nginx-user-public/user-public-server.conf b/host/layer/nginx-user-public/user-public-server.conf
new file mode 100644
index 0000000..c430984
--- /dev/null
+++ b/host/layer/nginx-user-public/user-public-server.conf
@@ -0,0 +1,13 @@
+# need CORS?
+# location ~* \.(eot|ttf|woff|woff2)$ {
+# add_header Access-Control-Allow-Origin *;
+# }
+
+location ~ ^/~(.+?)(/.*)?$ {
+ disable_symlinks off;
+ alias /home/$1/public$2;
+ index index.html index.htm;
+ autoindex on;
+ add_before_body "/.nginx-autoindex-before.html";
+ add_after_body "/.nginx-autoindex-after.html";
+}
diff --git a/host/layer/personal/dotfiles-setup.d.fish b/host/layer/personal/dotfiles-setup.d.fish
new file mode 100644
index 0000000..b1241a8
--- /dev/null
+++ b/host/layer/personal/dotfiles-setup.d.fish
@@ -0,0 +1,8 @@
+#!/usr/bin/env fish
+set me (status -f)
+set dfp $argv[1]
+set h $argv[2]
+set c $argv[3]
+
+pushd (dirname $me)
+# l app $c/app
diff --git a/host/layer/nginx-user-public/.nginx-autoindex-before.html b/host/layer/nginx-user-public/.nginx-autoindex-before.html
new file mode 100644
index 0000000..f7b6f40
--- /dev/null
+++ b/host/layer/nginx-user-public/.nginx-autoindex-before.html
@@ -0,0 +1,60 @@
+
+