This commit is contained in:
陆柯 2022-11-18 14:10:22 +08:00
parent 72f4b05e76
commit c7e9c53601
4 changed files with 19 additions and 15 deletions

View File

@ -1,5 +1,6 @@
echo "Usage: setup.sh [USER]" echo "Usage: setup.sh [USER]"
echo "Example: setup.sh alice" echo "Example: setup.sh alice"
echo
NewUser=$1 NewUser=$1
while [ ! "$NewUser" ] while [ ! "$NewUser" ]
@ -22,7 +23,7 @@ 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? <y> for yes, <anything else> for no" echo "=== Allow the new user [$NewUser] to sudo without password? <y> for yes, <anything else> for no"
read -p ">>> " AllowSudo read -p ">>> " AllowSudo
if [ "$AllowSudo" == "y" ] if [ "$AllowSudo" == "y" ]
then then
@ -35,7 +36,7 @@ else
fi fi
echo echo
echo "=== Configure $NewUser home with standard scripts? <y> for yes, <anything else> for no" echo "=== Configure $NewUser's home with standard scripts? <y> for yes, <anything else> for no"
read -p ">>> " ConfigHome read -p ">>> " ConfigHome
if [ "$ConfigHome" == 'y' ] if [ "$ConfigHome" == 'y' ]
then then

View File

@ -2,7 +2,7 @@
echo "Usage: this.sh [NewUser]" echo "Usage: this.sh [NewUser]"
echo "Example: this.sh alice" echo "Example: this.sh alice"
echo " curl https://git.faronear.org/fon/sysconfig/raw/branch/main/debian-config.sh | bash" echo "curl https://git.faronear.org/fon/sysconfig/raw/branch/main/debian-config.sh | sudo bash"
if [ v$1 != v ] if [ v$1 != v ]
then then
@ -50,7 +50,7 @@ then
fi fi
echo echo
echo "=== Configure /etc/sudoers" echo "=== Configure /etc/sudoers: includedir /etc/sudoers.d"
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
@ -75,15 +75,15 @@ fi
echo echo
echo "=== Configure autostart" echo "=== Configure autostart"
if [ -f /etc/rc.local ] if [ ! -f /etc/rc.local ]
then then
mv /etc/rc.local /etc/rc.local.backup echo '#!/bin/bash' > /etc/rc.local # can't omit, otherwise you can't launch pm2 in autostart.sh. Don't use double quote here, otherwise error.
fi fi
touch /etc/rc.local
chmod +x /etc/rc.local chmod +x /etc/rc.local
echo '#!/bin/bash' > /etc/rc.local # can't omit, otherwise you can't launch pm2 in autostart.sh. Don't use double quote here, otherwise error.
echo 'source /faronear/autostart.sh' >> /etc/rc.local # make sure to sudo pm2 in autostart.sh, otherwise pm2 list can't find it as root. echo 'source /faronear/autostart.sh' >> /etc/rc.local
touch /faronear/autostart.sh touch /faronear/autostart.sh
echo "# make sure to sudo in autostart.sh, otherwise for example pm2 list can't find it as root." >> /faronear/autostart.sh
chmod +x /faronear/autostart.sh 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

View File

@ -39,22 +39,22 @@ then
read -p "Enter root password (YU) >>" PWD_ROOT read -p "Enter root password (YU) >>" PWD_ROOT
expect ~/faronear/fon/sysconfig/expect-ssh.sh $targetUrl adot $PWD_ADOT $PWD_ADOT expect ~/faronear/fon/sysconfig/expect-ssh.sh $targetUrl adot $PWD_ADOT $PWD_ADOT
else else
while [ "$HOST" ] while [ ! "$HOST" ]
do do
read -p "host = " HOST read -p "host = " HOST
done done
while [ "$USER" ] while [ ! "$USER" ]
do do
read -p "user = " USER read -p "user = " USER
done done
while [ "$PWD_USER" ] while [ ! "$PWD_USER" ]
do do
read -p "user password = " PWD_USER read -p "user password = " PWD_USER
done done
while [ "$PWD_SU" ] while [ ! "$PWD_SU" ]
do do
read -p "root password = " ROOT_SU read -p "root password = " ROOT_SU
done done

View File

@ -36,7 +36,7 @@ if [ "$2" ]
then then
HomePath=/home/$2 HomePath=/home/$2
else else
HomePath=~ HomePath=/root
fi fi
if [ -d "$HomePath" ] if [ -d "$HomePath" ]
@ -48,7 +48,10 @@ then
read -p ">>> " CopyOrLinkScripts read -p ">>> " CopyOrLinkScripts
for homescript in $homescriptlist for homescript in $homescriptlist
do do
mv $homescript $homescript.backup-$(date +%Y%m%d%H%M%S) if [ -e "$homescript" ]
then
mv $homescript $homescript.backup-$(date +%Y%m%d%H%M%S)
fi
if [ "$CopyOrLinkScripts" = 'l' ] if [ "$CopyOrLinkScripts" = 'l' ]
then then
echo "--- Linking $SourcePath/$homescript to $HomePath/$homescript ..." echo "--- Linking $SourcePath/$homescript to $HomePath/$homescript ..."