mirror of
https://github.com/Matir/skel.git
synced 2026-05-25 21:19:09 -07:00
Add support for adding ssh keys.
This commit is contained in:
49
install.sh
49
install.sh
@@ -5,6 +5,7 @@ set errexit
|
|||||||
|
|
||||||
BASEDIR=${BASEDIR:-$HOME/.skel}
|
BASEDIR=${BASEDIR:-$HOME/.skel}
|
||||||
MINIMAL=${MINIMAL:-0}
|
MINIMAL=${MINIMAL:-0}
|
||||||
|
INSTALL_KEYS=${INSTALL_KEYS:-1}
|
||||||
|
|
||||||
if [ ! -d $BASEDIR ] ; then
|
if [ ! -d $BASEDIR ] ; then
|
||||||
echo "Please install to $BASEDIR!" 1>&2
|
echo "Please install to $BASEDIR!" 1>&2
|
||||||
@@ -38,7 +39,7 @@ function prerequisites {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function install_dotfile_dir {
|
function install_dotfile_dir {
|
||||||
SRCDIR="${1}"
|
local SRCDIR="${1}"
|
||||||
find "${SRCDIR}" \( -name .git -o \
|
find "${SRCDIR}" \( -name .git -o \
|
||||||
-path "${SRCDIR}/private_dotfiles" -o \
|
-path "${SRCDIR}/private_dotfiles" -o \
|
||||||
-name install.sh -o \
|
-name install.sh -o \
|
||||||
@@ -46,18 +47,18 @@ function install_dotfile_dir {
|
|||||||
-name .gitignore \) \
|
-name .gitignore \) \
|
||||||
-prune -o -type f -print | \
|
-prune -o -type f -print | \
|
||||||
while read dotfile ; do
|
while read dotfile ; do
|
||||||
TARGET="${HOME}/.${dotfile#${SRCDIR}/}"
|
local TARGET="${HOME}/.${dotfile#${SRCDIR}/}"
|
||||||
mkdir -p `dirname "${TARGET}"`
|
mkdir -p `dirname "${TARGET}"`
|
||||||
ln -s -f "${dotfile}" "${TARGET}"
|
ln -s -f "${dotfile}" "${TARGET}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function install_basic_dir {
|
function install_basic_dir {
|
||||||
SRCDIR="${1}"
|
local SRCDIR="${1}"
|
||||||
DESTDIR="${2}"
|
local DESTDIR="${2}"
|
||||||
find "${SRCDIR}" -type f -print | \
|
find "${SRCDIR}" -type f -print | \
|
||||||
while read file ; do
|
while read file ; do
|
||||||
TARGET="${2}/${file#${SRCDIR}/}"
|
local TARGET="${2}/${file#${SRCDIR}/}"
|
||||||
mkdir -p `dirname "${TARGET}"`
|
mkdir -p `dirname "${TARGET}"`
|
||||||
ln -s -f "${file}" "${TARGET}"
|
ln -s -f "${file}" "${TARGET}"
|
||||||
done
|
done
|
||||||
@@ -70,9 +71,47 @@ function postinstall {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ssh_key_already_installed {
|
||||||
|
# Return 1 if the key isn't already installed, 0 if it is
|
||||||
|
local AK="${HOME}/.ssh/authorized_keys"
|
||||||
|
if [ ! -f $AK ] ; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
local KEYFP=`ssh-keygen -l -f $1 2>/dev/null | awk '{print $2}'`
|
||||||
|
local TMPF=`mktemp`
|
||||||
|
local key
|
||||||
|
while read key ; do
|
||||||
|
echo "$key" > $TMPF
|
||||||
|
local EFP=`ssh-keygen -l -f ${TMPF} 2>/dev/null | awk '{print $2}'`
|
||||||
|
if [ "$EFP" == "$KEYFP" ] ; then
|
||||||
|
rm $TMPF 2>/dev/null
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done < <(grep -v '^#' ${AK})
|
||||||
|
rm $TMPF 2>/dev/null
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function install_keys {
|
||||||
|
# Install SSH keys
|
||||||
|
echo 'Installing SSH keys...' >&2
|
||||||
|
local AK="${HOME}/.ssh/authorized_keys"
|
||||||
|
local key
|
||||||
|
for key in ${BASEDIR}/keys/ssh/* ; do
|
||||||
|
if ssh_key_already_installed "${key}" ; then
|
||||||
|
echo "Key `basename ${key}` already installed..." >&2
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
echo "# `basename ${key}` added from skel on `date +%Y-%m-%d`" >> ${AK}
|
||||||
|
cat ${key} >> ${AK}
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
(( $MINIMAL )) || prerequisites
|
(( $MINIMAL )) || prerequisites
|
||||||
install_dotfile_dir "${BASEDIR}/dotfiles"
|
install_dotfile_dir "${BASEDIR}/dotfiles"
|
||||||
test -d "${BASEDIR}/private_dotfiles" && \
|
test -d "${BASEDIR}/private_dotfiles" && \
|
||||||
install_dotfile_dir "${BASEDIR}/private_dotfiles"
|
install_dotfile_dir "${BASEDIR}/private_dotfiles"
|
||||||
install_basic_dir "${BASEDIR}/bin" "${HOME}/bin"
|
install_basic_dir "${BASEDIR}/bin" "${HOME}/bin"
|
||||||
(( $MINIMAL )) || postinstall
|
(( $MINIMAL )) || postinstall
|
||||||
|
(( $INSTALL_KEYS )) && install_keys
|
||||||
|
|||||||
1
keys/ssh/id_ecdsa_human.pub
Normal file
1
keys/ssh/id_ecdsa_human.pub
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKI+CwNBBoC1G9M2rRR0P0lWAU9uvEZpvDg+CpD+I9NQOLuy80YJMRwIYgTZVTWo8OUqsKSMzYywP6NdMKVdVGg= david@human
|
||||||
1
keys/ssh/id_rsa_human.pub
Normal file
1
keys/ssh/id_rsa_human.pub
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDGOKUiQg5NBq2QqRC030Dmz4SzxcQP9dTHSQyKgrdV7ljSGAlN2GRKm8gu52K4CuOY6dK67FuVKp09fa2BvflnJWkjDsG7DtzFeiCao0eNvW7xL33f880xrU/r+2p+SdeGTuhylJDUejxh+yZ0gqzaLSFfsbXJZjiFnKD0qzl72wHtsbgHL+sTmZ5lCocMS6OoKGQDKkTEhm75TbMX5ZjeBzio9T5dpUR2X3BabxUZ2snyPa42U6rRNNBX+V7c5K1BRjDRTgJ2JmEsR5Al96xNk6gPwa+6F42Zb8lBYdbAt7T04lrv3fnBJ9Mzo+iWdvcKowb715zIGQqHpCuH8gNV david@human
|
||||||
Reference in New Issue
Block a user