This commit is contained in:
Luk Lu
2022-10-22 15:06:11 +08:00
parent 5c0238ac99
commit 20bafeaac5
10 changed files with 249 additions and 211 deletions

View File

@@ -1,40 +1,45 @@
#!/bin/bash
if [ $1 ]
testpath1=/faronear/fon/sysconfig/nixhome
testpath2=~/faronear/fon/sysconfig/nixhome
testpath3=~/faronear/fon/sysconfig.git/nixhome
testpath4=`pwd`/nixhome
if [ "$1" ]
then
SourcePath=$1
elif [ -d $testpath1 ]
then
SourcePath=$testpath1
elif [ -d $testpath2 ]
then
SourcePath=$testpath2
elif [ -d $testpath3 ]
then
SourcePath=$testpath3
elif [ -d $testpath4 ]
then
SourcePath=$testpath4
else
echo "Configure private home settings"
echo "Usage: setup.sh [Config-Source-Path] [User-Home-Path] [--AdotMode]"
echo
echo "=== Enter config <<SourcePath>> or leave <<blank>> for [/Users/luk.lu]/faronear/fon/sysconfig/nixhome):"
echo "=== Enter [target path] or leave [blank] to exit"
read -p ">>> " SourcePath
if [ ! $SourcePath ]
then
echo "Use default source path: [Users/luk.lu]/faronear/fon/sysconfig/nixhome"
echo
if [ -d /faronear/fon/sysconfig/nixhome ]
then
SourcePath=/faronear/fon/sysconfig/nixhome
else
if [ -d /Users/luk.lu/faronear/fon/sysconfig/nixhome ]
then
SourcePath=/Users/luk.lu/faronear/fon/sysconfig/nixhome
else
SourcePath=`pwd`/nixhome
fi
fi
echo ""
if [ ! -d "$SourcePath" ]
then
echo "*** Source path [$SourcePath] not available! Exit now. ***"
exit
fi
fi
if [ $2 ]
if [ "$2" ]
then
HomePath=$2
else
HomePath=~
fi
if [ -d $SourcePath ] && [ -d $HomePath ]
if [ -d $HomePath ]
then
pushd $HomePath
homescriptlist=".emacs .emacs.lisp .bashrc .bash_profile .gitignore"
@@ -44,7 +49,7 @@ then
for homescript in $homescriptlist
do
mv $homescript $homescript.backup-[$(date +%Y%m%d-%H%M%S)]
if [ $CopyOrLinkScripts = 'l' ]
if [ "$CopyOrLinkScripts" = 'l' ]
then
echo "--- Linking $SourcePath/$homescript to $HomePath/$homescript ..."
ln -s $SourcePath/$homescript $HomePath
@@ -54,20 +59,20 @@ then
fi
done
echo
echo "=== Append or link or omit [.ssh/authorized_keys]? <a> for append, <l> for link, <<anything else>> for omit:"
echo "=== Append or link or omit [.ssh/authorized_keys] to config ssh server? <a> for append, <l> for link, <<anything else>> for omit:"
read -p ">>> " CopyOrLinkOrOmitAuthorizedKeys
if [ $CopyOrLinkOrOmitAuthorizedKeys = 'l' ]
if [ "$CopyOrLinkOrOmitAuthorizedKeys" = 'l' ]
then
echo "--- Linking $SourcePath/authorized_keys to $HomePath/.ssh/authorized_keys ..."
mkdir -p $HomePath/.ssh
chmod 700 $HomePath/.ssh
mv $HomePath/.ssh/authorized_keys $HomePath/.ssh/authorized_keys.backup-[$(date +%Y%m%d-%H%M%S)]
ln -s $SourcePath/.ssh/authorized_keys $HomePath/.ssh/authorized_keys
elif [ $CopyOrLinkOrOmitAuthorizedKeys = 'a' ]
elif [ "$CopyOrLinkOrOmitAuthorizedKeys" = 'a' ]
then
mkdir -p $HomePath/.ssh
chmod 700 $HomePath/.ssh
if [ -L $HomePath/.ssh/authorized_keys ]
if [ -L '$HomePath/.ssh/authorized_keys' ]
then
mv $HomePath/.ssh/authorized_keys $HomePath/.ssh/authorized_keys.backup
fi
@@ -77,7 +82,7 @@ then
echo
popd
else
echo "!!! Not existing $SourcePath or $HomePath, please try again."
echo "!!! Not existing $HomePath, please try again."
fi
echo "=== Sourcing $HomePath/.bashrc ..."