Skip to content

Instantly share code, notes, and snippets.

@tumf
Last active July 26, 2020 01:51
Show Gist options
  • Save tumf/e0001343ce9b694501014cb4baf5f005 to your computer and use it in GitHub Desktop.
Save tumf/e0001343ce9b694501014cb4baf5f005 to your computer and use it in GitHub Desktop.
#!/bin/bash
command=$1
ssh_config_dir=~/.ssh
ssh_configs_dir=${ssh_config_dir}/conf.d
ssh_config_file=${ssh_config_dir}/config
ssh_base_config_file=${ssh_configs_dir}/config
function usage()
{
echo "Usage: `basename $0` [update [go]] [add user@ipaddress alias]"
}
function generate()
{
cat ${ssh_base_config_file} ${ssh_configs_dir}/*.conf > ${ssh_config_file}.new
}
function diff_w_new()
{
diff -uN ${ssh_config_file} ${ssh_config_file}.new
}
function update()
{
cp ${ssh_config_file} ${ssh_config_file}.old
cp ${ssh_config_file}.new ${ssh_config_file}
}
if [ -z "$command" ]; then
generate
diff_w_new && exit
while true; do
read -p "Do you wish to overwrite ${ssh_config_file}? [Y] " yn
case $yn in
[Yy]* ) update; break;;
* ) exit;;
esac
done
exit
fi
case $command in
update)
generate
update
;;
*)
usage
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment