shell脚本窗口的流浪路径

时间:2016-02-01 16:25:25

标签: vagrant

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位于同一文件夹中。流浪壳的相关输出:

==> 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.

我的mashine上不存在给定的记录路径 没有shell脚本,vagrant工作正常,有什么想法吗?

[编辑]:我可以访问机器,但我无法在机器内执行脚本:

 /bin/sh: 0: Illegal option -

Thx,martin

2 个答案:

答案 0 :(得分:0)

你可以试试下面的回购

# 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 -

答案 1 :(得分:0)

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