Arch Linux:创建另一个用户时 makepkg 出错
Arch Linux: Error in makepkg w/ creating another user
如标题所示,我在仅安装了 xfce4 的虚拟机上使用 Arch Linuxx
我想创建一个安装 yay 的脚本。我知道 makepkg 命令不能在 root 上 运行 所以我决定创建一个脚本。
# Setting up AUR and installing yay in this machine
cd /home
mkdir data
cd /home/data
sudo useradd -p $(openssl passwd -1 liveuser) liveuser
su liveuser
git clone https://aur.archlinux.org/yay.git
chmod 777 yay
cd yay./
makepkg -si
exit
userdel -r liveuser
但我得到的结果是这样的:
[root@archevaris Desktop]# ./APPINSTALLER.sh
[liveuser@archevaris EVARIS]$
它没有正确执行其余代码。我在 /home/data 文件夹中没有看到任何变化。我写的脚本有什么问题吗??
上面的脚本是根据我做的论坛:[https://linux.org/threads/yay-not-installing-in-arch-linux.27414/#post-84056][1]
脚本有问题吗?
瞧瞧。我已经准确地评论了,所以你可以看到。
#!/bin/bash
##################################################################################################################
# This section here is just to understand where the script is and then come back here at the end of the execution.
SOURCE="${BASH_SOURCE[0]}"
# Following cycle to resolve $SOURCE until the file is no longer a symlink
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
# If $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
##################################################################################################################
# Want to go back to the symlink if that is supposed behaviour? Then delete until here and uncomment next line
#DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
##################################################################################################################
#
# HERE IS WHERE YOUR ACTUAL SCRIPT BEGINS:
#
# Defining variables:
TEMPACCOUNT="liveuser"
DESTINATION="/home/$TEMPACCOUNT"
# Adding your temp user and giving it a home folder where it can downloads the source code
useradd -m -p $(openssl passwd -1 $TEMPACCOUNT) $TEMPACCOUNT
# He has to launch the command as non-root user, but he'll need to give admin permission at the end. Adding to sudoers.
echo "$TEMPACCOUNT ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
# Next line is to install packages needed to install yay. I may have forgotten some. I leave the line commented.
#pacman -S git make fakeroot go binutils --noconfirm
# Move to his home folder
cd $DESTINATION
# Create the script in his home folder
echo '#!/bin/bash' > $DESTINATION/yay-setup.sh
echo -e "git clone https://aur.archlinux.org/yay-bin.git\ncd $DESTINATION/yay-bin\nmakepkg --noconfirm -si" >> $DESTINATION/yay-setup.sh
chmod +x $DESTINATION/yay-setup.sh
# Done, now pass the following commands to the SU session we're about to open. << is crucial here, That's what you missed
su $TEMPACCOUNT<<'EOF'
set -e
/bin/bash "yay-setup.sh"
exit
EOF
# Remove the temp user from sudoers file by deleting last line
sed '$d' /etc/sudoers > /etc/sudoers
# The following line is actually pretty useless, userdel -r will wipe this anyway
rm -R yay-*
# And we go back to home sweet home
cd $DIR
# And we delete the temp user
userdel -r $TEMPACCOUNT
如标题所示,我在仅安装了 xfce4 的虚拟机上使用 Arch Linuxx 我想创建一个安装 yay 的脚本。我知道 makepkg 命令不能在 root 上 运行 所以我决定创建一个脚本。
# Setting up AUR and installing yay in this machine
cd /home
mkdir data
cd /home/data
sudo useradd -p $(openssl passwd -1 liveuser) liveuser
su liveuser
git clone https://aur.archlinux.org/yay.git
chmod 777 yay
cd yay./
makepkg -si
exit
userdel -r liveuser
但我得到的结果是这样的:
[root@archevaris Desktop]# ./APPINSTALLER.sh
[liveuser@archevaris EVARIS]$
它没有正确执行其余代码。我在 /home/data 文件夹中没有看到任何变化。我写的脚本有什么问题吗?? 上面的脚本是根据我做的论坛:[https://linux.org/threads/yay-not-installing-in-arch-linux.27414/#post-84056][1]
脚本有问题吗?
瞧瞧。我已经准确地评论了,所以你可以看到。
#!/bin/bash
##################################################################################################################
# This section here is just to understand where the script is and then come back here at the end of the execution.
SOURCE="${BASH_SOURCE[0]}"
# Following cycle to resolve $SOURCE until the file is no longer a symlink
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
# If $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
##################################################################################################################
# Want to go back to the symlink if that is supposed behaviour? Then delete until here and uncomment next line
#DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
##################################################################################################################
#
# HERE IS WHERE YOUR ACTUAL SCRIPT BEGINS:
#
# Defining variables:
TEMPACCOUNT="liveuser"
DESTINATION="/home/$TEMPACCOUNT"
# Adding your temp user and giving it a home folder where it can downloads the source code
useradd -m -p $(openssl passwd -1 $TEMPACCOUNT) $TEMPACCOUNT
# He has to launch the command as non-root user, but he'll need to give admin permission at the end. Adding to sudoers.
echo "$TEMPACCOUNT ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
# Next line is to install packages needed to install yay. I may have forgotten some. I leave the line commented.
#pacman -S git make fakeroot go binutils --noconfirm
# Move to his home folder
cd $DESTINATION
# Create the script in his home folder
echo '#!/bin/bash' > $DESTINATION/yay-setup.sh
echo -e "git clone https://aur.archlinux.org/yay-bin.git\ncd $DESTINATION/yay-bin\nmakepkg --noconfirm -si" >> $DESTINATION/yay-setup.sh
chmod +x $DESTINATION/yay-setup.sh
# Done, now pass the following commands to the SU session we're about to open. << is crucial here, That's what you missed
su $TEMPACCOUNT<<'EOF'
set -e
/bin/bash "yay-setup.sh"
exit
EOF
# Remove the temp user from sudoers file by deleting last line
sed '$d' /etc/sudoers > /etc/sudoers
# The following line is actually pretty useless, userdel -r will wipe this anyway
rm -R yay-*
# And we go back to home sweet home
cd $DIR
# And we delete the temp user
userdel -r $TEMPACCOUNT