| 4 | | * This command line script will setup an Editam site given the configuration parameters |
|---|
| 5 | | * |
|---|
| 6 | | * Application name: |
|---|
| | 4 | * This installer allows you to create editam site from the command line programatically. |
|---|
| | 5 | * |
|---|
| | 6 | * php install.php --database_host localhost --database_name editam --database_password pass --database_user root --database_type mysql --email bermi@example.com --locales en es --login bermi --password bermipass --path /Users/bermi/Sites/editam --site_name "Editam Demo" --url_suffix /editam |
|---|
| | 7 | * |
|---|
| | 8 | * Configuration files might be either a php file with an $options array like: |
|---|
| | 9 | * |
|---|
| | 10 | * <?php |
|---|
| | 11 | * |
|---|
| | 12 | * $options = array ( |
|---|
| | 13 | * 'database_host' => 'localhost', |
|---|
| | 14 | * 'database_name' => 'editam', |
|---|
| | 15 | * 'database_password' => 'pass', |
|---|
| | 16 | * 'database_user' => 'root', |
|---|
| | 17 | * 'database_type' => 'mysql', |
|---|
| | 18 | * 'email' => 'bermi@example.com', |
|---|
| | 19 | * 'locales' => |
|---|
| | 20 | * array ( |
|---|
| | 21 | * 0 => 'en', |
|---|
| | 22 | * 1 => 'es', |
|---|
| | 23 | * ), |
|---|
| | 24 | * 'login' => 'bermi', |
|---|
| | 25 | * 'password' => 'bermipass', |
|---|
| | 26 | * 'path' => '/Users/bermi/Sites/editam', |
|---|
| | 27 | * 'site_name' => 'Editam Demo', |
|---|
| | 28 | * 'url_suffix' => '/editam', |
|---|
| | 29 | * ); |
|---|
| | 30 | * |
|---|
| | 31 | * ?> |
|---|
| | 32 | * |
|---|
| | 33 | * Using a PHP configuration file might allow you to add post install actions like fixing path permissions using register_shutdown_function() or implementing a function named after_editam_install() |
|---|
| | 34 | * |
|---|
| | 35 | * If your configuration file extension is YAML or txt it will need to be YAML compliant like: |
|---|
| | 36 | * |
|---|
| | 37 | * database_host: localhost |
|---|
| | 38 | * database_name: editam |
|---|
| | 39 | * database_password: pass |
|---|
| | 40 | * database_user: root |
|---|
| | 41 | * database_type: mysql |
|---|
| | 42 | * email: bermi@example.com |
|---|
| | 43 | * locales: |
|---|
| | 44 | * - en |
|---|
| | 45 | * - es |
|---|
| | 46 | * login: bermi |
|---|
| | 47 | * password: bermipass |
|---|
| | 48 | * path: /Users/bermi/Sites/editam |
|---|
| | 49 | * site_name: Editam Demo |
|---|
| | 50 | * url_suffix: /editam |
|---|
| 54 | | 'host' => array( |
|---|
| | 102 | 'database_host' => array( |
|---|
| | 103 | 'short' => 'dbh', |
|---|
| | 104 | 'max' => 1, |
|---|
| | 105 | 'min' => 1, |
|---|
| | 106 | 'default' => 'localhost', |
|---|
| | 107 | 'desc' => 'Database host.'), |
|---|
| | 108 | |
|---|
| | 109 | 'database_user' => array( |
|---|
| | 110 | 'short' => 'dbu', |
|---|
| | 111 | 'max' => 1, |
|---|
| | 112 | 'min' => 1, |
|---|
| | 113 | 'desc' => 'Database user.'), |
|---|
| | 114 | |
|---|
| | 115 | 'database_name' => array( |
|---|
| | 116 | 'short' => 'dbn', |
|---|
| | 117 | 'max' => 1, |
|---|
| | 118 | 'min' => 1, |
|---|
| | 119 | 'default' => 'editam', |
|---|
| | 120 | 'desc' => 'Database password.'), |
|---|
| | 121 | |
|---|
| | 122 | 'database_password' => array( |
|---|
| | 123 | 'short' => 'dbp', |
|---|
| | 124 | 'max' => 1, |
|---|
| | 125 | 'min' => 1, |
|---|
| | 126 | 'desc' => 'Database password.'), |
|---|
| | 127 | |
|---|
| | 128 | |
|---|
| | 129 | 'database_type' => array( |
|---|
| | 130 | 'short' => 'dbt', |
|---|
| | 131 | 'max' => 1, |
|---|
| | 132 | 'min' => 1, |
|---|
| | 133 | 'default' => 'mysql', |
|---|
| | 134 | 'desc' => 'Database type.'), |
|---|
| | 135 | |
|---|
| | 136 | |
|---|
| | 137 | 'url_suffix' => array( |
|---|
| | 138 | 'short' => 'url', |
|---|
| | 139 | 'max' => 1, |
|---|
| | 140 | 'min' => 1, |
|---|
| | 141 | 'desc' => 'Url suffix.'), |
|---|
| | 142 | |
|---|
| | 143 | 'locales' => array( |
|---|
| | 144 | 'short' => 'lc', |
|---|
| | 145 | 'max' => 8, |
|---|
| | 146 | 'min' => 1, |
|---|
| | 147 | 'default' => 'en', |
|---|
| | 148 | 'desc' => 'Locales.'), |
|---|
| | 149 | |
|---|
| | 150 | 'config' => array( |
|---|
| | 151 | 'short' => 'c', |
|---|
| | 152 | 'max' => 1, |
|---|
| | 153 | 'min' => 1, |
|---|
| | 154 | 'desc' => 'Use a configuration file for getting the installer values.'), |
|---|
| | 155 | |
|---|
| | 156 | 'ftp_user' => array( |
|---|
| | 157 | 'short' => 'fu', |
|---|
| | 158 | 'max' => 1, |
|---|
| | 159 | 'min' => 0, |
|---|
| | 160 | 'desc' => 'FTP user name.'), |
|---|
| | 161 | |
|---|
| | 162 | 'ftp_password' => array( |
|---|
| | 163 | 'short' => 'fp', |
|---|
| | 164 | 'max' => 1, |
|---|
| | 165 | 'min' => 1, |
|---|
| | 166 | 'desc' => 'FTP password.'), |
|---|
| | 167 | |
|---|
| | 168 | 'ftp_host' => array( |
|---|
| | 169 | 'short' => 'fh', |
|---|
| | 170 | 'max' => 1, |
|---|
| | 171 | 'min' => 1, |
|---|
| | 172 | 'desc' => 'FTP host.'), |
|---|
| | 173 | |
|---|
| | 174 | |
|---|
| | 175 | 'ftp_path' => array( |
|---|
| | 176 | 'short' => 'fd', |
|---|
| | 177 | 'max' => 1, |
|---|
| | 178 | 'min' => 1, |
|---|
| | 179 | 'desc' => 'FTP path.'), |
|---|
| | 180 | |
|---|
| | 181 | 'help' => array( |
|---|
| 125 | | if(empty($options)){ |
|---|
| | 227 | if(!empty($options['config'])){ |
|---|
| | 228 | if(file_exists($options['config'])){ |
|---|
| | 229 | $extension = array_pop(pathinfo($options['config'])); |
|---|
| | 230 | $config_file = $options['config']; |
|---|
| | 231 | $cmd_options = $options; |
|---|
| | 232 | $options = array(); |
|---|
| | 233 | if($extension == 'php'){ |
|---|
| | 234 | include_once($config_file); |
|---|
| | 235 | }elseif($extension == 'txt' || $extension == 'yaml'){ |
|---|
| | 236 | $options = Ak::convert('yaml','array', file_get_contents($config_file)); |
|---|
| | 237 | }else{ |
|---|
| | 238 | echo "Unrecognized configuration format {$config_file}. Please use the extension php or txt.\n"; |
|---|
| | 239 | } |
|---|
| | 240 | }else{ |
|---|
| | 241 | echo "Could not find configuration file {$config_file}\n"; |
|---|
| | 242 | } |
|---|
| | 243 | } |
|---|
| | 244 | |
|---|
| | 245 | if(empty($options) || (empty($options['path']) && empty($config_file))){ |
|---|
| 130 | | print_r($options); |
|---|
| 131 | | |
|---|
| | 250 | if(!empty($cmd_options)){ |
|---|
| | 251 | $options = array_merge($cmd_options, $options); |
|---|
| | 252 | } |
|---|
| | 253 | |
|---|
| | 254 | if(!empty($options['quiet'])){ |
|---|
| | 255 | ob_start(); |
|---|
| | 256 | } |
|---|
| | 257 | |
|---|
| | 258 | // Check if destination path exists |
|---|
| | 259 | if(count(Ak::dir($options['path'])) > 0 && empty($options['force'])){ |
|---|
| | 260 | echo "Destination directory ({$options['path']}) is not empty. Please add --force if you want to override existing contents.\n"; |
|---|
| | 261 | return; |
|---|
| | 262 | } |
|---|
| | 263 | |
|---|
| | 264 | // Build a release |
|---|
| | 265 | echo "Building latest release.\n"; |
|---|
| | 266 | $build_serults = (`./makelos.php`); |
|---|
| | 267 | if(preg_match('/builds\/(.+)\.zip/', $build_serults, $match)){ |
|---|
| | 268 | echo "Will use {$match[1]}\n"; |
|---|
| | 269 | } |
|---|
| | 270 | |
|---|
| | 271 | // Unpack release and move to the setup path |
|---|
| | 272 | echo "Unpacking builds/{$match[1]}.tar.gz and moving it to {$options['path']}\n"; |
|---|
| | 273 | if(!is_dir(AK_BASE_DIR."/build/builds/{$match[1]}")){ |
|---|
| | 274 | (`tar -zxvf builds/{$match[1]}.tar.gz -C ./builds`); |
|---|
| | 275 | } |
|---|
| | 276 | (`cp -Rf builds/{$match[1]}/ {$options['path']}`); |
|---|
| | 277 | |
|---|
| | 278 | // Create temporary settings file |
|---|
| | 279 | file_put_contents("{$options['path']}/config/setup_options.txt", Ak::convert('array','yaml',$options)); |
|---|
| | 280 | |
|---|
| | 281 | // Run the editam setup against temp settings |
|---|
| | 282 | |
|---|
| | 283 | /* |
|---|
| | 284 | Ak::import('editam_setup'); |
|---|
| | 285 | $EditamSetup =& new EditamSetup(); |
|---|
| | 286 | $configuration_file = $EditamSetup->getConfigurationFile(); |
|---|
| | 287 | $EditamSetup->writeConfigurationFile($configuration_file); |
|---|
| | 288 | $EditamSetup->writeRoutesFile(); |
|---|
| | 289 | $EditamSetup->runEditamInstaller(); |
|---|
| | 290 | if($EditamSetup->hasUrlSuffix()){ |
|---|
| | 291 | $EditamSetup->modifyHtaccessFiles(); |
|---|
| | 292 | } |
|---|
| | 293 | $EditamSetup->relativizeStylesheetPaths(); |
|---|
| | 294 | */ |
|---|
| | 295 | // Remove tmp settings |
|---|
| | 296 | |
|---|
| | 297 | |
|---|
| | 298 | if(function_exists('after_editam_install')){ |
|---|
| | 299 | after_editam_install($options); |
|---|
| | 300 | } |
|---|
| | 301 | |
|---|
| | 302 | if(!empty($options['quiet'])){ |
|---|
| | 303 | ob_end_clean(); |
|---|
| | 304 | } |
|---|