我正在使用 Ubuntu 并尝试参加 Yocto 课程。我已经能够下载 Yocto 并运行“hello-world”测试脚本来验证 Yocto 安装。
下一步(由讲师指导)是运行名为“start.sh”的脚本。当我尝试以用户身份运行它时,我收到“权限被拒绝”的提示。当我尝试以 root (sudo) 身份运行它时,我收到“useradd: UID 0 不是唯一的”。
权限如下:
-rwxr-xr-x 1 chip chip 2336 Sep 28 20:30 start.sh
我尝试运行 start.sh 的方式是:
$ ./start.sh
或者
$ sudo ./start.sh
我是 Linux 新手,不知道发生了什么或如何恢复。
这是脚本(很长):
#!/usr/bin/env bash
set -e
usage() {
echo "Usage:"
echo "$0 <options>"
echo "Available options:"
echo "-x Use X11 forwarding"
echo "-n Forward /dev/net/tun"
echo "-p Run container in privileged mode"
echo "-e Execute additional instance"
exit 0
}
# rough check to see if we are in correct directory
dirs_to_check=( "./cache/downloads" "./cache/sstate" "./home" )
for d in "${dirs_to_check[@]}"; do
if [[ ! -d ${d} ]]; then
echo "\"${d}\" directory not found"
usage
fi
done
arg_privileged=""
set_arg_privileged() {
echo "WARNING: Running the container with privileged access"
arg_privileged="--privileged"
}
arg_x11_forward=""
set_arg_x11() {
xhost +
arg_x11_forward="--env DISPLAY=unix${DISPLAY} \
--volume ${XAUTH}:/root/.Xauthority \
--volume /tmp/.X11-unix:/tmp/.X11-unix "
}
arg_net_forward=""
tun_dev="/dev/net/tun"
set_arg_net() {
arg_net_forward="--cap-add=NET_ADMIN \
--device ${tun_dev}:/dev/net/tun
--publish 8000:8000"
}
run_additional_instance=false
# parse input arguments
while getopts ":hxnpe" opt; do
case ${opt} in
h )
usage
;;
x )
command -v xhost >/dev/null 2>&1 || { echo >&2 "\"xhost\" is not installed"; exit 1; }
set_arg_x11
;;
n )
[[ -e "${tun_dev}" ]] || { echo >&2 "\"${tun_dev}\" not found, is the \"tun\" kernel module loaded?"; exit 1; }
set_arg_net
;;
p )
set_arg_privileged
;;
e )
run_additional_instance=true
;;
\? )
echo "Invalid Argument: \"${opt}\"" 1>&2
usage
;;
esac
done
empty_password_hash="U6aMy0wojraho"
if [ "${run_additional_instance}" = true ]; then
docker container exec \
-it \
--user yocto \
-w /opt/yocto/workspace \
hubshuffle-yocto \
/bin/bash
else
docker container run \
-it \
--rm \
-v "${PWD}":/opt/yocto \
--name hubshuffle-yocto \
${arg_net_forward} \
${arg_x11_forward} \
${arg_privileged} \
--volume "${PWD}/home":/home/yocto \
hubshuffle/yocto:1.2 \
sudo bash -c "groupadd -g 7777 yocto && useradd --password ${empty_password_hash} --shell /bin/bash -u ${UID} -g 7777 \
yocto && usermod -aG sudo yocto && usermod -aG users yocto && cd /opt/yocto && su yocto"
fi
我可以在这里得到任何帮助吗?
答案1
显然,这个问题是通过在桌面上打开一个 FileManager 窗口来解决的,否则 ./start.sh 无法在终端窗口中运行。我不明白为什么会发生这种情况,我是偶然发现的,如果有人能澄清我将不胜感激。谢谢
答案2
UID 0 是 root 用户。您需要退出 root 并以任何其他用户身份运行该脚本。