首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Arch Linux: makepkg w/创建另一个用户中的错误

Arch Linux: makepkg w/创建另一个用户中的错误
EN

Stack Overflow用户
提问于 2020-02-05 14:03:28
回答 1查看 509关注 0票数 0

正如标题所示,我在一个只安装了xfce4的virtualbox上使用Arch,我想创建一个安装yay的脚本。我知道makepkg命令不能在root上运行,所以我决定创建一个脚本。

代码语言:javascript
复制
# 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

但我得到的结果是:

代码语言:javascript
复制
[root@archevaris Desktop]# ./APPINSTALLER.sh
[liveuser@archevaris EVARIS]$ 

它没有正确地执行其余的代码。我看不到/home/data文件夹中的任何更改。我写的剧本有什么问题吗??上面的脚本是基于我创建的论坛:[https://linux.org/threads/yay-not-installing-in-arch-linux.27414/#post-84056][1]

剧本有什么问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-13 16:54:49

哇哦。我准确地评论了它,这样你就可以看到。

代码语言:javascript
复制
#!/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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60077542

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档