sh 用于快速(呃)Laravel应用程序设置的Bash脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 用于快速(呃)Laravel应用程序设置的Bash脚本相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env bash

# Prompt for Yes/No answer
# $1 - question
# $2 - default answer (Y|N)
ask() {
    while true; do

        if [ "${2:-}" = "Y" ]; then
            prompt="Y/n"
            default=Y
        elif [ "${2:-}" = "N" ]; then
            prompt="y/N"
            default=N
        else
            prompt="y/n"
            default=
        fi
        # Prompt
        REPLY=`prompt "$1" $prompt`

        # Default?
        if [ -z "$REPLY" ]; then
            REPLY=$default
        fi

        # Check if the reply is valid
        case "$REPLY" in
            Y*|y*) return 0 ;;
            N*|n*) return 1 ;;
        esac

    done
}

# Prompt for an answer
# $1 - question
# $2 - default value (optional)
prompt() {
    QUESTION=$1

    if [ ! -z "$2" ]; then
        DEFAULT=$2
        QUESTION="$QUESTION [$DEFAULT]"
    fi

    # Ask the question - use /dev/tty in case stdin is redirected from somewhere else
    read -p "$QUESTION: " ANSWER </dev/tty

    # Default?
    if [ -z "$ANSWER" ]; then
        ANSWER=$DEFAULT
    fi
    echo $ANSWER
}

CURRENT_DIR=${PWD##*/}
if ask "Create project in current directory? (./$CURRENT_DIR)" 'Y'; then
    # Setup Laravel Project
    PROJECTNAME=$1
    composer create-project laravel/laravel --prefer-dist .

    if [ $? -eq 0 ]; then

        if [ ! -z PROJECTNAME ]; then
            echo "Setting application namespace to $PROJECTNAME"
            php artisan app:name $PROJECTNAME
        fi
        echo "Setup directory & file permissions"
        find ./storage -type d -mindepth 1 -exec chmod 777 {} \;
        chmod 777 bootstrap/cache
        echo "Done"

        if ask 'Run npm install?' 'Y'; then
            npm install
        fi
        if ask 'Open in Sublime?' 'Y'; then
            subl .
        fi
    fi
fi

以上是关于sh 用于快速(呃)Laravel应用程序设置的Bash脚本的主要内容,如果未能解决你的问题,请参考以下文章

sh 用于快速设置Golang环境的Bash脚本

sh 聚光灯重建呃!

sh 用于部署Laravel应用程序的脚本包括维护模式,编写器,迁移,清除缓存和重新启动队列

sh 设置laravel5项目以部署到共享主机提供程序

快速(呃)numpy花式索引和减少?

sh 在服务器存储上设置Laravel的权限