#!/bin/bash ### # This file is part of the code-cloppers openbox setup. Use at your own risk. # # This script should setup openbox for a user on ubuntu set -eo pipefail is-in-path() { which "$1" &>>/dev/null } install-apt-dependencies() { echo "=> Installing apt dependencies" set -x sudo apt-get update && \ sudo apt-get install \ xcompmgr \ openbox \ rofi \ plank \ dunst \ numix-icon-theme-circle \ vorbis-tools \ sound-theme-freedesktop \ terminator \ xscreensaver \ nitrogen \ trayer set +x } are-in-path() { [[ $# -gt 0 ]] || return 0 is-in-path "$1" || return 1 shift are-in-path "$@" } asset-dirs-exist() { [[ -d /usr/share/icons/Numix-Circle ]] && [[ -d /usr/share/sounds/freedesktop ]] } install-dependencies() { echo "=> Checking dependencies" if ! are-in-path xcompmgr openbox dunst ogg123 terminator xscreensaver nitrogen \ || ! asset-dirs-exist; then install-apt-dependencies fi declare notify_send_dir='' notify_send_dir="$(local-dir)/applications/notify-send.sh" if ! [[ -d "$notify_send_dir" ]]; then mkdir -p "$notify_send_dir" git clone git@github.com:vlevit/notify-send.sh.git "$notify_send_dir" || rm "$notify_send_dir" fi } here() { dirname "$(readlink -f "${BASH_SOURCE[0]}")" } config-dir() { if ! [[ $# -ge 1 ]]; then echo "$(caller) Expected argument" >&2 return 1 fi declare app="$1" echo "$HOME/.config/$app" } create-dir-if-not-exists() { [[ -d $1 ]] || mkdir -p "$1" } copy-files-in-dir-to() { declare source="$1" destination="$2" create-dir-if-not-exists "$destination" cp -r "$source/"* "$destination"/ } copy-config() { echo "=> Copying config" copy-files-in-dir-to "$(here)/config/openbox" "$(config-dir openbox)" copy-files-in-dir-to "$(here)/config/dunst" "$(config-dir dunst)" copy-files-in-dir-to "$(here)/config/terminator" "$(config-dir terminator)" cp -b "$(here)/config/xscreensaver/config-file" ~/.xscreensaver copy-files-in-dir-to "$(here)/config/gtk/gtk-3" "$(config-dir gtk-3.0)" cp -b "$(here)/config/gtk/gtk-2/rc" ~/.gtkrc-2.0 } add-custom-startup() { declare startup_file='' [[ -z $startup_file ]] && startup_file="$HOME/.startup" printf '. "%s"\n' "$startup_file" >> "$(config-dir openbox)/autostart.sh" } os-is-ubuntu-1804() { [[ $(cat /etc/os-release | grep VERSION_ID | grep -Po '(?<=").*(?=")') == '18.04' ]] } cache-dir() { echo "$HOME/.cache/clopper-ob" } theme-dir() { echo "$HOME/.local/share/themes" } local-dir() { echo "$HOME/.local/share/clopper-ob" } create-theme-dir() { create-dir-if-not-exists "$(theme-dir)" } create-cache-dir() { create-dir-if-not-exists "$(cache-dir)" } create-local-dir() { create-dir-if-not-exists "$(local-dir)" } copy-bins-to-local-dir() { cp -r "$(here)/bin" "$(local-dir)/" } copy-libs-to-local-dir() { cp -r "$(here)/lib" "$(local-dir)/" } copy-themes-to-theme-dir() { cp -r "$(here)/themes"/* "$(theme-dir)/" } create-user-config-if-not-created() { if ! [[ -f ~/.code-clopper-ob ]]; then echo '=> Creating user config' echo -n > ~/.code-clopper-ob fi } config-get() { declare -u value_name="$1" grep -Po '(?<=^'"$value_name"'=")[^"]+(?="$)' ~/.code-clopper-ob } config-has() { config-get "$1" &>>/dev/null } config-add() { declare -u value_name="$1" declare value="$2" printf '%s="%s"\n' "$value_name" "$value" >> ~/.code-clopper-ob } check-config() { declare startup_script='' if ! config-has startup_script; then read -rep "Please provide a path to a custom startup script for your sessions (default: ~/.startup):" \ startup_script if [[ -z $startup_script ]]; then startup_script="$HOME/.startup" fi config-add startup_script "$startup_script" fi if ! config-has desktop_background; then read -rep "Pleade provide a file to use as desktop background, leave blank for none: " \ background if [[ -z $background ]]; then config-add desktop_background none else config-add desktop_background "$background" fi fi } configure-dock() { declare dock_items='' [[ -d ~/.local/share/plank ]] || mkdir -p ~/.local/share/plank cp -r "$(here)/config/plank/themes" ~/.local/share/plank { cat "$(here)/config/plank/dconf-file" dconf dump /net/launchpad/plank/docks/dock1/ | grep ^dock-items } | dconf load /net/launchpad/plank/docks/dock1/ } add-custom-background() { if [[ $(config-get desktop_background) != 'none' ]]; then printf 'nitrogen --set-auto %s\n' "$(config-get desktop_background)" \ >> "$(config-dir openbox)/autostart.sh" fi } setup-openbox-for-user() { install-dependencies copy-config create-cache-dir create-local-dir create-theme-dir copy-bins-to-local-dir copy-libs-to-local-dir copy-themes-to-theme-dir configure-dock create-user-config-if-not-created check-config add-custom-startup add-custom-background echo '=> Finished. You might want to run "openbox --restart" ' \ '(or for initial setup "openbox --exit" and then login again)' } setup-openbox-for-user