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}"
|
|
|
|
|
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
|
|
|
|
# $1 : path of file
|
|
|
|
# $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
|
2019-11-18 23:36:59 +01:00
|
|
|
echo "$changed_files" | grep --quiet "${1#$HOME/}"
|
2019-11-14 15:35:59 +01:00
|
|
|
if [ $? == "0" ]; then
|
2019-11-18 23:36:59 +01:00
|
|
|
echo "$changed_files" | cut -f 1 | grep --quiet "D"
|
2019-11-14 15:35:59 +01:00
|
|
|
if [ $? == "0" ]; then
|
|
|
|
echo "* $1 has been removed"
|
2019-11-18 23:36:59 +01:00
|
|
|
echo -e "\t* Running \"$3\"" && eval "$3"
|
2019-11-14 15:35:59 +01:00
|
|
|
else
|
|
|
|
echo "* Changes detected in $1"
|
2019-11-18 23:36:59 +01:00
|
|
|
echo -e "* 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
|
|
|
|
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
|
|
|
|
echo "Found ${f}, add to regular config file"
|
|
|
|
cat "${f}" >> ${CONFIG}/${m}/${FINAL_CONFIG}
|
|
|
|
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
|
|
|
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
|
|
|
|
2023-02-18 22:29:26 +01:00
|
|
|
for m in ${MERGE_DIRS}; do
|
|
|
|
merge_config $m ${ENV}
|
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..."
|
|
|
|
chsh -s $(which zsh)
|
|
|
|
# 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-02-18 22:29:26 +01:00
|
|
|
echo -e "* Enabling NetworkManager..."
|
|
|
|
sudo systemctl enable --now NetworkManager
|
2023-02-19 00:49:30 +01:00
|
|
|
# So that "Open in Terminal" works in Nemo
|
|
|
|
gsettings set org.cinnamon.desktop.default-applications.terminal exec i3-sensible-terminal
|
2023-02-19 11:01:41 +01:00
|
|
|
# For screenshots
|
|
|
|
pip install pychee
|
2023-02-20 14:03:38 +01:00
|
|
|
# Additionnal plugins for ZSH
|
|
|
|
sudo git clone https://github.com/zsh-users/zsh-syntax-highlighting.git /usr/share/oh-my-zsh/plugins/zsh-syntax-highlighting
|
|
|
|
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-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-04-11 11:50:02 +02:00
|
|
|
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}" \)`; do
|
2019-02-24 21:20:30 +01:00
|
|
|
# Now copy to destination
|
2020-12-13 16:45:49 +01:00
|
|
|
sudo mkdir -p ${DEST}
|
2023-04-11 11:50:02 +02:00
|
|
|
# ##* strips the base path, so we manipulate absolute paths by concatening with $DEST
|
2019-11-18 23:36:59 +01:00
|
|
|
check_copy "${config_file}" "sudo cp ${config_file} ${DEST}" "sudo rm ${DEST}/${config_file##*/}"
|
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
|
|
|
|