Arch Linux: ошибка в makepkg при создании другого пользователя - PullRequest
0 голосов
/ 05 февраля 2020

Как видно из названия, я использую Arch Linuxx на виртуальной коробке с только что установленным xfce4. Я хочу создать скрипт, который устанавливает 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]

Есть проблемы со сценарием?

1 Ответ

0 голосов
/ 13 марта 2020

Вуаля. Я прокомментировал это точно, чтобы вы могли видеть.

#!/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
...