windows - 如何运行/调整 .sh 文件以适应 Windows 环境
问题描述
我有一个项目的以下配置文件。
它本身不能在 Windows 上运行。我安装了 powershell、linux 子系统、docker running 等。
我应该按照哪些步骤使项目在 Windows 上运行?我有点迷路了我可以在没有 cygwin 的情况下运行它吗?
#!/usr/bin/env bash
CYAN='\033[0;36m'
BLUE='\033[0;34m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
yell() { echo "$0: $*" >&2; }
die() { yell "$*"; exit 111; }
try() { "$@" || die "cannot $*"; }
# Path to your hosts file
hostsFile="/etc/hosts"
# Default IP address for host
ip="127.0.0.1"
hostnames="api.foodmeup.local"
removeHost() {
if [ -n "$(grep -p "[[:space:]]$1" /etc/hosts)" ]; then
echo "$1 found in $hostsFile. Removing now...";
try sudo sed -ie "/[[:space:]]$1/d" "$hostsFile";
else
yell "$1 was not found in $hostsFile";
fi
}
addHost() {
if [ -n "$(grep -p "[[:space:]]$1" /etc/hosts)" ]; then
yell "$1, already exists: $(grep $1 $hostsFile)";
else
echo "Adding $1 to $hostsFile...";
try printf "%s\t%s\n" "$ip" "$1" | sudo tee -a "$hostsFile" > /dev/null;
if [ -n "$(grep $1 /etc/hosts)" ]; then
echo "$1 was added succesfully:";
echo "$(grep $1 /etc/hosts)";
else
die "Failed to add $1";
fi
fi
}
addLinuxSSL() {
sudo mkdir -p /usr/local/share/ca-certificates/foodmeup.local
sudo cp ./.docker/nginx/ssl/foodmeup-ca.cert.pem /usr/local/share/ca-certificates/foodmeup.local
sudo update-ca-certificates
}
addMacSSL() {
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ./.docker/nginx/ssl/foodmeup-ca.cert.pem
}
addCygwinSSL() {
echo "Unable to add SSL for CygWin platform";
exit;
}
while true; do
echo "Do you wish to init the FoodMeUp API project?";
read -p "(Y/N) " yn
case $yn in
[Yy]* )
echo "";
echo -e "${BLUE}Setting local host names...${NC}";
IFS=', '; array=($hostnames)
for host in ${array[@]}; do addHost $host; done
echo -e "${GREEN}Host names set!${NC}";
echo "";
echo "";
echo -e "${BLUE}Prepping environment, please wait...${NC}";
aws s3 cp s3://fmu-dev/ssl ./.docker/nginx/ssl/ --recursive --profile fmu
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) addLinuxSSL;;
Darwin*) addMacSSL;;
CYGWIN*) addCygwinSSL;;
*) exit;;
esac
rm ./.docker/nginx/ssl/foodmeup-ca.cert.pem
aws s3 cp s3://fmu-dev/env-api-devel ./.env --profile fmu
mkdir -p ./var/cache ./var/logs ./var/jwt ./var/cloud ./public/uploads
aws s3 cp s3://fmu-dev/fmu-google-cloud.json ./var/cloud/FoodMeUp-dc2389a0a0cd.json --profile fmu
JWT_PASSPHRASE=$(grep JWT_PASSPHRASE .env | cut -d '=' -f 2-)
openssl genrsa -passout pass:${JWT_PASSPHRASE} -out ./var/jwt/private.pem -aes256 4096
openssl rsa -passin pass:${JWT_PASSPHRASE} -pubout -in ./var/jwt/private.pem -out ./var/jwt/public.pem
echo -e "${GREEN}Environment all set!${NC}";
echo "";
echo -e "${BLUE}Building Docker containers, please wait...${NC}";
docker-compose up -d nginx;
docker-compose up -d postgres;
docker-compose up -d rabbitmq;
echo -e "${GREEN}Docker containers built!${NC}";
echo "";
echo -e "${BLUE}Installing Composer dependencies, please wait...${NC}";
docker exec -ti fmu_backend-php composer install --no-ansi --no-interaction --no-progress --no-suggest --optimize-autoloader;
echo -e "${GREEN}Composer dependencies installed!!${NC}";
echo "";
echo -e "${BLUE}Generating assets, please wait...${NC}";
docker exec -ti fmu_backend-php bin/console assets:install
echo -e "${GREEN}Assets generated!${NC}";
echo "";
echo -e "${BLUE}Initializing application, please wait...${NC}";
docker exec -ti fmu_backend-php /var/www/bin/phing init
echo -e "${GREEN}Application initialized!${NC}";
echo "";
echo -e "${GREEN}[ALL DONE]${NC}";
break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
echo -e "${GREEN}Project successfully installed${NC}";
解决方案
好吧,我一个接一个地接受每个命令,并试图让它发挥作用
这是结果
function Green {
process { Write-Host $_ -ForegroundColor Green }
}
function Red {
process { Write-Host $_ -ForegroundColor Red }
}
Write-output "Adding hosts...";
Set-HostsEntry -IPAddress 127.0.0.1 -HostName 'api.foodmeup.local' -Description "FoodMeUp local API"
Write-output "Host added" | Green;
Write-output "Adding certificates...";
aws s3 cp s3://fmu-dev/ssl ./.docker/nginx/ssl/ --recursive --profile fmu
Import-Certificate -FilePath "./.docker/nginx/ssl/foodmeup-ca.cert.pem" -CertStoreLocation cert:\CurrentUser\Root
Remove-Item ./.docker/nginx/ssl/foodmeup-ca.cert.pem
aws s3 cp s3://fmu-dev/env-api-devel ./.env --profile fmu
'./var/cache','./var/logs','./var/jwt','./var/cloud','./public/uploads','./vendor' | % {New-Item -Name "$_" -ItemType 'Directory'}
aws s3 cp s3://fmu-dev/fmu-google-cloud.json ./var/cloud/FoodMeUp-dc2389a0a0cd.json --profile fmu
$file = ".env"
$pattern = "(?<=JWT_PASSPHRASE=).*"
$values=Select-String -Path $file -Pattern $pattern |
Select-Object -Expand matches |
Select-Object value
$JWT_PASSPHRASE=$values.value
openssl genrsa -passout pass:$JWT_PASSPHRASE -out ./var/jwt/private.pem -aes256 4096
openssl rsa -passin pass:$JWT_PASSPHRASE -pubout -in ./var/jwt/private.pem -out ./var/jwt/public.pem
Write-output "Certificates added successfully" | Green
Write-output "Granting rights on all folders...";
takeown /r /d y /f "var"
icacls "./var/" /grant:r Users:F /t
Write-output "Rights granted" | Green;
Write-output "Building and uping all containers..."
Write-output "Make sure to accept prompts asking to share project local drive or share it manually...";
docker-compose up -d
Write-output "All containers up!" | Green
Write-output "Installing dependencies, please wait..."
docker exec -ti fmu_backend-php php composer install
Write-output "Dependencies installed!" | Green
Write-output "Generating assets, please wait..."
docker exec -ti fmu_backend-php bin/console assets:install
Write-output "Assets generated!" | Green
Write-output "Initializing application, please wait..."
docker exec -ti fmu_backend-php /var/www/bin/phing init
Write-output "Application initialized!" | Green
Write-output "All done!" | Green
推荐阅读
- html - Xpath 问题选择
嵌套在 - azure - Azure 无法初始化 UserPrincipal
- microsoft-graph-api - Microsoft Graph 刷新令牌到期
- node.js - 如何配置 IDE 以从资源管理器运行任何 node.js 文件?
- python - cross_val_score 与 sklearn 中的不同分类器的行为不同
- mongodb - 如何在 MongoDB 中将我的所有文本 _id 字段从“abc”更新为“xxx#abc”
- ios - Firebase Google 登录获取凭据
- java - 如何指定数组应从扫描仪接受哪些数字
- python - 结合 GridSearchCV 和 StackingClassifier
- python - 用于构建自动编码器的 keras.Flatten 的逆