我一直在尝试编写一个 shell 脚本来检测虚拟 linux = Ubuntu 16.0.4 机器上的 composer 和 git,然后在需要时安装它们。+ 如果机器准备好,则克隆所需的存储库。现在这是我第一次尝试编写任何类型的脚本,如果我以某种方式把问题本身搞砸了,我也很抱歉,我现在也在 stackoverflow 上。
任何帮助表示赞赏,在此先感谢。
这是我最初收到的原始任务规范:
- 检查 git 是否安装在服务器上,如果是,则使用代码库克隆 repo
- 检查 composer 是否安装在服务器上,如果是,composer 安装在 laravel 应用程序的根目录下
-最后,php artisan migrate --seed
现在这就是我试图实现这一目标的方式:
#!/bin/bash
echo "The installation process is about the begin..."
if ! which git;
then echo "Git has been located on the destination system. Cloning begins..."
git clone <link to the gitlabe repo>
else echo "There is no Git installed on the system. Git installation commences..."
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git
echo "Cloning begins..."
git clone <link to the gitlabe repo>
fi
if ! which composer;
then
echo "Composer has been located on the destination system."
else
echo "There is no Composer installed on the system. Composer installation commences..."
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install composer
fi
sudo apt-get update
sudo apt-get install curl php5-cli git
curl -sS https://getcomposer.org/installer | sudo php -- --install- dir=/usr/local/bin --filename=composer
composer global require "laravel/installer"
sudo apt-get update
'Now the preferred version in the vagrantfile has to be edited to be 1.8.1 instead of 1.9'
'Generate a ssh key'
ssh-keygen -t rsa -b 4096 -C "< e-mail adress that I used >"
'Start ssh agent eval $'
ssh-agent -s
'Add your SSH private key to the ssh-agent'
ssh-add -K ~/.ssh/id_rsa
php artisan migrate --seed
我收到的错误消息:
sudo sh ./testscript.sh
[sudo] password for linuxtest:
The installation process is about the begin...
: not foundt.sh: 3: ./testscript.sh:
: not foundt.sh: 4: ./testscript.sh:
: not foundt.sh: 5: ./testscript.sh:
./testscript.sh: 72: ./testscript.sh: Syntax error: end of file unexpected (expecting "then")