From 4008fa4f12d6688c580a78980e4722899a84498c Mon Sep 17 00:00:00 2001 From: Matt Singleton Date: Fri, 12 Apr 2024 16:06:30 -0500 Subject: Update Makefile to manage fedora/sway-de config --- .gitignore | 5 +- Makefile | 68 +++++++++++++---- README.md | 33 ++++----- cleanup.sh | 32 ++++---- local/duplicity-config | 4 - local/duplicity-excludes | 5 -- local/vimrc-local | 0 stow/duplicity/.local/bin/backup | 27 ------- .../.local/share/systemd/user/backup.service | 7 -- .../.local/share/systemd/user/backup.timer | 9 --- sway-de/install.sh | 85 ---------------------- .../udiskie/.config/systemd/user/udiskie.service | 15 ++++ .../.local/share/systemd/user/udiskie.service | 15 ---- .../.config/systemd/user/xdg-names.service | 14 ++++ .../.local/share/systemd/user/xdg-names.service | 14 ---- 15 files changed, 113 insertions(+), 220 deletions(-) delete mode 100644 local/duplicity-config delete mode 100644 local/duplicity-excludes create mode 100644 local/vimrc-local delete mode 100755 stow/duplicity/.local/bin/backup delete mode 100644 stow/duplicity/.local/share/systemd/user/backup.service delete mode 100644 stow/duplicity/.local/share/systemd/user/backup.timer delete mode 100755 sway-de/install.sh create mode 100644 sway-de/udiskie/.config/systemd/user/udiskie.service delete mode 100644 sway-de/udiskie/.local/share/systemd/user/udiskie.service create mode 100644 sway-de/xdg-names/.config/systemd/user/xdg-names.service delete mode 100644 sway-de/xdg-names/.local/share/systemd/user/xdg-names.service diff --git a/.gitignore b/.gitignore index fd22466..de63cc8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -stow/zsh/.config/zsh/00-local.zsh stow/git/.config/git/config-local -stow/duplicity/.config/duplicity/config -stow/duplicity/.config/duplicity/excludes +stow/vim/.vimrc-local +stow/zsh/.config/zsh/00-local.zsh diff --git a/Makefile b/Makefile index bbdaf73..6f6fc48 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,66 @@ REPO_CHANGES := $(shell git status --porcelain | wc -l) +DEV_MODE := 0 +IS_FEDORA := $(shell command -v dnf > /dev/null && test -f /etc/fedora-release; echo $$?) .PHONY: .initialize .initialize: ifneq ($(REPO_CHANGES),0) - $(error cannot run with a dirty repo. stash or commit changes.) +ifeq ($(DEV_MODE),0) + $(error will not run with a dirty repo. stash or commit changes, or re-run with DEV_MODE=1.) +endif endif git submodule update --init --recursive - -.PHONY: .local -.local: - mkdir -p stow/duplicity/.config/duplicity - cp --update=none local/duplicity-config stow/duplicity/.config/duplicity/config - cp --update=none local/duplicity-excludes stow/duplicity/.config/duplicity/excludes + cp --update=none local/vimrc-local stow/vim/.vimrc-local cp --update=none local/gitconfig-local stow/git/.config/git/config-local cp --update=none local/local.zsh stow/zsh/.config/zsh/00-local.zsh .PHONY: console -console: .initialize .local - stow --adopt --dir=stow --target=${HOME} console-utils - stow --adopt --dir=stow --target=${HOME} dircolors - stow --adopt --dir=stow --target=${HOME} git - stow --adopt --dir=stow --target=${HOME} vim - stow --adopt --dir=stow --target=${HOME} zsh - stow --adopt --dir=stow --target=${HOME} duplicity +console: .initialize + stow --adopt --dir=stow --target=$(HOME) console-utils + stow --adopt --dir=stow --target=$(HOME) dircolors + stow --adopt --dir=stow --target=$(HOME) git + stow --adopt --dir=stow --target=$(HOME) vim + stow --adopt --dir=stow --target=$(HOME) zsh + +.PHONY: fedora-packages +fedora-packages: +ifneq ($(IS_FEDORA),0) + $(warning not fedora workstation, skipping.) +else + sudo dnf install \ + "https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(shell rpm -E %fedora).noarch.rpm" \ + "https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(shell rpm -E %fedora).noarch.rpm" + sudo dnf install \ + sway waybar rofi-wayland foot mako intel-one-mono-fonts \ + udiskie libappindicator-gtk3 python3-b2sdk pass passmenu \ + vlc unzip vim wget git zsh stow dnf-automatic \ + grimshot pulseaudio-utils thunar pavucontrol-qt \ + network-manager-applet +endif + +.PHONY: fedora +fedora: console +ifneq ($(IS_FEDORA),0) + $(warning not fedora workstation, skipping.) +else + stow --adopt --dir=sway-de --target=$(HOME) foot + stow --adopt --dir=sway-de --target=$(HOME) mako + stow --adopt --dir=sway-de --target=$(HOME) rofi + stow --adopt --dir=sway-de --target=$(HOME) sway + stow --adopt --dir=sway-de --target=$(HOME) swaylock + stow --adopt --dir=sway-de --target=$(HOME) udiskie + stow --adopt --dir=sway-de --target=$(HOME) waybar + stow --adopt --dir=sway-de --target=$(HOME) xdg-names +ifeq ($(shell systemctl --user is-active sway-session.target),active) + systemctl --user enable --now udiskie.service + systemctl --user enable --now xdg-names.service +else + systemctl --user enable udiskie.service + systemctl --user enable xdg-names.service +endif + sudo systemctl enable --now dnf-automatic-install.timer +endif +.PHONY: restore restore: - git restore . + git restore stow sway-de diff --git a/README.md b/README.md index 0c8d64f..f6b672b 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,14 @@ -Install dotfiles with the deploy script: - - $ sh deploy.sh - -Tries to follow the [XDG base directory -spec](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) -as much as possible. - -The script does the following: - - * Clear out `$PWD/dotfiles-backup/`. - * Symlink everything under `config` into `$XDG_CONFIG_HOME`. Moves everything - that already exists to `$PWD/dotfiles-backup/` first. - * Symlink everything under `home` into `$HOME`. Again back up existing files to - `$PWD/dotfiles-backup`. - * Clone Vundle into `~/.vim/bundle/vundle/` and run `BundleInstall`. - * Copy files under `local` into the appropriate locations only if they don't - already exist. These are for handling local configuration that shouldn't or - can't be version controlled. +Manages dotfiles with stow and make. + +Make targets: + * `console`: configs for os-independent cli tools + * `fedora-packages`: install rpmfusion and fedora packages (standalone, should + only need to be run once unless new packages or repos are added) + * `fedora`: configs for fedora-specific gui tools (depends on `console`) + * `restore`: restore committed versions of files in `stow\` and `sway-de/` + +Note: stow is run with the `--adopt` option, which will overwrite files in the +stow directory with the version that would be replaced with a symlink. You can +do a `git diff` to see the differences and if you don't care about them you can +quickly revert to the committed versions with `make restore`. Makefile will do +it's best to abort if there are uncommitted changes in the repo. diff --git a/cleanup.sh b/cleanup.sh index a0d6944..7061e55 100755 --- a/cleanup.sh +++ b/cleanup.sh @@ -9,21 +9,19 @@ set -euo pipefail -to_delete=" -.local/bin/color_test -.local/bin/utf8_demo -.config/dircolors.conf -.config/git -.vim/autoload -.vim/plugged -.vimrc -.config/zsh -.zshenv -.local/bin/backup -.local/share/systemd/user/backup.service -.local/share/systemd/user/backup.timer -" +# symlinks +rm -f "$HOME/.config/dircolors.conf" +rm -f "$HOME/.config/git" +rm -f "$HOME/.config/zsh" +rm -f "$HOME/.local/bin/backup" +rm -f "$HOME/.local/bin/color_test" +rm -f "$HOME/.local/bin/utf8_demo" +rm -f "$HOME/.local/share/systemd/user/backup.service" +rm -f "$HOME/.local/share/systemd/user/backup.timer" +rm -f "$HOME/.vimrc" +rm -f "$HOME/.zshenv" -for i in $to_delete; do - rm -rf "$HOME/${i:?}" -done +# directories +rm -rf "$HOME/.vim/autoload" +rm -rf "$HOME/.vim/bundle" +rm -rf "$HOME/.vim/plugged" diff --git a/local/duplicity-config b/local/duplicity-config deleted file mode 100644 index f9607b0..0000000 --- a/local/duplicity-config +++ /dev/null @@ -1,4 +0,0 @@ -PASSPHRASE= -FTP_PASSWORD= -B2_KEY_ID= -B2_BUCKET= diff --git a/local/duplicity-excludes b/local/duplicity-excludes deleted file mode 100644 index 122b565..0000000 --- a/local/duplicity-excludes +++ /dev/null @@ -1,5 +0,0 @@ -/home/matt/Downloads -/home/matt/.local -/home/matt/.cache -/home/matt/.mozilla -/home/matt/.wine diff --git a/local/vimrc-local b/local/vimrc-local new file mode 100644 index 0000000..e69de29 diff --git a/stow/duplicity/.local/bin/backup b/stow/duplicity/.local/bin/backup deleted file mode 100755 index 6324c05..0000000 --- a/stow/duplicity/.local/bin/backup +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -set -o allexport -# shellcheck source=../../.config/duplicity/config -source ~/.config/duplicity/config -set +o allexport - -source_directory=~ -excludes=~/.config/duplicity/excludes -target_url=b2://"$B2_KEY_ID"@"$B2_BUCKET" - -# take a new full backup every month, incremental otherwise -duplicity backup --full-if-older-than 1M --exclude-filelist "$excludes" "$source_directory" "$target_url" - -# keep 12 months of full backups -duplicity remove-all-but-n-full 12 --force "$target_url" - -# keep 3 months of incremental backups -duplicity remove-all-inc-of-but-n-full 3 --force "$target_url" - -# cleanup -duplicity cleanup --force "$target_url" - -# show collection status -duplicity collection-status "$target_url" diff --git a/stow/duplicity/.local/share/systemd/user/backup.service b/stow/duplicity/.local/share/systemd/user/backup.service deleted file mode 100644 index c1adfde..0000000 --- a/stow/duplicity/.local/share/systemd/user/backup.service +++ /dev/null @@ -1,7 +0,0 @@ -[Unit] -Description=Backup with duplicity -After=network.target - -[Service] -Type=oneshot -ExecStart=bash ${HOME}/.local/bin/backup diff --git a/stow/duplicity/.local/share/systemd/user/backup.timer b/stow/duplicity/.local/share/systemd/user/backup.timer deleted file mode 100644 index b7815d6..0000000 --- a/stow/duplicity/.local/share/systemd/user/backup.timer +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Run backup every four hours - -[Timer] -OnCalendar=*-*-* 0/4:15 -Persistent=true - -[Install] -WantedBy=timers.target diff --git a/sway-de/install.sh b/sway-de/install.sh deleted file mode 100755 index ccef98f..0000000 --- a/sway-de/install.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/bash -# -# Designed for Fedora Workstation -# -# Installs and configures sway and related tools to provide a richer -# "desktop environment" style session. Relies on systemd for running -# services as much as possible. - -set -euo pipefail - -script_path="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -if [ ! "$(pwd)" = "$script_path" ]; then - echo "expects to be run from the root sway-de directory" - exit 1 -fi - -if ! command -v dnf > /dev/null !! [ ! -f /etc/fedora-release ]; then - echo "doesn't seem to be fedora workstation" - exit 1 -fi - - -# give the option to skip installing packages since dnf can be slow -skip_packages="" -while [[ $# -gt 0 ]]; do - case $1 in - --skip-packages) - skip_packages=1 - shift - ;; - *) - shift - ;; - esac -done - -if [ -z "$skip_packages" ]; then - - # install rpmfusion if it's not already installed - repos_installed="$(dnf --cacheonly repolist | tail -n+2 | cut -f1 -d' ' | awk '/(^rpmfusion-free$)|(^rpmfusion-nonfree$)/' | wc -l)" - if [ "$repos_installed" -lt "2" ]; then - sudo dnf install \ - "https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm" \ - "https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm" - fi - - # install packages - sudo dnf install \ - sway waybar rofi-wayland foot mako \ - udiskie libappindicator-gtk3 duplicity python3-b2sdk pass passmenu \ - vlc unzip vim wget git zsh stow dnf-automatic \ - grimshot pulseaudio-utils thunar pavucontrol-qt \ - network-manager-applet - -fi - -# make sure stow is installed. -# it should be at this point, so if it's not, die with a message -# to re-run without skipping the package install step. -STOWCMD="" -if command -v stow > /dev/null; then - STOWCMD="stow" -fi -if [ -z "$STOWCMD" ]; then - echo "requires 'stow'. run without '--skip-packages' to install." - exit 1 -fi - -# use stow to install config files -$STOWCMD \ - --dir "$(pwd)" \ - --target "$HOME" \ - foot mako rofi sway swaylock udiskie waybar xdg-names - -# enable new systemd units and start them if sway is running -for unit in udiskie.service xdg-names.service; do - if systemctl --user is-active sway-session.target; then - systemctl --user enable --now "$(basename "$unit")" - else - systemctl --user enable "$(basename "$unit")" - fi -done - -# enable dnf automatic updates -sudo systemctl enable --now dnf-automatic-install.timer diff --git a/sway-de/udiskie/.config/systemd/user/udiskie.service b/sway-de/udiskie/.config/systemd/user/udiskie.service new file mode 100644 index 0000000..ba7e7f0 --- /dev/null +++ b/sway-de/udiskie/.config/systemd/user/udiskie.service @@ -0,0 +1,15 @@ +[Unit] +Description=Handle automounting of usb devices +Documentation=man:udiskie(1) +PartOf=sway-session.target + +[Service] +Type=simple +ExecStart=/usr/bin/udiskie -s +ExecStop=/bin/kill -2 $MAINPID +Restart=on-failure +RestartSec=1 +TimeoutStopSec=10 + +[Install] +WantedBy=sway-session.target diff --git a/sway-de/udiskie/.local/share/systemd/user/udiskie.service b/sway-de/udiskie/.local/share/systemd/user/udiskie.service deleted file mode 100644 index ba7e7f0..0000000 --- a/sway-de/udiskie/.local/share/systemd/user/udiskie.service +++ /dev/null @@ -1,15 +0,0 @@ -[Unit] -Description=Handle automounting of usb devices -Documentation=man:udiskie(1) -PartOf=sway-session.target - -[Service] -Type=simple -ExecStart=/usr/bin/udiskie -s -ExecStop=/bin/kill -2 $MAINPID -Restart=on-failure -RestartSec=1 -TimeoutStopSec=10 - -[Install] -WantedBy=sway-session.target diff --git a/sway-de/xdg-names/.config/systemd/user/xdg-names.service b/sway-de/xdg-names/.config/systemd/user/xdg-names.service new file mode 100644 index 0000000..799431b --- /dev/null +++ b/sway-de/xdg-names/.config/systemd/user/xdg-names.service @@ -0,0 +1,14 @@ +[Unit] +Description=Rename Sway workspaces based on XDG metadata +PartOf=sway-session.target + +[Service] +Type=simple +ExecStart=%h/.local/bin/xdg-names.py --debug +ExecStop=/bin/kill -2 $MAINPID +Restart=on-failure +RestartSec=1 +TimeoutStopSec=10 + +[Install] +WantedBy=sway-session.target diff --git a/sway-de/xdg-names/.local/share/systemd/user/xdg-names.service b/sway-de/xdg-names/.local/share/systemd/user/xdg-names.service deleted file mode 100644 index 799431b..0000000 --- a/sway-de/xdg-names/.local/share/systemd/user/xdg-names.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=Rename Sway workspaces based on XDG metadata -PartOf=sway-session.target - -[Service] -Type=simple -ExecStart=%h/.local/bin/xdg-names.py --debug -ExecStop=/bin/kill -2 $MAINPID -Restart=on-failure -RestartSec=1 -TimeoutStopSec=10 - -[Install] -WantedBy=sway-session.target -- cgit v1.2.3