From be5e16f4aff0073bcfec1593396b57430a601621 Mon Sep 17 00:00:00 2001 From: Anmol Date: Wed, 12 Jul 2017 05:15:37 +0530 Subject: [PATCH] Initial commit --- LICENSE | 136 +++++++++++++++ README.md | 12 +- check_process | 39 +++++ conf/install.php | 407 +++++++++++++++++++++++++++++++++++++++++++++ conf/nginx.conf | 37 +++++ manifest.json | 75 +++++++++ scripts/_common.sh | 111 +++++++++++++ scripts/install | 162 ++++++++++++++++++ scripts/remove | 45 +++++ scripts/upgrade | 77 +++++++++ 10 files changed, 1100 insertions(+), 1 deletion(-) create mode 100644 LICENSE create mode 100644 check_process create mode 100644 conf/install.php create mode 100644 conf/nginx.conf create mode 100644 manifest.json create mode 100644 scripts/_common.sh create mode 100644 scripts/install create mode 100644 scripts/remove create mode 100644 scripts/upgrade diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..106c7f1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,136 @@ +Joomla Licenses + +GNU GENERAL PUBLIC LICENSE + +Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. +Preamble + +The licenses for most software are designed to take away yourfreedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. +For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. + +Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and modification follow. +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. + +You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. + + c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. + +If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. + +5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. + +7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. + +10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. +NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +END OF TERMS AND CONDITIONS +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. + +one line to give the program's name and an idea of what it does. +Copyright (C) yyyy name of author + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this when it starts in an interactive mode: + +Gnomovision version 69, Copyright (C) year name of author +Gnomovision comes with ABSOLUTELY NO WARRANTY; for details +type `show w'. This is free software, and you are welcome +to redistribute it under certain conditions; type `show c' +for details. + +The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright +interest in the program `Gnomovision' +(which makes passes at compilers) written +by James Hacker. + +signature of Ty Coon, 1 April 1989 +Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. + diff --git a/README.md b/README.md index 4045820..8eacf40 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,12 @@ # Joomla_ynh -Joomla! is an award-winning content management system https://www.joomla.org/ +Joomla! is an award-winning content management system https://www.joomla.org/

