sh来自https://segmentfault.com/q/1010000004634747(代码片段)

author author     2022-12-20     520

关键词:

#/bin/sh
set -e

if [[ -z "$port" ]]; then
  ls
fi

# run
nginx -g demon off
#!/bin/bash
set -e

if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
    if [ -n "$MYSQL_PORT_3306_TCP" ]; then
        if [ -z "$WORDPRESS_DB_HOST" ]; then
            WORDPRESS_DB_HOST='mysql'
        else
            echo >&2 'warning: both WORDPRESS_DB_HOST and MYSQL_PORT_3306_TCP found'
            echo >&2 "  Connecting to WORDPRESS_DB_HOST ($WORDPRESS_DB_HOST)"
            echo >&2 '  instead of the linked mysql container'
        fi
    fi
  
    if [ -z "$WORDPRESS_DB_HOST" ]; then
        echo >&2 'error: missing WORDPRESS_DB_HOST and MYSQL_PORT_3306_TCP environment variables'
        echo >&2 '  Did you forget to --link some_mysql_container:mysql or set an external db'
        echo >&2 '  with -e WORDPRESS_DB_HOST=hostname:port?'
        exit 1
    fi

    # if we're linked to MySQL and thus have credentials already, let's use them
    : $WORDPRESS_DB_USER:=$MYSQL_ENV_MYSQL_USER:-root
    if [ "$WORDPRESS_DB_USER" = 'root' ]; then
        : $WORDPRESS_DB_PASSWORD:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD
    fi
    : $WORDPRESS_DB_PASSWORD:=$MYSQL_ENV_MYSQL_PASSWORD
    : $WORDPRESS_DB_NAME:=$MYSQL_ENV_MYSQL_DATABASE:-wordpress

    if [ -z "$WORDPRESS_DB_PASSWORD" ]; then
        echo >&2 'error: missing required WORDPRESS_DB_PASSWORD environment variable'
        echo >&2 '  Did you forget to -e WORDPRESS_DB_PASSWORD=... ?'
        echo >&2
        echo >&2 '  (Also of interest might be WORDPRESS_DB_USER and WORDPRESS_DB_NAME.)'
        exit 1
    fi

    if ! [ -e index.php -a -e wp-includes/version.php ]; then
        echo >&2 "WordPress not found in $(pwd) - copying now..."
        if [ "$(ls -A)" ]; then
            echo >&2 "WARNING: $(pwd) is not empty - press Ctrl+C now if this is an error!"
            ( set -x; ls -A; sleep 10 )
        fi
        tar cf - --one-file-system -C /usr/src/wordpress . | tar xf -
        echo >&2 "Complete! WordPress has been successfully copied to $(pwd)"
        if [ ! -e .htaccess ]; then
            # NOTE: The "Indexes" option is disabled in the php:apache base image
            cat > .htaccess <<-'EOF'
                # BEGIN WordPress
                <IfModule mod_rewrite.c>
                RewriteEngine On
                RewriteBase /
                RewriteRule ^index\.php$ - [L]
                RewriteCond %REQUEST_FILENAME !-f
                RewriteCond %REQUEST_FILENAME !-d
                RewriteRule . /index.php [L]
                </IfModule>
                # END WordPress
            EOF
            chown www-data:www-data .htaccess
        fi
    fi

    # TODO handle WordPress upgrades magically in the same way, but only if wp-includes/version.php's $wp_version is less than /usr/src/wordpress/wp-includes/version.php's $wp_version

    # version 4.4.1 decided to switch to windows line endings, that breaks our seds and awks
    # https://github.com/docker-library/wordpress/issues/116
    # https://github.com/WordPress/WordPress/commit/1acedc542fba2482bab88ec70d4bea4b997a92e4
    sed -ri 's/\r\n|\r/\n/g' wp-config*

    if [ ! -e wp-config.php ]; then
        awk '/^\/\*.*stop editing.*\*\/$/ && c == 0  c = 1; system("cat")   print ' wp-config-sample.php > wp-config.php <<'EOPHP'
