2016-08-19 18:02:49 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2016-12-31 03:10:34 +01:00
|
|
|
pc_settings_path="${HOME}/pc_settings"
|
2017-06-23 19:01:16 +02:00
|
|
|
configs_dir="${pc_settings_path}/configs"
|
|
|
|
shared_configs="${configs_dir}/shared"
|
2016-11-10 17:47:44 +01:00
|
|
|
|
2017-06-23 19:01:16 +02:00
|
|
|
if [[ $(uname) == 'Darwin' ]]; then
|
|
|
|
os_specific_configs="${configs_dir}/os_x"
|
|
|
|
elif [[ $(uname) == 'Linux' ]]; then
|
|
|
|
os_specific_configs="${configs_dir}/linux"
|
|
|
|
fi
|
2016-11-10 17:47:44 +01:00
|
|
|
|
|
|
|
|
2017-06-23 19:01:16 +02:00
|
|
|
function symlink_configs () {
|
|
|
|
configs_dir=$1
|
2016-11-10 17:47:44 +01:00
|
|
|
|
2017-06-23 19:01:16 +02:00
|
|
|
for cf in $(find $configs_dir -type f -name ".*"); do
|
|
|
|
filename=$(grep -o "[^\/]+$" <<<$cf)
|
|
|
|
echo "$filename: "
|
2016-11-10 20:49:13 +01:00
|
|
|
|
2017-06-23 19:01:16 +02:00
|
|
|
if [ -f "${HOME}/${filename}" ] && [ ! -L "${HOME}/${filename}" ]; then
|
|
|
|
echo -n "Backing up ${filename} ... " && \
|
|
|
|
mv "${HOME}/${filename}" "${HOME}/${filename}.bak" && \
|
|
|
|
echo "Done."
|
|
|
|
fi
|
2016-11-10 17:47:44 +01:00
|
|
|
|
2017-06-23 19:01:16 +02:00
|
|
|
if [ -L "${HOME}/${filename}" ]; then
|
|
|
|
if [ $(readlink "${HOME}/${filename}") = $cf ]; then
|
|
|
|
echo "Already properly symlinked to ${configs_dir}."
|
|
|
|
else
|
|
|
|
echo "Already symlinked but NOT to the proper location. Aborting..."
|
|
|
|
fi
|
2016-11-10 17:47:44 +01:00
|
|
|
else
|
2017-06-23 19:01:16 +02:00
|
|
|
echo -n "Symlinking to ${filename} ... " && \
|
|
|
|
ln -s $cf "${HOME}/${filename}" && \
|
|
|
|
echo "Done."
|
2016-11-10 17:47:44 +01:00
|
|
|
fi
|
2017-06-23 19:01:16 +02:00
|
|
|
echo ""
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# handle shared configs
|
|
|
|
symlink_configs $shared_configs
|
|
|
|
|
|
|
|
# handle os-specific configs
|
|
|
|
symlink_configs $os_specific_configs
|