-
-
Save penguin2716/7f6076a4da08b41cc641 to your computer and use it in GitHub Desktop.
~/.ssh/conf.d の中の設定ファイルを結合してからsshを叩くシェルスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# ssh (concatenating split config file) | |
# | |
# Copyright (c) 2014 Takuma Nakajima | |
# | |
# This software is released under the MIT License. | |
# http://opensource.org/licenses/mit-license.php | |
# | |
CONFIG_ON_MEMORY=/dev/shm/$USER-ssh-config | |
CONFIG_PATH=$HOME/.ssh/config | |
CONFIG_DIR=$HOME/.ssh/conf.d | |
which ssh >/dev/null 2>&1 | |
# check if ssh exists | |
if [ $? -ne 0 ]; then | |
echo "ssh does not exists or is not in \$PATH." | |
exit 1 | |
fi | |
# create ~/.ssh/config as a symlink to /dev/shm/ssh-config | |
if [ ! -e $CONFIG_PATH ]; then | |
echo 'creating symlink' | |
ln -s $CONFIG_ON_MEMORY $CONFIG_PATH | |
fi | |
# exit if ~/.ssh/config is not a symlink | |
if [ ! -L $CONFIG_PATH ]; then | |
echo "ERROR: $CONFIG_PATH is not a symbolic link." | |
exit 1 | |
fi | |
# delete and regenerate config on memory | |
rm -rf $CONFIG_ON_MEMORY | |
touch $CONFIG_ON_MEMORY | |
chmod 600 $CONFIG_ON_MEMORY | |
for config in `find $CONFIG_DIR -type f`; do | |
cat $config >> $CONFIG_ON_MEMORY | |
echo >> $CONFIG_ON_MEMORY | |
echo >> $CONFIG_ON_MEMORY | |
done | |
# generate ssh command | |
SSH_COMMAND="/usr/bin/ssh -F $CONFIG_ON_MEMORY" | |
while [ -n "$1" ]; do | |
SSH_COMMAND="$SSH_COMMAND \"$1\"" | |
shift | |
done | |
# spawn the command | |
eval $SSH_COMMAND |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment