2019-01-10 10:45:52 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
LAPTOP="laptop"
|
|
|
|
DESKTOP="desk"
|
2019-02-24 21:20:30 +01:00
|
|
|
DEST_FILENAME="dest"
|
2019-01-10 10:45:52 +01:00
|
|
|
|
|
|
|
function usage() {
|
2019-02-24 21:20:30 +01:00
|
|
|
echo "$0: creates symlink for divergent config between laptop and desktop (e.g. battery management...) and copy configuration to external locations"
|
2019-01-10 10:45:52 +01:00
|
|
|
echo "usage: $0 [${LAPTOP}|${DESKTOP}]"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2019-02-24 21:20:30 +01:00
|
|
|
# Use XDG_CONFIG_HOME if defined, default otherwise
|
|
|
|
CONFIG=${XDG_CONFIG_HOME:-$HOME/.config}
|
|
|
|
|
|
|
|
# Check that there is one matching argument
|
2019-01-10 10:45:52 +01:00
|
|
|
if [ -z "{$1}" ] || [ "$#" -ne 1 ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${1}" != "${LAPTOP}" ] && [ "${1}" != "${DESKTOP}" ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2019-02-24 21:20:30 +01:00
|
|
|
echo "=== Create symlink to *.${1} 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 "*.${1}"`; do
|
|
|
|
echo "Create symlink to ${f}..."
|
2019-01-10 10:45:52 +01:00
|
|
|
ln -sf ${f} ${f%.*}
|
2019-01-26 19:24:25 +01:00
|
|
|
done
|
|
|
|
|
2019-02-24 21:20:30 +01:00
|
|
|
# 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 "*.${1}"`; do
|
|
|
|
echo "Create symlink to ${f}..."
|
2019-01-26 19:24:25 +01:00
|
|
|
ln -sf ${f} ${f%.*}
|
2019-02-24 21:20:30 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
echo -e "\n=== Copy configuration which resides in outer directory ==="
|
|
|
|
# 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
|
|
|
|
for config_file in `find ${DIR} -maxdepth 1 -mindepth 1 -not \( -name "*.${LAPTOP}" -o -name "*.${DESKTOP}" -o -name "${DEST_FILENAME}" \)`; do
|
|
|
|
# Now copy to destination
|
|
|
|
echo "Copying ${config_file} to ${DEST}..."
|
|
|
|
sudo cp ${config_file} ${DEST}
|
|
|
|
done
|
2019-01-10 10:45:52 +01:00
|
|
|
done
|