This commit is contained in:
陆柯 2022-06-18 11:58:52 +08:00
parent a7e073853c
commit eb2bc570b7
5 changed files with 45 additions and 41 deletions

View File

@ -5,7 +5,8 @@ if [ v$1 != v ]
then then
NewUser=$1 NewUser=$1
else else
read -p "Enter new user name (leave blank for default 'adot')>> " NewUser echo "=== Enter new <<UserName>> (leave blank for default 'adot'):"
read -p ">>> " NewUser
if [ ! $NewUser ] if [ ! $NewUser ]
then then
echo Use default new user: adot echo Use default new user: adot
@ -13,7 +14,7 @@ else
fi fi
fi fi
echo "<<< Add a new user $NewUser" echo "=== Add a new user $NewUser"
useradd $NewUser useradd $NewUser
# usermod -a -G sudo $NewUser # Add to sudo group # usermod -a -G sudo $NewUser # Add to sudo group
passwd $NewUser passwd $NewUser
@ -27,19 +28,19 @@ sed -i "s|/home/$NewUser:/bin/sh$|/home/$NewUser:/bin/bash|g" /etc/passwd
# Debian 9 default to empty # Debian 9 default to empty
sed -i "s|/home/$NewUser:$|/home/$NewUser:/bin/bash|g" /etc/passwd sed -i "s|/home/$NewUser:$|/home/$NewUser:/bin/bash|g" /etc/passwd
echo "<<< Allow the new user $NewUser to sudo without password" echo "=== Allow the new user $NewUser to sudo without password"
#usermod -a -G sudo $NewUser # Add to sudo group # Option 1: add user to %sudo group #usermod -a -G sudo $NewUser # Add to sudo group # Option 1: add user to %sudo group
echo "$NewUser ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers.d/${NewUser//./-} # Option 2: add a user file into /etc/sudoers.d/ echo "$NewUser ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers.d/${NewUser//./-} # Option 2: add a user file into /etc/sudoers.d/
chmod a-w /etc/sudoers.d/${NewUser//./-} chmod a-w /etc/sudoers.d/${NewUser//./-}
echo echo
# 注意,在这里为新用户创建的配置文件,主人是 root而不是新用户 # 注意,由 root 为新用户创建的配置文件的 owner 是 root而不是新用户
if [ $NewUser = 'adot' ] if [ $NewUser = 'adot' ]
then then
source /faronear/fon/sysconfig/home-config.sh /faronear/fon/sysconfig/nixhome /home/$NewUser source /faronear/fon/sysconfig/home-config.sh /faronear/fon/sysconfig/nixhome /home/$NewUser
else else
echo "<<< Configure $NewUser home with standard scripts? (注意,由 root 为新用户创建的配置文件的 owner 是 root而不是新用户)" echo "=== Configure $NewUser home with standard scripts? <y> for yes, <<anything else>> for no"
read -p "y for yes, anything else for no >> " YesOrNo read -p ">>> " YesOrNo
if [ $YesOrNo = 'y' ] if [ $YesOrNo = 'y' ]
then then
source /faronear/fon/sysconfig/home-config.sh /faronear/fon/sysconfig/nixhome /home/$NewUser source /faronear/fon/sysconfig/home-config.sh /faronear/fon/sysconfig/nixhome /home/$NewUser

View File

@ -10,26 +10,26 @@ else
NewUser=adot NewUser=adot
fi fi
echo "<<< Installing basic tools" echo "=== Installing basic tools"
apt update apt update
apt install -y emacs git curl screen sudo automake rsync apt install -y emacs git curl screen sudo automake rsync
echo echo
echo "<<< Making dir /faronear" echo "=== Making dir /faronear"
if [ ! -d "/faronear" ] if [ ! -d "/faronear" ]
then then
mkdir /faronear mkdir /faronear
fi fi
echo echo
echo "<<< Making dir /faronear/fon" echo "=== Making dir /faronear/fon"
if [ ! -d "/faronear/fon" ] if [ ! -d "/faronear/fon" ]
then then
mkdir /faronear/fon mkdir /faronear/fon
fi fi
echo echo
echo "<<< Git cloning to /faronear/fon/sysconfig" echo "=== Git cloning to /faronear/fon/sysconfig"
git config --global credential.helper cache git config --global credential.helper cache
if [ ! -d "/faronear/fon/sysconfig" ] if [ ! -d "/faronear/fon/sysconfig" ]
then then
@ -37,33 +37,29 @@ then
fi fi
echo echo
echo "<<< Configure root home" echo "=== Configure root home"
source /faronear/fon/sysconfig/home-config.sh /faronear/fon/sysconfig/nixhome source /faronear/fon/sysconfig/home-config.sh /faronear/fon/sysconfig/nixhome
echo echo
echo "<<< Change root password" echo "=== Change root password"
passwd passwd
echo echo
echo "<<< Configure /etc/sudoers" echo "=== Configure /etc/sudoers"
chmod o+w /etc/sudoers chmod o+w /etc/sudoers
#sed -i "s|%sudo\s\+ALL=(ALL:ALL)\sALL|%sudo\tALL=(ALL:ALL) NOPASSWD:ALL|g" /etc/sudoers # allow all users in %sudo group to sudo without password #sed -i "s|%sudo\s\+ALL=(ALL:ALL)\sALL|%sudo\tALL=(ALL:ALL) NOPASSWD:ALL|g" /etc/sudoers # allow all users in %sudo group to sudo without password
sed -i "s|#includedir /etc/sudoers.d|includedir /etc/sudoers.d|g" /etc/sudoers # allow users in /etc/sudoers.d/ folder to sudo sed -i "s|#includedir /etc/sudoers.d|includedir /etc/sudoers.d|g" /etc/sudoers # allow users in /etc/sudoers.d/ folder to sudo
chmod o-w /etc/sudoers chmod o-w /etc/sudoers
echo echo
echo "<<< Add a new user $NewUser" echo "=== Disallow root login: #PermitRootLogin yes"
source /faronear/fon/sysconfig/debian-add-user.sh $NewUser
echo
echo "<<< Disallow root login: #PermitRootLogin yes"
# emacs /etc/ssh/sshd_config # emacs /etc/ssh/sshd_config
sed -i "s|^PermitRootLogin yes|#PermitRootLogin yes|g" /etc/ssh/sshd_config sed -i "s|^PermitRootLogin yes|#PermitRootLogin yes|g" /etc/ssh/sshd_config
service sshd restart service sshd restart
echo echo
echo "<<< Set hostname or leave blank for no change" echo "=== Set <<hostname>> or leave blank for no change"
read -p ">> " NewHostname read -p ">>> " NewHostname
if [ $NewHostname ] if [ $NewHostname ]
then then
hostnamectl set-hostname $NewHostname hostnamectl set-hostname $NewHostname
@ -73,19 +69,7 @@ else
fi fi
echo echo
echo "<<< Enable xfce autologin [/etc/lightdm/lightdm.conf] as ($NewUser for autologin or anything else for no change):" echo "=== Configure autostart"
read -p ">> " XfceAutologinUsername
if [ $XfceAutologinUsername = $NewUser ]
then
sed -i "s/^.*autologin-user=.*$/autologin-user=$NewUser/g" /etc/lightdm/lightdm.conf
sed -i "s/^.*autologin-user-timeout=.*$/autologin-user-timeout=0/g" /etc/lightdm/lightdm.conf
echo "Successfully configured autologin as $NewUser"
else
echo 'Nothing changed >>>'
fi
echo
echo "<<< Configure autostart"
if [ -f /etc/rc.local ] if [ -f /etc/rc.local ]
then then
mv /etc/rc.local /etc/rc.local.backup mv /etc/rc.local /etc/rc.local.backup
@ -99,9 +83,25 @@ chmod +x /faronear/autostart.sh
echo 'Autostart is set to /faronear/autostart.sh. Run "systemctl start/stop/status rc-local" to manage it.' echo 'Autostart is set to /faronear/autostart.sh. Run "systemctl start/stop/status rc-local" to manage it.'
echo echo
echo "<<< Configure locales: install all-locales and set default to none." echo "=== Configure locales: install all-locales and set default to none."
dpkg-reconfigure locales dpkg-reconfigure locales
echo echo
echo "<<< Debian System Setup Completed >>>" echo "=== Add a new user $NewUser"
source /faronear/fon/sysconfig/debian-add-user.sh $NewUser
echo
echo "=== Enable xfce autologin [/etc/lightdm/lightdm.conf] as <$NewUser> for autologin or <<anything else>> for no change):"
read -p ">>> " XfceAutologinUsername
if [ $XfceAutologinUsername = $NewUser ]
then
sed -i "s/^.*autologin-user=.*$/autologin-user=$NewUser/g" /etc/lightdm/lightdm.conf
sed -i "s/^.*autologin-user-timeout=.*$/autologin-user-timeout=0/g" /etc/lightdm/lightdm.conf
echo "Successfully configured autologin as $NewUser"
else
echo 'Nothing changed >>>'
fi
echo
echo "=== Debian System Setup Completed >>>"

View File

@ -1,6 +1,7 @@
# https://docs.docker.com/engine/install/debian/ # https://docs.docker.com/engine/install/debian/
read -p "Choose docker source (a: 阿里云, z: 中科大, leave blank for default) >> " DOCKER_SOURCE echo "=== Choose docker source (a: 阿里云, z: 中科大, leave blank for default):"
read -p ">>> " DOCKER_SOURCE
if [ $DOCKER_SOURCE = 'a' ] if [ $DOCKER_SOURCE = 'a' ]
then then
GPG_URL=http://mirrors.aliyun.com/docker-ce/linux/debian/gpg GPG_URL=http://mirrors.aliyun.com/docker-ce/linux/debian/gpg
@ -35,7 +36,8 @@ echo Install Docker-Compose ...
sudo curl -L $COMPOSE_URL/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose sudo curl -L $COMPOSE_URL/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose
read -p "配置中国加速镜像源 /etc/docker/daemon.json (d: Docker中国, t: 腾讯云, z: 中科大, leave blank for no mirror) >> " DOCKER_MIRROR echo "=== 配置中国加速镜像源 /etc/docker/daemon.json (d: Docker中国, t: 腾讯云, z: 中科大, leave blank for no mirror):"
read -p ">>> " DOCKER_MIRROR
if [ $DOCKER_MIRROR = 'd' ] if [ $DOCKER_MIRROR = 'd' ]
then then
DOCKER_MIRROR=https://registry.docker-cn.com DOCKER_MIRROR=https://registry.docker-cn.com

View File

@ -7,7 +7,7 @@ else
echo "Configure private home settings" echo "Configure private home settings"
echo "Usage: setup.sh [Config-Source-Path] [User-Home-Path] [--AdotMode]" echo "Usage: setup.sh [Config-Source-Path] [User-Home-Path] [--AdotMode]"
echo echo
echo "=== Enter config source path (leave blank for [/Users/luk.lu]/faronear/fon/sysconfig/nixhome):" echo "=== Enter config <<SourcePath>> (leave blank for [/Users/luk.lu]/faronear/fon/sysconfig/nixhome):"
read -p ">>> " SourcePath read -p ">>> " SourcePath
if [ ! $SourcePath ] if [ ! $SourcePath ]
then then
@ -39,7 +39,7 @@ then
pushd $HomePath pushd $HomePath
homescriptlist=".emacs .emacs.lisp .bashrc .bash_profile .gitignore" homescriptlist=".emacs .emacs.lisp .bashrc .bash_profile .gitignore"
echo echo
echo "=== Copy or link scripts? l for link, anything else for copy:" echo "=== Copy or link scripts? <l> for link, <<anything else>> for copy:"
read -p ">>> " CopyOrLinkScripts read -p ">>> " CopyOrLinkScripts
for homescript in $homescriptlist for homescript in $homescriptlist
do do
@ -55,7 +55,7 @@ then
fi fi
done done
echo 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]? <a> for append, <l> for link, <<anything else>> for omit:"
read -p ">>> " CopyOrLinkOrOmitAuthorizedKeys read -p ">>> " CopyOrLinkOrOmitAuthorizedKeys
if [ $CopyOrLinkOrOmitAuthorizedKeys = 'l' ] if [ $CopyOrLinkOrOmitAuthorizedKeys = 'l' ]
then then

View File

@ -6,7 +6,8 @@ if [ $1 ]
then then
REMOTEHOST=$1 REMOTEHOST=$1
else else
read -p "Enter user@remotehost >> " REMOTEHOST echo "=== Enter << user@remotehost >> to connect to:"
read -p ">>> " REMOTEHOST
fi fi
scp ~/.ssh/id_rsa.pub $REMOTEHOST:~/tmp.pub scp ~/.ssh/id_rsa.pub $REMOTEHOST:~/tmp.pub