Download and insert salt string inside wordpress wp-config.php with Bash

前端 未结 10 2298
有刺的猬
有刺的猬 2021-02-13 06:27

How can I insert the content of the variable $SALT in a specific point (line or string) of a file like wp-contet.php from wordpress using Bash script?



        
10条回答
  •  深忆病人
    2021-02-13 06:33

    I think I got this one! its a bash script using only commands normally available at the command prompt and it does -everything- (assuming httpd is your web user) except create the databases. here you go.

    #!/bin/bash
    
    # wordpress latest auto-install script, by alienation 24 jan 2013. run as root.
    # usage: ~/wp-install alien /hsphere/local/home/alien/nettrip.org alien_wpdbname alien_wpdbusername p@sSw0rd
    # ( wp-install shell-user folder db-name db-user-name db-user-pw )
    
    # download wordpress to temporary area
    cd /tmp
    rm -rf tmpwp
    mkdir tmpwp
    cd tmpwp
    wget http://wordpress.org/latest.tar.gz
    tar -xvzpf latest.tar.gz
    
    # copy wordpress to where it will live, and go there, removing index placeholder if there is one
    mv wordpress/* $2
    cd $2
    rm index.html
    
    # create config from sample, replacing salt example lines with a real salt from online generator
    grep -A 1 -B 50 'since 2.6.0' wp-config-sample.php > wp-config.php
    wget -O - https://api.wordpress.org/secret-key/1.1/salt/ >> wp-config.php
    grep -A 50 -B 3 'Table prefix' wp-config-sample.php >> wp-config.php
    
    # put the appropriate db info in place of placeholders in our new config file
    replace 'database_name_here' $3 -- wp-config.php
    replace 'username_here' $4 -- wp-config.php
    replace 'password_here' $5 -- wp-config.php
    
    # change file ownership and permissions according to ideal at http://codex.wordpress.org/Hardening_WordPress#File_Permissions
    touch .htaccess
    chown $1:httpd .htaccess
    chown -R $1:httpd *
    find . -type d -exec chmod 755 {} \;
    find . -type f -exec chmod 644 {} \;
    chmod -R 770 wp-content
    chmod -R g-w wp-admin wp-includes wp-content/plugins
    chmod g+w .htaccess
    
    # thats it!
    echo ALL DONE
    

提交回复
热议问题