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