vagrant up命令错误'文件/vagrant/provision/prep_server.sh'意外结束

时间:2016-11-28 18:00:28

标签: vagrant debian windows-10 virtual-machine virtualbox

我尝试vagrant up。 我在主机上的环境

  • Microsoft Windows 10
  • Virtual Box 5.1.10
  • Vagrant 1.8.6

Vagrant获得了框bento/debian-8.6,设置了端口,安装了共享文件夹,之后返回错误

==> myvag: /vagrant/provision/prep_server.sh: line 2: $'\r': command not found
==> myvag: /vagrant/provision/prep_server.sh: line 4: $'\r': command not found
==> myvag: /vagrant/provision/prep_server.sh: line 10: $'\r': command not found
==> myvag: Updating Aptitude
==> myvag: /vagrant/provision/prep_server.sh: line 14: $'\r': command not found
==> myvag: Removing exim4
==> myvag: /vagrant/provision/prep_server.sh: line 20: $'\r': command not found
==> myvag: Performing an safe-upgrade
==> myvag: Reading changelogs...
==> myvag: Done with safe-upgrade
==> myvag: /vagrant/provision/prep_server.sh: line 25: $'\r': command not found
==> myvag: Adding dotdeb dependencies to apt sources if not there.
==> myvag: /vagrant/provision/prep_server.sh: line 27: $'\r': command not found
==> myvag: /vagrant/provision/prep_server.sh: line 30: $'\r': command not found
==> myvag: Adding dotdeb GPG Key
==> myvag: /vagrant/provision/prep_server.sh: line 42: syntax error: unexpected end of file

此文件中的内容位于

之下
#!/bin/bash

export DEBIAN_FRONTEND=noninteractive

############ Ultimately, this is a HACK: ###############
## Because of libssl and heartbleed, there are some
## debian propts that come up and destroy screw up
## Our provisioning scripts in salt and make the output
## really funny.

# Update our packages data
echo "Updating Aptitude"
sudo aptitude update > /dev/null

# exim4 is the stupid package causing the prompt to occur.
# It was just easier to remove it than automate the lib's
# Upgrade screen.
echo "Removing exim4"
sudo aptitude purge -y -q -f exim4 > /dev/null

echo "Performing an safe-upgrade"
# Do an upgrade of the existing stuff
sudo -E bash -c 'aptitude safe-upgrade -y -f > /dev/null'
echo "Done with safe-upgrade"

echo "Adding dotdeb dependencies to apt sources if not there."
grep -q -F 'packages.dotdeb.org' /etc/apt/sources.list ||
echo "deb http://packages.dotdeb.org jessie all
deb-src http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list

echo "Adding dotdeb GPG Key"
if ! apt-key list | grep -q -F  'dotdeb'; then
    wget https://www.dotdeb.org/dotdeb.gpg
    apt-key add dotdeb.gpg
    rm dotdeb.gpg
else
    echo "Dotdeb GPG Key present"
fi

echo "Updating apt-get"
apt-get update

据我所知,它可以与结尾相关\ r \ n,但我该如何解决呢。

与此同时,我的同事对vagrant up没有麻烦,但他在主机上使用Ubuntu。

1 个答案:

答案 0 :(得分:1)

您的文件具有由windows编码的回车符,这在linux世界中是不同的。

您的解决方案:

  1. 通过dos2unix脚本(http://dos2unix.sourceforge.net)运行您的文件

  2. Windows上的大多数高级编辑器(UltraEdit,Notepad ++)允许您专门为linux保存文件的格式(例如UltraEdit具有File / convert with options to convert for linux)