github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/acceptancetests/repository/xenial/wordpress/hooks/db-relation-changed (about)

     1  #!/bin/bash
     2  
     3  set -eu
     4  
     5  juju-log "We've got a db"
     6  
     7  source inc/common
     8  
     9  if [ -f "$config_file_path" ]; then
    10  	# No longer to quietly in to that good night. Update the wp-config file with new DB values
    11  	juju-log "WordPress is already setup, just silently going away"
    12  	exit 0
    13  fi
    14  
    15  database=`relation-get database`
    16  user=`relation-get user`
    17  password=`relation-get password`
    18  host=`relation-get private-address`
    19  
    20  if [ -z "$database" ] ; then
    21  	exit 0
    22  fi
    23  
    24  source "/usr/share/charm-helper/sh/net.sh"
    25  
    26  payload=`ch_get_file "https://wordpress.org/latest.tar.gz" "https://wordpress.org/latest.tar.gz.sha1"`
    27  
    28  if [ ! -f "$payload" ] || [ -z "$payload" ]; then
    29  	juju-log "Failed to retrieve latest.tar.gz"
    30  	exit 1
    31  fi
    32  
    33  juju-log "Extract ALL THE FILES!"
    34  tar -xzf $payload
    35  
    36  mkdir -p $wp_install_path
    37  
    38  juju-log "Move them in to place, but just 'drop' them in place."
    39  rsync -az wordpress/ $wp_install_path
    40  
    41  juju-log "Clean up"
    42  rm -rf wordpress
    43  
    44  secret_key=`cat .wp-secret`
    45  
    46  juju-log "Writing wordpress config file $config_file_path"
    47  # Write the wordpress config
    48  cat > $config_info_path <<EOF
    49  <?php
    50  define('DB_NAME', '$database');
    51  define('DB_USER', '$user');
    52  define('DB_PASSWORD', '$password');
    53  define('DB_HOST', '$host');
    54  define('SECRET_KEY', '$secret_key');
    55  
    56  define('WP_CACHE', true);
    57  
    58  /*
    59  define('AUTH_KEY', '$secret_key');
    60  define('SECURE_AUTH_KEY', '$secret_key');
    61  define('LOGGED_IN_KEY', '$secret_key');
    62  define('NONCE_KEY', '$secret_key');
    63  */
    64  
    65  \$table_prefix  = 'wp_';
    66  
    67  EOF
    68  
    69  cat > $config_file_path <<EOF
    70  <?php
    71  
    72  /* That's all, stop editing! Happy blogging. */
    73  
    74  /** Absolute path to the WordPress directory. */
    75  if ( !defined('ABSPATH') )
    76          define('ABSPATH', dirname(__FILE__) . '/');
    77  
    78  /** Pull in the config information */
    79  require_once(ABSPATH . 'wp-info.php');
    80  require_once(ABSPATH . 'wp-overrides.php');
    81  
    82  /** Sets up WordPress vars and included files. */
    83  require_once(ABSPATH . 'wp-settings.php');
    84  
    85  remove_filter('template_redirect', 'redirect_canonical');
    86  
    87  EOF
    88  
    89  chmod 0644 $config_file_path
    90  touch $config_override_path
    91  
    92  juju-log "Resetting permissions"
    93  
    94  chown -R www-data.www-data $wp_install_path
    95  
    96  . hooks/config-changed
    97  . hooks/restart
    98  
    99  # Make it publicly visible, once the wordpress service is exposed
   100  open-port 80/tcp