+ +There is installer.php added for bypassing the web installation process. see https://github.com/joomla/joomla-cms/pull/2764 + +# To-do +- [X] Installation and remove script +- [ ] Ldap integration +- [ ] Make update script better to backup content +- [ ] Backup and restore script +- [ ] Add php-fpm.ini and php-fpm.conf + diff --git a/check_process b/check_process new file mode 100644 index 0000000..91150a7 --- /dev/null +++ b/check_process @@ -0,0 +1,39 @@ +;; Nom du test +# Commentaire ignoré + ; Manifest + domain="domain.tld" (DOMAIN) + path="/path" (PATH) + username="john" + email="john@domain.tld" + password="password" +# is_public="Yes" (PUBLIC|public=Yes|private=No) + is_public=1 (PUBLIC|public=1|private=0) + + + ; Checks + pkg_linter=1 + setup_sub_dir=1 + setup_root=1 + setup_nourl=0 + setup_private=1 + setup_public=1 + upgrade=1 + backup_restore=0 + multi_instance=1 + incorrect_path=1 + port_already_use=0 (66) + change_url=0 +;;; Levels + Level 1=auto + Level 2=auto + Level 3=auto + Level 4=0 + Level 5=auto + Level 6=0 + Level 7=auto + Level 8=0 + Level 9=0 + Level 10=0 +;;; Options +Email= +Notification=none diff --git a/conf/install.php b/conf/install.php new file mode 100644 index 0000000..a07e0e8 --- /dev/null +++ b/conf/install.php @@ -0,0 +1,407 @@ + array( + 'getopt' => 'help', + 'description' => 'Display help', + ), + 'admin_email' => array( + 'getopt' => 'admin-email:', + 'description' => 'Admin user\'s email', + 'required' => true, + ), + 'admin_password' => array( + 'getopt' => 'admin-pass:', + 'description' => 'Admin user\'s password', + 'required' => true, + ), + 'admin_user' => array( + 'getopt' => 'admin-user:', + 'description' => 'Admin user\'s username', + 'default' => 'admin', + ), + 'db_host' => array( + 'getopt' => 'db-host:', + 'description' => 'Hostname (or hostname:port)', + 'default' => 'localhost', + ), + 'db_name' => array( + 'getopt' => 'db-name:', + 'description' => 'Database name', + 'required' => true, + ), + 'db_old' => array( + 'getopt' => 'db-old:', + 'description' => 'Policy to use with old DB [remove,backup]]', + 'default' => 'remove', + ), + 'db_pass' => array( + 'getopt' => 'db-pass:', + 'description' => 'Database password', + 'required' => true, + ), + 'db_prefix' => array( + 'getopt' => 'db-prefix:', + 'description' => 'Table prefix', + 'factory' => function () { + // FIXME: Duplicated from installation/model/fields/prefix.php + $size = 5; + $prefix = ''; + $chars = range('a', 'z'); + $numbers = range(0, 9); + // We want the fist character to be a random letter: + shuffle($chars); + $prefix .= $chars[0]; + // Next we combine the numbers and characters to get the other characters: + $symbols = array_merge($numbers, $chars); + shuffle($symbols); + for ($i = 0, $j = $size - 1; $i < $j; ++$i) + { + $prefix .= $symbols[$i]; + } + // Add in the underscore: + $prefix .= '_'; + return $prefix; + }, + ), + 'db_type' => array( + 'getopt' => 'db-type:', + 'description' => 'Database type [mysql,mysqli,postgresql,sqlsrv,sqlazure]', + 'default' => 'mysqli', + ), + 'db_user' => array( + 'getopt' => 'db-user:', + 'description' => 'Database user', + 'required' => true, + ), + 'helpurl' => array( + 'getopt' => 'help-url:', + 'description' => 'Help URL', + 'default' => 'http://help.joomla.org/proxy/index.php?option=com_help&keyref=Help{major}{minor}:{keyref}', + ), + // FIXME: Not clear if this is useful. Seems to be "the language of the installation application" + // and not "the language of the installed CMS" + 'language' => array( + 'getopt' => 'lang:', + 'description' => 'Language', + 'default' => 'en-US', + ), + 'site_metadesc' => array( + 'getopt' => 'desc:', + 'description' => 'Site description', + 'default' => '' + ), + 'site_name' => array( + 'getopt' => 'name:', + 'description' => 'Site name', + 'default' => 'Joomla' + ), + 'site_offline' => array( + 'getopt' => 'offline', + 'description' => 'Set site as offline', + 'default' => 0, + ), + 'sample_file' => array( + 'getopt' => 'sample:', + 'description' => 'Sample SQL file (sample_blog.sql,sample_brochure.sql,...)', + 'default' => '', + ), + 'summary_email' => array( + 'getopt' => 'email', + 'description' => 'Send email notification', + 'default' => 0, + ), + ); + // Installer internally has an option "admin_password2", but it + // doesn't seem to be necessary. + foreach (array_keys($optionsMetadata) as $key) + { + if (!isset($optionsMetadata[$key]['syntax'])) + { + if (preg_match('/:$/', $optionsMetadata[$key]['getopt'])) + { + $optionsMetadata[$key]['syntax'] = '--' . rtrim($optionsMetadata[$key]['getopt'], ':') . '="..."'; + } + else + { + $optionsMetadata[$key]['syntax'] = '--' . $optionsMetadata[$key]['getopt']; + } + } + } + return $optionsMetadata; + } + /** + * Entry point for the script + * + * @return void + * + * @since 2.5 + */ + public function doExecute() + { + JFactory::getApplication('CliInstaller'); + // Parse options + $options = $this->parseOptions(); + if (array_key_exists('help', $options)) + { + $this->displayUsage(); + $this->close(0); + } + $errors = $this->validateOptions($options); + if (!empty($errors)) + { + foreach ($errors as $error) + { + $this->enqueueMessage($error, 'fatal'); + } + $this->displayUsage(); + $this->close(1); + } + // Attempt to initialise the database. + $db = new InstallationModelDatabase; + if (!$db->createDatabase($options)) + { + $this->fatal("Error executing createDatabase"); + } + // FIXME InstallationModelDatabase relies on session manipulation which doesn't work well in cli + // $session = JFactory::getSession(); + // $options = $session->get('setup.options', NULL); + $options['db_created'] = 1; + $options['db_select'] = 1; + if ($options['db_old'] == 'backup') + { + if (!$db->handleOldDatabase($options)) + { + $this->fatal("Error executing handleOldDatabase"); + } + } + if (!$db->createTables($options)) + { + $this->fatal("Error executing createTables"); + } + // Attempt to setup the configuration. + $configuration = new InstallationModelConfiguration; + if (!$configuration->setup($options)) + { + $this->fatal("Error executing setup"); + } + // Attempt to create the database tables. + if ($options['sample_file']) + { + if (!$db->installSampleData($options)) + { + $this->fatal("Error executing installSampleData"); + } + } + $this->out('Done'); + } + /** + * Display help text + * + * @return void + */ + public function displayUsage() + { + $this->out("Install Joomla"); + $this->out("usage: php install.php [options]"); + foreach ($this->getOptionsMetadata() as $spec) + { + $syntax = sprintf("%-25s", $spec['syntax']); + if (isset($spec['description'])) + { + $syntax .= $spec['description']; + } + if (isset($spec['required']) && $spec['required']) + { + $syntax .= ' (required)'; + } + if (isset($spec['default'])) + { + $syntax .= " (default: {$spec['default']})"; + } + if (isset($spec['factory'])) + { + $syntax .= " (default: auto-generated)"; + } + $this->out(" " . $syntax); + } + } + /** + * Validate the inputs + * + * @param array $options parsed input values + * + * @return array of error messages + */ + public function validateOptions($options) + { + $optionsMetadata = $this->getOptionsMetadata(); + $errors = array(); + foreach ($optionsMetadata as $key => $spec) + { + if (!isset($options[$key]) && isset($spec['required']) && $spec['required']) + { + $errors[] = "Missing required option: {$spec['syntax']}"; + } + } + return $errors; + } + /** + * Parse all options from the command-line + * + * @return array + */ + public function parseOptions() + { + global $argv; + if (count($argv) <= 1) + { + return array('help' => 1); + } + $optionsMetadata = $this->getOptionsMetadata(); + $longopts = array(); + foreach ($optionsMetadata as $key => $spec) + { + $longopts[] = $spec['getopt']; + } + $rawOptions = getopt("", $longopts); + $options = array(); + foreach ($optionsMetadata as $key => $spec) + { + $rawKey = rtrim($spec['getopt'], ':'); + if (isset($rawOptions[$rawKey])) + { + if (preg_match('/:$/', $spec['getopt'])) + { + $options[$key] = $rawOptions[$rawKey]; + } + else + { + $options[$key] = 1; + } + } + elseif (isset($spec['factory'])) + { + $options[$key] = call_user_func($spec['factory']); + } + elseif (isset($spec['default'])) + { + $options[$key] = $spec['default']; + } + } + return $options; + } + /** + * Enqueue a system message. + * + * @param string $msg The message to enqueue. + * @param string $type The message type. Default is message. + * + * @return void + * + * @since 3.2 + */ + public function enqueueMessage($msg, $type = 'message') + { + $this->out("[$type] $msg"); + } + /** + * Trigger a fatal error + * + * @param string $msg The message to enqueue. + * + * @return void + */ + public function fatal($msg) + { + $this->enqueueMessage($msg, 'fatal'); + $this->close(1); + } + /** + * FIXME: Duplicated from ./installation/application/web.php + */ + public function getLocaliseAdmin($db = false) + { + // Read the files in the admin area + $path = JLanguage::getLanguagePath(JPATH_ADMINISTRATOR); + $langfiles['admin'] = JFolder::folders($path); + // Read the files in the site area + $path = JLanguage::getLanguagePath(JPATH_SITE); + $langfiles['site'] = JFolder::folders($path); + if ($db) + { + $langfiles_disk = $langfiles; + $langfiles = array(); + $langfiles['admin'] = array(); + $langfiles['site'] = array(); + $query = $db->getQuery(true) + ->select($db->quoteName(array('element', 'client_id'))) + ->from($db->quoteName('#__extensions')) + ->where($db->quoteName('type') . ' = ' . $db->quote('language')); + $db->setQuery($query); + $langs = $db->loadObjectList(); + foreach ($langs as $lang) + { + switch ($lang->client_id) + { + // Site + case 0: + if (in_array($lang->element, $langfiles_disk['site'])) + { + $langfiles['site'][] = $lang->element; + } + break; + // Administrator + case 1: + if (in_array($lang->element, $langfiles_disk['admin'])) + { + $langfiles['admin'][] = $lang->element; + } + break; + } + } + } + return $langfiles; + } +} +JApplicationCli::getInstance('JApplicationCliInstaller')->execute(); diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..3a3112e --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,37 @@ +location __PATH__ { + alias __FINALPATH__/; + + # Default indexes and catch-all + index index.html index.php; + try_files $uri $uri/ __PATH__/index.php?$args; + + # Prevent useless logs + location = __PATH__/favicon.ico { + log_not_found off; + access_log off; + } + location = __PATH__/robots.txt { + allow all; + log_not_found off; + access_log off; + } + + # Deny access to hidden files and directories + location ~ ^__PATH__/(.+/|)\.(?!well-known\/) { + deny all; + } + + # Execute and serve PHP files + location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + fastcgi_pass unix:/var/run/php5-fpm-my_webapp__11.sock; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param REMOTE_USER $remote_user; + fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_param SCRIPT_FILENAME $request_filename; + } + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; +} diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..00afe3f --- /dev/null +++ b/manifest.json @@ -0,0 +1,75 @@ +{ + "name": "Joomla", + "id": "joomla", + "packaging_format": 1, + "description": { + "en": "Example package for YunoHost application." + }, + "url": "https://www.joomla.org", + "license": "free", + "maintainer": { + "name": "Anmol Sharma", + "email": "anmol@datamol.in" + }, + "requirements": { + "yunohost": ">> 2.5.6" + }, + "multi_instance": true, + "services": [ + "nginx", + "php5-fpm", + "mysql" + ], + "arguments": { + "install" : [ + { + "name": "domain", + "type": "domain", + "ask": { + "en": "Choose a domain name for ynhexample" + }, + "example": "example.com" + }, + { + "name": "path", + "type": "path", + "ask": { + "en": "Choose a path for ynhexample" + }, + "example": "/example", + "default": "/joomla" + }, + { + "name": "username", + "ask": { + "en": "Admin unsername" + }, + "example": "john" + }, + { + "name": "email", + "ask": { + "en": "Admin email" + }, + "example": "admin@example.com" + }, + { + "name": "password", + "type": "password", + "ask": { + "en": "Password for the admin account (At least 6 characters long)" + }, + "example": "admin@example.com" + }, + { + "name": "is_public", + "type": "boolean", + "ask": { + "en": "Is it a public application?" + + }, + "default": true + } + ] + } +} diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..1e42df9 --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +# ============================================================================= +# YUNOHOST 2.7 FORTHCOMING HELPERS +# ============================================================================= + +# Create a dedicated nginx config +# +# usage: ynh_add_nginx_config +ynh_add_nginx_config () { + finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf" + + sudo cp ../conf/nginx.conf "$finalnginxconf" + + # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. + # Substitute in a nginx config file only if the variable is not empty + if test -n "${path_url:-}"; then + ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf" + fi + if test -n "${domain:-}"; then + ynh_replace_string "__DOMAIN__" "$domain" "$finalnginxconf" + fi + if test -n "${port:-}"; then + ynh_replace_string "__PORT__" "$port" "$finalnginxconf" + fi + if test -n "${app:-}"; then + ynh_replace_string "__NAME__" "$app" "$finalnginxconf" + fi + if test -n "${final_path:-}"; then + ynh_replace_string "__FINALPATH__" "$final_path" "$finalnginxconf" + fi + + sudo systemctl reload nginx +} + +# Remove the dedicated nginx config +# +# usage: ynh_remove_nginx_config +ynh_remove_nginx_config () { + ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf" + sudo systemctl reload nginx +} + +# Create a dedicated php-fpm config +# +# usage: ynh_add_fpm_config +ynh_add_fpm_config () { + finalphpconf="/etc/php5/fpm/pool.d/$app.conf" + ynh_backup_if_checksum_is_different "$finalphpconf" 1 + sudo cp ../conf/php-fpm.conf "$finalphpconf" + ynh_replace_string "__NAMETOCHANGE__" "$app" "$finalphpconf" + ynh_replace_string "__FINALPATH__" "$final_path" "$finalphpconf" + ynh_replace_string "__USER__" "$app" "$finalphpconf" + sudo chown root: "$finalphpconf" + ynh_store_file_checksum "$finalphpconf" + + if [ -e "../conf/php-fpm.ini" ] + then + finalphpini="/etc/php5/fpm/conf.d/20-$app.ini" + ynh_compare_checksum_config "$finalphpini" 1 + sudo cp ../conf/php-fpm.ini "$finalphpini" + sudo chown root: "$finalphpini" + ynh_store_checksum_config "$finalphpini" + fi + + sudo systemctl reload php5-fpm +} + +# Remove the dedicated php-fpm config +# +# usage: ynh_remove_fpm_config +ynh_remove_fpm_config () { + ynh_secure_remove "/etc/php5/fpm/pool.d/$app.conf" + ynh_secure_remove "/etc/php5/fpm/conf.d/20-$app.ini" 2>&1 + sudo systemctl reload php5-fpm +} + +# Create a dedicated systemd config +# +# usage: ynh_add_systemd_config +ynh_add_systemd_config () { + finalsystemdconf="/etc/systemd/system/$app.service" + ynh_compare_checksum_config "$finalsystemdconf" 1 + sudo cp ../conf/systemd.service "$finalsystemdconf" + + # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. + # Substitute in a nginx config file only if the variable is not empty + if test -n "${final_path:-}"; then + ynh_replace_string "__FINALPATH__" "$final_path" "$finalsystemdconf" + fi + if test -n "${app:-}"; then + ynh_replace_string "__APP__" "$app" "$finalsystemdconf" + fi + ynh_store_checksum_config "$finalsystemdconf" + + sudo chown root: "$finalsystemdconf" + sudo systemctl enable $app + sudo systemctl daemon-reload +} + +# Remove the dedicated systemd config +# +# usage: ynh_remove_systemd_config +ynh_remove_systemd_config () { + finalsystemdconf="/etc/systemd/system/$app.service" + if [ -e "$finalsystemdconf" ]; then + sudo systemctl stop $app + sudo systemctl disable $app + ynh_secure_remove "$finalsystemdconf" + fi +} diff --git a/scripts/install b/scripts/install new file mode 100644 index 0000000..8cd7863 --- /dev/null +++ b/scripts/install @@ -0,0 +1,162 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= + +domain=$YNH_APP_ARG_DOMAIN +path_url=$YNH_APP_ARG_PATH +admin_username=$YNH_APP_ARG_USERNAME +admin_email=$YNH_APP_ARG_EMAIL +admin_password=$YNH_APP_ARG_PASSWORD +is_public=$YNH_APP_ARG_IS_PUBLIC + + + +# This is a multi-instance app, meaning it can be installed several times independently +# The id of the app as stated in the manifest is available as $YNH_APP_ID +# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) +# The app instance name is available as $YNH_APP_INSTANCE_NAME +# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample +# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 +# - ynhexample__{N} for the subsequeadmin_email=$YNH_APP_ARG_EMAILnt installations, with N=3,4, ... +# The app instance name is probably what you are interested the most, since this is +# guaranteed to be unique. This is a good unique identifier to define installation path, +# db names, ... +app=$YNH_APP_INSTANCE_NAME + +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS +#================================================= + +# Normalize the url path syntax +path_url=$(ynh_normalize_url_path $path_url) + +# Check web path availability +ynh_webpath_available $domain $path_url +# Register (book) web path +ynh_webpath_register $app $domain $path_url + +final_path=/var/www/$app +test ! -e "$final_path" || ynh_die "This path already contains a folder" + +# Check password strength +[[ ${#admin_password} -gt 6 ]] || ynh_die \ +"The password is too weak, it must be longer than 6 characters" + +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= + +ynh_app_setting_set $app domain $domain +ynh_app_setting_set $app path $path_url +ynh_app_setting_set $app is_public $is_public + + + +#================================================= +# STANDARD MODIFICATIONS +#================================================= +#================================================= +# CREATE A MYSQL DATABASE +#================================================= +# If your app uses a MySQL database, you can use these lines to bootstrap +# a database, an associated user and save the password in app settings + +db_name=$(ynh_sanitize_dbid $app) +ynh_app_setting_set $app db_name $db_name +ynh_mysql_setup_db $db_name $db_name + + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +ynh_app_setting_set $app final_path $final_path +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source "$final_path" + + +#================================================= +# NGINX CONFIGURATION +#================================================= + +# Create a dedicated nginx config +ynh_add_nginx_config + + +#================================================= +# SPECIFIC SETUP +#================================================= +#================================================= +# COPYING THE CUSTOM INSTALL SCRIPT AND INPUTING THE ARGUMENTS +#================================================= +sudo cp -a ../conf/install.php $final_path/cli/. +php $final_path/cli/install.php \ +--db-user=$db_name \ +--db-name=$db_name \ +--db-pass=$db_pwd \ +--admin-user=$admin_username \ +--admin-pass=$admin_password \ +--admin-email=$admin_email + + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +# Remove the installation folder in the root folder(required by joomla after install) +sudo rm -R $final_path/installation + +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +# Set permissions to app files (requires 774 for folder permissions) +#**********NEEDED TO BE CHECKED********* +sudo find $final_path -type f | xargs chmod 774 +sudo find $final_path -type d | xargs chmod 774 + +#Give root folder www-data ownership +sudo chown -R www-data: $final_path + + +#================================================= +# SETUP SSOWAT +#================================================= + +if [ $is_public -eq 0 ] +then # Remove the public access + ynh_app_setting_delete $app skipped_uris +fi +# Make app public if necessary +if [ $is_public -eq 1 ] +then + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set $app unprotected_uris "/" +fi + + +#================================================= +# RELOAD NGINX +#================================================= + +sudo systemctl reload nginx diff --git a/scripts/remove b/scripts/remove new file mode 100644 index 0000000..c8dbd8f --- /dev/null +++ b/scripts/remove @@ -0,0 +1,45 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +domain=$(ynh_app_setting_get $app domain) + +db_name=$(ynh_app_setting_get $app db_name) + +#================================================= +# STANDARD REMOVE +#================================================= + +#================================================= +# REMOVE THE MYSQL DATABASE +#================================================= + +# Remove a database if it exists, along with the associated user +ynh_mysql_remove_db $db_name $db_name + +#================================================= +# REMOVE APP MAIN DIR +#================================================= + +# Remove the app directory securely +ynh_secure_remove "/var/www/$app" + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= + +# Remove the dedicated nginx config +ynh_remove_nginx_config diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100644 index 0000000..766176f --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,77 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +domain=$(ynh_app_setting_get $app domain) +path_url=$(ynh_app_setting_get $app path) +is_public=$(ynh_app_setting_get $app is_public) +final_path=$(ynh_app_setting_get $app final_path) +db_name=$(ynh_app_setting_get $app db_name) + +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= + +if [ "$is_public" = "Yes" ]; then + ynh_app_setting_set $app is_public 1 # Fix is_public as a boolean value + is_public=1 +elif [ "$is_public" = "No" ]; then + ynh_app_setting_set $app is_public 0 + is_public=0 +fi + +if [ -z $db_name ]; then # If db_name doesn't exist, create it + db_name=$(ynh_sanitize_dbid $app) + ynh_app_setting_set $app db_name $db_name +fi + +#================================================= +# CHECK THE PATH +#================================================= + +# Normalize the URL path syntax +path_url=$(ynh_normalize_url_path $path_url) + + +#================================================= +# NGINX CONFIGURATION +#================================================= + +# Create a dedicated nginx config +ynh_add_nginx_config + + + +#================================================= +# SETUP SSOWAT +#================================================= + +if [ $is_public -eq 0 ] +then # Remove the public access + ynh_app_setting_delete $app skipped_uris +fi +# Make app public if necessary +if [ $is_public -eq 1 ] +then + # unprotected_uris allows SSO credentials to be passed anyway + ynh_app_setting_set $app unprotected_uris "/" +fi + +#================================================= +# RELOAD NGINX +#================================================= + +sudo systemctl reload nginx