【问题标题】:vagrant path to shell script windowsshell脚本窗口的流浪路径
【发布时间】:2016-02-03 19:56:05
【问题描述】:

Windows 上的 shell 脚本的路径存在问题。 在 linux 上,Vagrantfile 工作正常。

# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.provider :virtualbox do |vb|
    vb.name = "studstat_dev"
  end
  config.vm.network "forwarded_port", guest: 8000, host: 8888
  config.vm.network "forwarded_port", guest: 5432, host: 15432
  # Provisioning mit Shell-Script
  config.vm.provision "shell", path: "studstat.sh"
end

studstat.sh

#!/bin/sh -e
# Edit the following to change the name of the database user that will be created:
APP_DB_USER=vagrant
APP_DB_PASS=vagrant
# Edit the following to change the name of the database that is created (defaults to the user name)
APP_DB_NAME=studstat
# Edit the following to change the version of PostgreSQL that is installed
PG_VERSION=9.4
export DEBIAN_FRONTEND=noninteractive
PG_REPO_APT_SOURCE=/etc/apt/sources.list.d/pgdg.list
if [ ! -f "$PG_REPO_APT_SOURCE" ]
then
# Add PG apt repo:
echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" > "$PG_REPO_APT_SOURCE"
# Add PGDG repo key:
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
fi
# Update package list and upgrade all packagesini
apt-get update
apt-get -y upgrade
# install packages for postgres + python3
apt-get -y install "postgresql-$PG_VERSION" "postgresql-contrib-$PG_VERSION"
apt-get -y install vim git python3-setuptools python3-dev libpq-dev python3-pip
# install virtualenv via pip3, not yet in ubuntu repository (20.11.15)
pip3 install virtualenv
PG_CONF="/etc/postgresql/$PG_VERSION/main/postgresql.conf"
PG_HBA="/etc/postgresql/$PG_VERSION/main/pg_hba.conf"
PG_DIR="/var/lib/postgresql/$PG_VERSION/main"
# Edit postgresql.conf to change listen address to '*':
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" "$PG_CONF"
# Append to pg_hba.conf to add password auth:
echo "host    all             all             all                     md5" >> "$PG_HBA"
# Explicitly set default client_encoding
echo "client_encoding = utf8" >> "$PG_CONF"
# generate locales
locale-gen de_DE.UTF-8
update-locale LANG=de_DE.UTF-8
# Restart so that all new config is loaded:
service postgresql restart
cat << EOF | su - postgres -c psql
-- Create the database user:
CREATE USER $APP_DB_USER WITH PASSWORD '$APP_DB_PASS';
-- Create the database:
CREATE DATABASE $APP_DB_NAME WITH OWNER=$APP_DB_USER
                              LC_COLLATE='de_DE.UTF-8'
                              LC_CTYPE='de_DE.UTF-8'
                              ENCODING='UTF8'
                              TEMPLATE=template0;
EOF

该脚本与 Vagrantfile 位于同一文件夹中。 vagrant shell 的相关输出:

==> default: Running provisioner: shell...
    default: Running: C:Users/hema0004/AppData/Local/Temp/vagrant-shell20160201-2732-1v2m7qa.sh
==> default: gpg: no valid OpenPGP data found.
The SSH command responded with a non-zero exit status. Vagrant assumes, that this means the command failed. The output for this command should be in the log above. Please read the output to determine what went wrong.

我的机器上不存在给定的日志路径。
没有 shell 脚本,vagrant 可以正常工作,有什么想法吗?

[编辑]:我可以访问机器但我不能从机器内执行脚本:

 /bin/sh: 0: Illegal option -

谢谢,马丁

【问题讨论】:

  • 当windows为主机时,你能确认盒子可以上网吗?如果你在没有脚本的情况下 ssh 并在之后运行脚本,它会起作用吗?
  • ok 我可以访问机器但是我不能运行脚本:/bin/sh: 0: Illegal option -

标签: vagrant


【解决方案1】:

问题是由于缺少环境变量,盒子无法访问互联网。这些变量应该是通过 vagrant-proxyconf 插件提供的。潜在的问题是,提供代理配置的 $VAGRANT_HOME 路径是错误的。

【讨论】:

    【解决方案2】:

    你可以从以下 repo 中尝试吗

    # Add PGDG repo key:
    apt-get install -y ca-certificates wget
    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
    

    【讨论】:

    • 盒子在windows主机时脚本没有运行:/bin/sh: 0: Illegal option -
    • 奇怪...你可以尝试将#!/bin/sh -e 更改为#!/bin/sh#!/bin/bash
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 2012-08-07
    • 1970-01-01
    • 1970-01-01
    • 2011-07-15
    • 2013-02-09
    相关资源
    最近更新 更多