This commit is contained in:
Luk Lu
2022-12-10 18:44:12 +08:00
parent 69f77d929b
commit 6751a5bb76
4 changed files with 113 additions and 126 deletions

View File

@@ -48,38 +48,54 @@ fi
if [ -d "$HomePath" ]
then
pushd $HomePath
homescriptlist=".emacs .emacs.lisp .bashrc .bash_profile .gitignore"
echo
echo "=== Copy or link scripts? <l> for link, <anything else> for copy:"
echo "=== Copy or link scripts? <l> to link, <c> to copy, <anything else> to omit:"
read -p ">>> " CopyOrLinkScripts
for homescript in $homescriptlist
do
if [ -e "$homescript" ]
then
mv $homescript $homescript.backup-$(date +%Y%m%d%H%M%S)
fi
if [ "$CopyOrLinkScripts" = 'l' ]
then
if [ "$CopyOrLinkScripts" == 'l' ]
then
for homescript in $homescriptlist
do
if [ -e "$homescript" ] || [ -L "$homescript" ]
then
mv $homescript $homescript.backup-$(date +%Y%m%dT%H%M%S)
fi
echo "--- Linking $SourcePath/$homescript to $HomePath/$homescript ..."
ln -s $SourcePath/$homescript ./
else
done
elif [ "$CopyOrLinkScripts" == 'c' ]
then
for homescript in $homescriptlist
do
if [ -e "$homescript" ]
then
mv $homescript $homescript.backup-$(date +%Y%m%dT%H%M%S)
fi
echo "--- Copying $SourcePath/$homescript to $HomePath/$homescript ..."
cp -r $SourcePath/$homescript ./
fi
done
done
else
echo '--- Home scripts not changed.'
fi
echo
if [ "$TheUser" != 'root' ]
if [ "$TheUser" != 'root' ] && [[ "$(uname)" != "Darwin" ]] # 仅允许 non-root 用户进行远程密钥登录
then
mkdir -p $HomePath/.ssh
chmod 700 $HomePath/.ssh
# 注意,由 root 为新用户创建的配置文件的 owner 是 root而不是新用户导致新用户无法读取该文件而密钥登录失败因此要重设 owner。
chown $TheUser:$TheUser $HomePath/.ssh
if [ "$2" ]
then
# 由 root 指定新用户而创建的配置文件的 owner 是 root而不是新用户导致新用户无法读取该文件而密钥登录失败因此要重设 owner。
chown $TheUser:$TheUser $HomePath/.ssh
fi
if [ -e '$HomePath/.ssh/authorized_keys' ]
then
mv $HomePath/.ssh/authorized_keys $HomePath/.ssh/authorized_keys.backup-$(date +%Y%m%d%H%M%S)
mv $HomePath/.ssh/authorized_keys $HomePath/.ssh/authorized_keys.backup-$(date +%Y%m%dT%H%M%S)
fi
echo "=== Append or link or omit [$HomePath/.ssh/authorized_keys] to config ssh server? <a> for append, <l> for link, <<anything else>> for omit:"
@@ -101,6 +117,7 @@ then
fi
popd
else
echo "!!! Not existing $HomePath, please try again."
fi