// If we're behind a proxy server and using HTTPS, we need to alert Wordpress of that fact
// see also http://codex.wordpress.org/Administration_Over_SSL#Using_a_Reverse_Proxy
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') 
    $_SERVER['HTTPS'] = 'on';


EOPHP
        chown www-data:www-data wp-config.php
    fi

    # see http://stackoverflow.com/a/2705678/433558
    sed_escape_lhs() 
        echo "$@" | sed 's/[]\/$*.^|[]/\\&/g'
    
    sed_escape_rhs() 
        echo "$@" | sed 's/[\/&]/\\&/g'
    
    php_escape() 
        php -r 'var_export(('$2') $argv[1]);' "$1"
    
    set_config() 
        key="$1"
        value="$2"
        var_type="$3:-string"
        start="(['\"])$(sed_escape_lhs "$key")\2\s*,"
        end="\);"
        if [ "$key:0:1" = '$' ]; then
            start="^(\s*)$(sed_escape_lhs "$key")\s*="
            end=";"
        fi
        sed -ri "s/($start\s*).*($end)$/\1$(sed_escape_rhs "$(php_escape "$value" "$var_type")")\3/" wp-config.php
    

    set_config 'DB_HOST' "$WORDPRESS_DB_HOST"
    set_config 'DB_USER' "$WORDPRESS_DB_USER"
    set_config 'DB_PASSWORD' "$WORDPRESS_DB_PASSWORD"
    set_config 'DB_NAME' "$WORDPRESS_DB_NAME"

    # allow any of these "Authentication Unique Keys and Salts." to be specified via
    # environment variables with a "WORDPRESS_" prefix (ie, "WORDPRESS_AUTH_KEY")
    UNIQUES=(
        AUTH_KEY
        SECURE_AUTH_KEY
        LOGGED_IN_KEY
        NONCE_KEY
        AUTH_SALT
        SECURE_AUTH_SALT
        LOGGED_IN_SALT
        NONCE_SALT
    )
    for unique in "$UNIQUES[@]"; do
        eval unique_value=\$WORDPRESS_$unique
        if [ "$unique_value" ]; then
            set_config "$unique" "$unique_value"
        else
            # if not specified, let's generate a random value
            current_set="$(sed -rn "s/define\((([\'\"])$unique\2\s*,\s*)(['\"])(.*)\3\);/\4/p" wp-config.php)"
            if [ "$current_set" = 'put your unique phrase here' ]; then
                set_config "$unique" "$(head -c1M /dev/urandom | sha1sum | cut -d' ' -f1)"
            fi
        fi
    done

    if [ "$WORDPRESS_TABLE_PREFIX" ]; then
        set_config '$table_prefix' "$WORDPRESS_TABLE_PREFIX"
    fi

    if [ "$WORDPRESS_DEBUG" ]; then
        set_config 'WP_DEBUG' 1 boolean
    fi

    TERM=dumb php -- "$WORDPRESS_DB_HOST" "$WORDPRESS_DB_USER" "$WORDPRESS_DB_PASSWORD" "$WORDPRESS_DB_NAME" <<'EOPHP'
<?php
// database might not exist, so let's try creating it (just to be safe)

$stderr = fopen('php://stderr', 'w');

list($host, $port) = explode(':', $argv[1], 2);

$maxTries = 10;
do 
    $mysql = new mysqli($host, $argv[2], $argv[3], '', (int)$port);
    if ($mysql->connect_error) 
        fwrite($stderr, "\n" . 'MySQL Connection Error: (' . $mysql->connect_errno . ') ' . $mysql->connect_error . "\n");
        --$maxTries;
        if ($maxTries <= 0) 
            exit(1);
        
        sleep(3);
    
 while ($mysql->connect_error);

if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `' . $mysql->real_escape_string($argv[4]) . '`')) 
    fwrite($stderr, "\n" . 'MySQL "CREATE DATABASE" Error: ' . $mysql->error . "\n");
    $mysql->close();
    exit(1);


$mysql->close();
EOPHP
fi

exec "$@"

xpath笔记-转

来自Xavier的笔记:https://segmentfault.com/u/lihanx and https://segmentfault.com/q/1010000008883941菜鸟Xpath教程:http://www.runoob.com/xpath/xpath-tutorial.html一、基本语法1.表达式nodename#节点名/#若在起始位置,则表明从根节点选 查看详情

算法类

排序快速https://segmentfault.com/a/1190000009426421选择https://segmentfault.com/a/1190000009366805希尔https://segmentfault.com/a/1190000009461832冒泡堆栈,队列,链表堆栈https://juejin.im/entry/58759e79128fe1006b48cdfd队列https://juejin.im/entry/58759e79128fe1006b48cdfd链表htt... 查看详情

kafka安装使用和遇到的坑(代码片段)

下载安装参考:https://segmentfault.com/a/1190000012730949?https://kafka.apache.org/quickstart关闭服务关闭zookeeperbin/zookeeper-server-stop.sh关闭kafkabin/kafka-server-stop.sh遇到的坑问题1[2018-04-0811:20:32,999]WARNSessi 查看详情

sh来自cacher(代码片段)

查看详情

sh来自shell的curl(代码片段)

查看详情

chrome调式工具

1.Elementshttps://segmentfault.com/a/11900000083166902.Consolehttps://segmentfault.com/a/11900000080749423.JS调试https://segmentfault.com/a/11900000083963894.Networkhttps://segmentfault.com/a/1190000008 查看详情

sh来自终端的快速提醒(bash)(代码片段)

查看详情

sh来自远程排除目录的rsync(代码片段)

查看详情

sh来自不同用户的gitpull命令(代码片段)

查看详情

ygzyybpzxq

第一步:请在下方输入框中输入你要搬家的博客个人主页地址,需要注意格式:SegmentFault:https://segmentfault.com/u/xxxx掘金:https://juejin.im/user/xxxx/postscsdn:https://blog.csdn.net/xxxx简书:https://www.jianshu.com/u/xxxx博客园:https://www.cnblo 查看详情

java示例代码_开一辆。来自java的sh文件

java示例代码_开一辆。来自java的sh文件 查看详情

gitlab实现代码自动部署(转载自https://segmentfault.com/a/1190000011561808)

在当下使用GIT来管理代码已经是一种非常流行的方式了。使用GIT可以很方便的给代码创建分支,撤销不需要的提交,与他人合作共同编写代码。GitLab是基于GIT实现的现代化的开发者协作平台,它将issues,codereview,CI和CD整合到独立... 查看详情

sh来自env文件的docker机密(代码片段)

查看详情

sh来自文件的shell中的topk(代码片段)

查看详情

sh我的自卸车装载来自备份(代码片段)

查看详情

sh等待来自url的200响应循环(代码片段)

查看详情

[转帖]数据库用优化方案https://segmentfault.com/a/1190000006158186(代码片段)

Mysql大表优化方案   当MySQL单表记录数过大时,增删改查性能都会急剧下降,可以参考以下步骤来优化:单表优化除非单表数据未来会一直不断上涨,否则不要一开始就考虑拆分,拆分会带来逻辑、部署、运维的各种... 查看详情

如何使用来自 Java 文本字段的用户输入运行 .sh 脚本?

】如何使用来自Java文本字段的用户输入运行.sh脚本?【英文标题】:Howrun.shscriptwithuserinputfromtextfieldinJava?【发布时间】:2020-02-0713:57:42【问题描述】:我尝试使用来自txtfield的用户输入来启动.sh脚本。思路:用户在txt字段中写入... 查看详情