2019-01-10 10:45:52 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-02-18 22:29:26 +01:00
|
|
|
# Environments
|
2019-01-10 10:45:52 +01:00
|
|
|
LAPTOP="laptop"
|
|
|
|
DESKTOP="desk"
|
2023-02-18 22:29:26 +01:00
|
|
|
ENV_EXT_REGEXP=".*\.${LAPTOP}|.*\.${DESKTOP}"
|
|
|
|
|
|
|
|
# Special filename for external config path
|
2019-02-24 21:20:30 +01:00
|
|
|
DEST_FILENAME="dest"
|
2019-01-10 10:45:52 +01:00
|
|
|
|
2023-02-18 22:29:26 +01:00
|
|
|
# Special configuration filename
|
|
|
|
BASE_CONFIG="config_common"
|
|
|
|
MERGE_CONFIG_FOLDER="config.d"
|
|
|
|
FINAL_CONFIG="config"
|
|
|
|
|
|
|
|
# Special directories with per-environment configuration merge
|
|
|
|
I3_CONFIG="i3"
|
|
|
|
POLYBAR_CONFIG="polybar"
|
|
|
|
ARCH_PACKAGES="bootstrap"
|
|
|
|
MERGE_DIRS="${I3_CONFIG} ${POLYBAR_CONFIG} ${ARCH_PACKAGES}"
|
|
|
|
|
2023-10-28 23:13:37 +02:00
|
|
|
changed_files="$(git --git-dir=$HOME/.cfg/ --work-tree=$HOME diff-tree -r --name-status --no-commit-id HEAD^1 HEAD)"
|
|
|
|
|
2019-11-14 15:35:59 +01:00
|
|
|
# Check if a file has been modified and deleted since last commit, if so perform an action
|
2023-10-28 23:13:37 +02:00
|
|
|
# $1 : absolute path of the file
|
2019-11-14 15:35:59 +01:00
|
|
|
# $2 : command to launch if file has been created of modifed
|
|
|
|
# $3 : command to launch if file has been deleted
|
|
|
|
function check_copy() {
|
2023-02-18 22:29:26 +01:00
|
|
|
# When initializing, always copy files
|
|
|
|
if [ ! -z ${INIT} ]; then
|
|
|
|
echo -e "* Running \"$2\"" && eval "$2"
|
|
|
|
return
|
|
|
|
fi
|
2023-10-28 23:13:37 +02:00
|
|
|
changed_file=`grep "${1#$HOME/}" <<< "${changed_files}"`
|
|
|
|
if [ ! -z "${changed_file}" ]; then
|
|
|
|
if echo "$changed_file" | grep -q -E "^D"; then
|
2019-11-14 15:35:59 +01:00
|
|
|
echo "* $1 has been removed"
|
2019-11-18 23:36:59 +01:00
|
|
|
echo -e "\t* Running \"$3\"" && eval "$3"
|
2023-10-28 23:13:37 +02:00
|
|
|
fi
|
|
|
|
if echo "$changed_file" | grep -q -E "^(A|M)"; then
|
|
|
|
echo "* Changes detected in $(basename $1)"
|
|
|
|
echo -e "\t* Running \"$2\"" && eval "$2"
|
2019-11-14 15:35:59 +01:00
|
|
|
fi
|
2023-02-18 22:29:26 +01:00
|
|
|
else
|
|
|
|
echo "$1 not modified, no need to copy"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Generates a `config` file in $1, by merging a required $1/{MERGE_CONFIG_FOLDER} file
|
|
|
|
# with an optional `$1/config.d/$2` file. This is useful for having
|
|
|
|
# a common base for multiple computer, and per-computer stuff.
|
|
|
|
# $1 : path of the folder
|
|
|
|
# $2 : optional current environment
|
2023-10-28 23:13:37 +02:00
|
|
|
# $3 : if defined, prepend $2 instead of appending
|
2023-02-18 22:29:26 +01:00
|
|
|
function merge_config() {
|
|
|
|
echo -e "\n=== Generate ${m} config file ==="
|
|
|
|
rm -f ${CONFIG}/${m}/${FINAL_CONFIG}
|
|
|
|
# Copy common config
|
|
|
|
cp ${CONFIG}/${m}/${BASE_CONFIG} ${CONFIG}/${m}/${FINAL_CONFIG}
|
|
|
|
echo "${CONFIG}/${m}/${FINAL_CONFIG} created"
|
|
|
|
# If there is an override folder, merge given env
|
|
|
|
if [ ! -z ${2} ] && [ -d ${CONFIG}/${m}/${MERGE_CONFIG_FOLDER} ]; then
|
|
|
|
for f in `find ${CONFIG}/${m}/config.d -type f -path "*${2}"`; do
|
2023-10-28 23:13:37 +02:00
|
|
|
final_path=${CONFIG}/${m}/${FINAL_CONFIG}
|
2023-10-28 23:52:40 +02:00
|
|
|
if [ -z $3 ]; then
|
2023-10-28 23:13:37 +02:00
|
|
|
echo "Found ${f}, append to regular config file"
|
|
|
|
cat "${f}" >> ${final_path}
|
|
|
|
else
|
|
|
|
echo "Found ${f}, prepend to regular config file"
|
|
|
|
cat ${f} > /tmp/config
|
|
|
|
echo -e '\n' >> /tmp/config
|
|
|
|
cat ${final_path} >> /tmp/config
|
|
|
|
mv /tmp/config ${final_path}
|
|
|
|
fi
|
2023-02-18 22:29:26 +01:00
|
|
|
done
|
2019-11-14 15:35:59 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-01-10 10:45:52 +01:00
|
|
|
function usage() {
|
2023-02-18 22:29:26 +01:00
|
|
|
echo "${0}: manage package installation, environment divergence and external location for config, see README."
|
|
|
|
echo "usage: [WM_RESTART=1] [INIT=1] $0 [${ENVIRONMENTS}]"
|
2019-01-10 10:45:52 +01:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2019-02-24 21:20:30 +01:00
|
|
|
# Use XDG_CONFIG_HOME if defined, default otherwise
|
|
|
|
CONFIG=${XDG_CONFIG_HOME:-$HOME/.config}
|
|
|
|
|
2023-02-18 22:29:26 +01:00
|
|
|
ENV=${1}
|
2019-01-10 10:45:52 +01:00
|
|
|
|
2023-02-18 22:29:26 +01:00
|
|
|
for m in ${MERGE_DIRS}; do
|
2023-10-28 23:52:40 +02:00
|
|
|
if [ -f "${CONFIG}/${m}/${MERGE_CONFIG_FOLDER}/above" ]; then
|
2023-10-28 23:13:37 +02:00
|
|
|
merge_config $m ${ENV} true
|
|
|
|
else
|
|
|
|
merge_config $m ${ENV}
|
|
|
|
fi
|
2019-01-26 19:24:25 +01:00
|
|
|
done
|
|
|
|
|
2023-02-18 22:29:26 +01:00
|
|
|
if [ ! -z "$INIT" ]; then
|
|
|
|
echo -e "* Installing base Arch packages..."
|
|
|
|
yay -Syu --needed --noconfirm - < ${CONFIG}/${ARCH_PACKAGES}/${FINAL_CONFIG}
|
|
|
|
echo -e "* Changing shell to ZSH..."
|
2023-10-28 20:35:46 +02:00
|
|
|
sudo chsh -s $(which zsh)
|
2023-02-18 22:29:26 +01:00
|
|
|
# https://man.archlinux.org/man/rofi-dmenu.5
|
|
|
|
echo -e "* Symlink dmenu → rofi..."
|
2023-04-11 11:50:02 +02:00
|
|
|
sudo ln -sf /usr/bin/rofi /usr/bin/dmenu
|
2023-10-28 18:21:46 +02:00
|
|
|
echo -e "* Enabling required systemd units..."
|
2023-02-18 22:29:26 +01:00
|
|
|
sudo systemctl enable --now NetworkManager
|
2023-10-28 18:21:46 +02:00
|
|
|
sudo systemctl enable --now systemd-timesyncd
|
2023-11-07 12:09:47 +01:00
|
|
|
sudo systemctl enable --now cups
|
2023-12-03 18:42:21 +01:00
|
|
|
sudo systemctl enable --now bluetooth
|
2023-12-03 18:45:21 +01:00
|
|
|
sudo systemctl enable --now bluetooth-autoconnect
|
2023-10-28 20:35:46 +02:00
|
|
|
# iwd will be used as a backend for NetworkManager
|
|
|
|
sudo systemctl disable wpa_supplicant
|
2023-10-28 18:21:46 +02:00
|
|
|
echo -e "* Ensure hardware clock is up to date..."
|
|
|
|
sudo hwclock --systohc
|
2023-10-28 20:35:46 +02:00
|
|
|
# So that "Open in Terminal" works inc Nemo
|
2023-10-28 18:21:46 +02:00
|
|
|
echo -e "* Make 'Open Terminal' work in Nemo..."
|
2023-02-19 00:49:30 +01:00
|
|
|
gsettings set org.cinnamon.desktop.default-applications.terminal exec i3-sensible-terminal
|
2023-02-19 11:01:41 +01:00
|
|
|
# For screenshots
|
2023-10-28 18:21:46 +02:00
|
|
|
echo -e "* Install pychee for uploading screenshots on Lychee..."
|
|
|
|
pip install --break-system-packages pychee
|
2023-02-20 14:03:38 +01:00
|
|
|
# Additionnal plugins for ZSH
|
2023-10-28 18:21:46 +02:00
|
|
|
echo -e "* Install ZSH plugins for oh-my-zsh..."
|
2023-12-19 21:32:31 +01:00
|
|
|
sudo git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git /usr/share/oh-my-zsh/plugins/fast-syntax-highlighting
|
2023-02-20 14:03:38 +01:00
|
|
|
sudo git clone https://github.com/zsh-users/zsh-autosuggestions /usr/share/oh-my-zsh/plugins/zsh-autosuggestions
|
|
|
|
sudo git clone https://github.com/unixorn/fzf-zsh-plugin.git /usr/share/oh-my-zsh/plugins/fzf-zsh-plugin
|
2023-12-18 21:58:40 +01:00
|
|
|
echo -e "* Install everything we need for Catppuccin themes..."
|
|
|
|
echo -e "\tFor polybar..."
|
2023-12-19 21:32:31 +01:00
|
|
|
wget https://raw.githubusercontent.com/catppuccin/polybar/main/themes/mocha.ini -O ~/.config/polybar/mocha.ini
|
|
|
|
echo -e "\tFor zsh..."
|
|
|
|
sudo mkdir -p /usr/local/share/fsh
|
|
|
|
sudo wget https://raw.githubusercontent.com/catppuccin/zsh-fsh/main/themes/catppuccin-mocha.ini -O /usr/local/share/fsh/catpuccin-mocha.ini
|
2023-10-28 18:21:46 +02:00
|
|
|
# Basic directory structure
|
|
|
|
echo -e "* Create base home directories..."
|
|
|
|
mkdir -p ~/documents ~/images/screenshots ~/videos ~/downloads
|
2023-10-29 00:26:31 +02:00
|
|
|
echo -e "* Allow user to control brightness..."
|
|
|
|
sudo usermod $(whoami) -aG video
|
2023-11-07 12:17:22 +01:00
|
|
|
echo -e "* Allow user to administrate printers..."
|
|
|
|
sudo usermod $(whoami) -aG wheel
|
2023-10-29 22:47:38 +01:00
|
|
|
echo -e "* Install host app for PassFF Firefox extension..."
|
|
|
|
curl -sSL github.com/passff/passff-host/releases/latest/download/install_host_app.sh | bash -s -- firefox
|
2023-11-08 01:18:29 +01:00
|
|
|
echo -e "* Set Firefox to be the default browser, probably overwritten by Chromium..."
|
|
|
|
xdg-settings set default-web-browser firefox.desktop
|
2023-12-03 17:52:26 +01:00
|
|
|
echo -e "* Ensure keyboard will still be in AZERTY mode when plugged/unplugged..."
|
|
|
|
# This creates a Xorg configuration file
|
|
|
|
sudo localectl --no-convert set-x11-keymap fr
|
2023-12-18 14:30:12 +01:00
|
|
|
echo -e "* Create a symlink rrm → rm (rm will be an alias to rmtrash) in zsh"
|
2023-12-18 20:00:52 +01:00
|
|
|
echo -e "* Install synchronization extension for VSCode settings and plugins..."
|
|
|
|
# Avoid to push whole extensions up to hundreds of MB, and avoid using
|
|
|
|
# Micro$oft proprietary stuff, usable with any git server
|
|
|
|
vscodium --install-extension zokugun.sync-settings
|
|
|
|
git clone git@git.chosto.me:Chosto/codium-settings.git ~/.config/codium-settings
|
|
|
|
echo -e "* Install plugin to pick theme for Terminator..."
|
|
|
|
# See https://github.com/EliverLara/terminator-themes
|
|
|
|
mkdir -p $HOME/.config/terminator/plugins
|
|
|
|
wget https://git.io/v5Zww -O $HOME"/.config/terminator/plugins/terminator-themes.py"
|
2023-02-18 22:29:26 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -z ${ENV} ]; then
|
|
|
|
echo -e "\n=== Create symlink to *.${ENV} regular files ==="
|
|
|
|
# Take all specific files and create a symlink pointing to it without the extension
|
|
|
|
# This file will be used by applications
|
|
|
|
for f in `find ${CONFIG} -type f -name "*.${ENV}"`; do
|
|
|
|
echo "${f%.*} → ${f}"
|
|
|
|
ln -sf ${f} ${f%.*}
|
|
|
|
done
|
|
|
|
# Take care of config files at home level, outside ${CONFIG} (e.g. Xresources)
|
|
|
|
for f in `find ${HOME} -maxdepth 1 -mindepth 1 -type f -name "*.${ENV}"`; do
|
|
|
|
echo "${f%.*} → ${f}"
|
|
|
|
ln -sf ${f} ${f%.*}
|
|
|
|
done
|
|
|
|
fi
|
2019-02-24 21:20:30 +01:00
|
|
|
|
2019-11-14 15:35:59 +01:00
|
|
|
echo -e "\n=== Copy changed configuration which resides in outer directory ==="
|
2019-02-24 21:20:30 +01:00
|
|
|
# Destination files are regular files
|
|
|
|
for f in `find ${CONFIG} -type f -name ${DEST_FILENAME}`; do
|
|
|
|
DIR=`dirname "${f}"`
|
|
|
|
DEST=`cat ${f}`
|
|
|
|
# Get all files, either regular files or symlinks, which are not the destination file nor specific desktop/laptop files
|
|
|
|
# This is because if desktop/laptop files exist, they already have a symlink pointing to them at this stage
|
2023-10-28 20:35:46 +02:00
|
|
|
# We want to get the path relative to the directory we are searching in, so subfolders are kept when copying
|
|
|
|
for config_file in `find ${DIR} -regextype posix-extended -mindepth 1 \( -type f -o -type l \) -not \( -regex "${ENV_EXT_REGEXP}" -o -name "${DEST_FILENAME}" \) -exec realpath --relative-to ${DIR} {} \;`; do
|
|
|
|
# If we have to copy to a subfolder, extract it
|
|
|
|
if echo ${config_file} | grep -q '/'; then
|
|
|
|
subfolder=${config_file%/*}
|
|
|
|
else
|
|
|
|
subfolder=''
|
|
|
|
fi
|
|
|
|
filename=${config_file##*/}
|
2019-02-24 21:20:30 +01:00
|
|
|
# Now copy to destination
|
2023-10-28 20:35:46 +02:00
|
|
|
real_dest=${DEST}/${subfolder}
|
|
|
|
sudo mkdir -p ${real_dest}
|
|
|
|
absolute_source=`realpath "${DIR}/${config_file}"`
|
2023-10-28 23:13:37 +02:00
|
|
|
check_copy "${absolute_source}" "sudo cp ${absolute_source} ${real_dest}" "sudo rm ${real_dest}/${filename}"
|
2019-02-24 21:20:30 +01:00
|
|
|
done
|
2019-11-14 15:35:59 +01:00
|
|
|
done
|
|
|
|
|
2023-02-18 22:29:26 +01:00
|
|
|
if [ ! -z "${WM_RESTART}" ]; then
|
|
|
|
echo -e "\n=== Restart graphical environment ==="
|
|
|
|
# Reload i3 configuration
|
2023-02-22 12:38:41 +01:00
|
|
|
i3-msg restart
|
2019-11-14 19:06:44 +01:00
|
|
|
|
2023-02-18 22:29:26 +01:00
|
|
|
# Restart picom due to this bug https://github.com/yshui/picom/issues/166
|
|
|
|
killall picom; picom &>/dev/null &
|
|
|
|
fi
|
2020-01-24 11:57:08 +01:00
|
|
|
|