commit aa0ea266a41b6ed199b15909fd787db5b7cd590e Author: Llewellyn van der Merwe Date: Tue Jun 8 08:20:21 2021 +0200 Initial commit of OctoJpack diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + 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 your +freedom 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. + + GNU GENERAL PUBLIC LICENSE + 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. + + + Copyright (C) + + 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. + + , 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 new file mode 100644 index 0000000..230eaca --- /dev/null +++ b/README.md @@ -0,0 +1,133 @@ +# Octojpack - Easy Joomla Extension Packaging + +With this script we can easily package multiple extensions in an automated way from a json configuration file, and environment variables. + +> program only for ubuntu/debian and Gitea systems at this time (should you like to use it on other OS's please open and issue...) +--- +# Install +```shell +$ sudo curl -L "https://git.vdm.dev/api/v1/repos/octoleo/octojpack/raw/src/octojpack" -o /usr/local/bin/octojpack +$ sudo chmod +x /usr/local/bin/octojpack +``` +--- +# Usage +> To see the help menu +```shell +$ octojpack -h +``` +--- +## Help Menu (octojpack) +```txt +Usage: octojpack [OPTION...] + Options + ====================================================== + -p | --packager= + Packager name + example: octojpack -p="Vast Development Method" + ====================================================== + -pu | --packager-url= + Packager url + example: octojpack -pu="https://git.vdm.dev/" + ====================================================== + -e | --env= + load the environment variables file + example: octojpack --env=/src/.env + ====================================================== + --conf | --config= + load the configuration for the package in json format + file-example: src/example.json + example: octojpack --config=config.json + ====================================================== + -t | --token= + load the global token + example: octojpack --token=xxxxxxxxxxxxxxxxxxxxxxxxx + ====================================================== + -u | --url= + Global url of the Gitea instance + example: octojpack --url="git.vdm.dev" + ====================================================== + -a | --api= + Global api of the Gitea instance + example: octojpack --api="https://git.vdm.dev/api/v1" + ====================================================== + -q | --quiet + mute all output messages + example: octojpack --quiet + ====================================================== + --update + to update your install + example: octojpack --update + ====================================================== + --uninstall + to uninstall this script + example: octojpack --uninstall + ====================================================== + -h|--help + display this help menu + example: octojpack -h + example: octojpack --help + ====================================================== + Octojpack v1.0 + ====================================================== +``` + +### Local Environment Variables File + +Give the path to your .env file to the program like this: +```shell +$ octojpack --env="/home/username/.config/octojpack/custom.env" +``` +Or with an environment variable you set before using the program like this: +```shell +$ export VDM_ENV_FILE_PATH="/home/username/.config/octojpack/custom.env" +``` + +> Default path is: /home/$USER/.config/octojpack/.env + +### API ACCESS TOKEN (never share your token) + +You can set your API access token for Gitea via the .env file like this: +```shell +VDM_GLOBAL_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxx" +``` +Or you can pass the token directly to the script like this: +```shell +$ octojpack --token="xxxxxxxxxxxxxxxxxxxxxxxxx" +``` +Or with an environment variable you set before using the program like this: +```shell +$ export VDM_GLOBAL_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxx" +``` + +### Configuration File + +To see the example of the json configuration options check out [src/example.json](https://git.vdm.dev/octoleo/octojpack/src/branch/master/src/example.json). + +You can set your configuration file path via the .env file like this: +```shell +VDM_PACKAGE_CONF_FILE="/home/username/.config/octojpack/package_name_config.json" +``` +Or you can pass it to the program by URL: +```shell +$ octojpack --conf="https://git.vdm.dev/api/v1/repos/octoleo/octojpack/raw/src/example.json" +``` +Or via a local file path: +```shell +$ octojpack --conf="/home/username/.config/octojpack/package_name_config.json" +``` +Or with an environment variable you set before using the program like this: +```shell +$ export VDM_PACKAGE_CONF_FILE="/home/username/.config/octojpack/package_name_config.json" +``` + +--- +## Uninstall +```shell +$ octojpack --uninstall +``` +--- +# Free Software License +```txt +@copyright Copyright (C) 2021 Llewellyn van der Merwe. All rights reserved. +@license GNU General Public License version 2; see LICENSE +``` \ No newline at end of file diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..46c7786 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,4 @@ +conf.json +packager +licenses +.env \ No newline at end of file diff --git a/src/example.json b/src/example.json new file mode 100644 index 0000000..431cbe7 --- /dev/null +++ b/src/example.json @@ -0,0 +1,197 @@ +{ + "global": { + "packager": "Vast Development Method", + "packager_url": "https://dev.vdm.io/", + "url": "git.vdm.dev", + "api": "https://git.vdm.dev/api/v1" + }, + "package": { + "name": "PKG_COMPONENT_BUILDER_PRO", + "code_name": "component_builder_pro", + "package_name": "pkg_component_builder_pro", + "min_joomla_version": "3.8", + "max_joomla_version": "3.10", + "copyright": "Copyright (C) 2015 Llewellyn van der Merwe. All rights reserved.", + "copyright_year": "2015", + "license": "GNU General Public License version 2; see LICENSE", + "license_file": "LICENSE", + "author": "Llewellyn van der Merwe", + "author_email": "joomla@vdm.io", + "author_url": "https://io.vdm.dev", + "description": "The Joomla Component Builder Package (PRO) that bundles JCB Pro Component all the plugins and features available to Pro Members into one package for easy install and update of your JCB system.", + "update_servers": "https://io.vdm.dev/update/componentbuilder_update_server.xml", + "version_id": "com_componentbuilder" + }, + "repository": { + "owner": "joomla", + "repo": "pkg-component-builder-pro" + }, + "files": [ + { + "owner": "joomla", + "repo": "Component-Builder-Pro", + "id": "com_componentbuilder", + "type": "component", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + }, + { + "owner": "joomla", + "repo": "plg_installer_componentbuilder", + "id": "ComponentBuilder", + "type": "plugin", + "group": "installer", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + }, + { + "owner": "joomla", + "repo": "plg_content_componentbuilderadminheaderstabs", + "id": "ComponentBuilderAdminHeadersTabs", + "type": "plugin", + "group": "content", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + }, + { + "owner": "joomla", + "repo": "plg_content_componentbuildercomponentdashboardheaderstabs", + "id": "ComponentBuilderComponentDashboardHeadersTabs", + "type": "plugin", + "group": "content", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + }, + { + "owner": "joomla", + "repo": "plg_content_componentbuildercomponentheaderstabs", + "id": "ComponentBuilderComponentHeadersTabs", + "type": "plugin", + "group": "content", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + }, + { + "owner": "joomla", + "repo": "plg_content_componentbuildercustomadminheaderstabs", + "id": "ComponentBuilderCustomAdminHeadersTabs", + "type": "plugin", + "group": "content", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + }, + { + "owner": "joomla", + "repo": "plg_content_componentbuilderfieldorderingtabs", + "id": "ComponentBuilderFieldOrderingTabs", + "type": "plugin", + "group": "content", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + }, + { + "owner": "joomla", + "repo": "plg_content_componentbuilderlanguagetabs", + "id": "ComponentBuilderLanguageTabs", + "type": "plugin", + "group": "content", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + }, + { + "owner": "joomla", + "repo": "plg_content_componentbuilderprivacytabs", + "id": "ComponentBuilderPrivacyTabs", + "type": "plugin", + "group": "content", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + }, + { + "owner": "joomla", + "repo": "plg_content_componentbuildersiteheaderstabs", + "id": "ComponentBuilderSiteHeadersTabs", + "type": "plugin", + "group": "content", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + }, + { + "owner": "joomla", + "repo": "plg_extension_componentbuilderactionlogcompiler", + "id": "ComponentBuilderActionLogCompiler", + "type": "plugin", + "group": "extension", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + }, + { + "owner": "joomla", + "repo": "plg_extension_componentbuilderexportcompiler", + "id": "ComponentBuilderExportCompiler", + "type": "plugin", + "group": "extension", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + }, + { + "owner": "joomla", + "repo": "plg_extension_componentbuilderfieldorderingcompiler", + "id": "ComponentBuilderFieldOrderingCompiler", + "type": "plugin", + "group": "extension", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + }, + { + "owner": "joomla", + "repo": "plg_extension_componentbuilderheaderscompiler", + "id": "ComponentBuilderHeadersCompiler", + "type": "plugin", + "group": "extension", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + }, + { + "owner": "joomla", + "repo": "plg_extension_componentbuilderlanguagepackaging", + "id": "ComponentBuilderLanguagePackaging", + "type": "plugin", + "group": "extension", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + }, + { + "owner": "joomla", + "repo": "plg_extension_componentbuilderpowersautoloadercompiler", + "id": "ComponentBuilderPowersAutoloaderCompiler", + "type": "plugin", + "group": "extension", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + }, + { + "owner": "joomla", + "repo": "plg_extension_componentbuilderprivacycompiler", + "id": "ComponentBuilderPrivacyCompiler", + "type": "plugin", + "group": "extension", + "token_name": "VDM_GLOBAL_TOKEN", + "api_name": "VDM_GLOBAL_API" + } + ], + "languages": [ + { + "tag": "en-GB", + "ini": "sys.ini", + "key": "PKG_COMPONENT_BUILDER_PRO", + "value": "Component Builder Pro Package" + }, + { + "tag": "en-GB", + "ini": "ini", + "key": "PKG_COMPONENT_BUILDER_PRO", + "value": "Component Builder Pro Package" + } + ] +} \ No newline at end of file diff --git a/src/octojpack b/src/octojpack new file mode 100755 index 0000000..dbe5b9b --- /dev/null +++ b/src/octojpack @@ -0,0 +1,1230 @@ +#! /bin/bash + +# Program name +PROGRAM_NAME="Octojpack" +PROGRAM_CODE="octojpack" +PROGRAM_VERSION="1.0.0" +PROGRAM_V="1.0" +PROGRAM_URL="https://git.vdm.dev/octoleo/${PROGRAM_CODE}" + +# Do some prep work +command -v git >/dev/null 2>&1 || { + echo >&2 "[error] We require git for $PROGRAM_NAME v${PROGRAM_V} to work, but it's not installed. Aborting." + exit 1 +} +command -v curl >/dev/null 2>&1 || { + echo >&2 "[error] We require curl for $PROGRAM_NAME v${PROGRAM_V} to work, but it's not installed. Aborting." + exit 1 +} +command -v jq >/dev/null 2>&1 || { + echo >&2 "[error] We require jq for $PROGRAM_NAME v${PROGRAM_V} to work, but it's not installed. Aborting." + exit 1 +} + +# main function ˘Ô≈ôﺣ +function main() { + # get the package details + # shellcheck disable=SC2015 + [ -f "$VDM_PACKAGE_CONF_FILE" ] && getPackageDetails || { + echo >&2 "[error] We require config file with correct packaging details for $PROGRAM_NAME v${PROGRAM_V} to work, but it's not found in/at $VDM_PACKAGE_CONF_FILE. Aborting." + clearMainEnv + exit 1 + } + # get destination details + getRepositoryDetails || { + echo >&2 "[error] We require config file with correct destination repository details for $PROGRAM_NAME v${PROGRAM_V} to work, but it's not found in/at $VDM_PACKAGE_CONF_FILE. Aborting." + clearMainEnv + exit 1 + } + # build the project package path + setPackageDir || { + echo >&2 "[error] We could not set the package directories for ${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}. Aborting." + clearMainEnv + exit 1 + } + # set the files + setFiles || { + echo >&2 "[error] We could not find any files for ${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO} package. Aborting." + clearMainEnv + exit 1 + } + # set languages + setLanguages + # set the package XML + setPackageXml + # set the readme + setReadMe + # set the licence file + setLicenseFile || { + echo >&2 "[error] We could not set the LICENSE for ${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}. Aborting." + clearMainEnv + exit 1 + } + # set the installation file + setInstallFile + # get package repository + setRepository || { + echo >&2 "[error] We could not set the GIT repository for ${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}. Aborting." + clearMainEnv + exit 1 + } + # remove all files + clearFiles + # clear main env + clearMainEnv + # final message + _echo "[Success] Package completely updated!" +} + +# set the package details +function getPackageDetails() { + # load the config data + VDM_CONFIG_DATA=$(cat "$VDM_PACKAGE_CONF_FILE") + # make sure we have package details + if [[ "${VDM_CONFIG_DATA}" =~ '"package"' ]] && [[ "${VDM_CONFIG_DATA}" =~ '"files"' ]]; then + # little information of progress + _echo "[info] Loading the Package Details..." + # make configuration globally available + export VDM_CONFIG_DATA + # check for errors + local has_error=false + # get the global config values if not set + getConfigValue 'VDM_PACKAGER' '.global.packager' false || VDM_PACKAGER="${PROGRAM_NAME} v${PROGRAM_V}" + getConfigValue 'VDM_PACKAGER_URL' '.global.packager_url' false || VDM_PACKAGER_URL="${PROGRAM_URL}" + getConfigValue 'VDM_PACKAGER_LANG' '.global.language' false || VDM_PACKAGER_LANG="en-GB" + getConfigValue 'VDM_GLOBAL_TOKEN' '.global.token' || has_error=true + getConfigValue 'VDM_GLOBAL_API' '.global.api' || has_error=true + getConfigValue 'VDM_GLOBAL_URL' '.global.url' || has_error=true + # check if we have some errors already + $has_error && return 13 + + # package related details + getConfigValue 'VDM_PACKAGE_NAME' '.package.package_name' || has_error=true + getConfigValue 'VDM_CODE_NAME' '.package.code_name' || has_error=true + getConfigValue 'VDM_PACKAGE_VERSION_ID' '.package.version_id' false + getConfigValue 'VDM_NAME' '.package.name' || has_error=true + getConfigValue 'VDM_DESCRIPTION' '.package.description' || has_error=true + getConfigValue 'VDM_MIN_JOOMLA_VERSION' '.package.min_joomla_version' false || VDM_MIN_JOOMLA_VERSION="3.8" + getConfigValue 'VDM_MAX_JOOMLA_VERSION' '.package.max_joomla_version' false || unset VDM_MAX_JOOMLA_VERSION + getConfigValue 'VDM_COPYRIGHT' '.package.copyright' || has_error=true + getConfigValue 'VDM_COPYRIGHT_YEAR' '.package.copyright_year' || has_error=true + getConfigValue 'VDM_LICENSE' '.package.license' || has_error=true + getConfigValue 'VDM_LICENSE_FILE' '.package.license_file' || has_error=true + getConfigValue 'VDM_INSTALLATION_FILE' '.package.installation_file' false || unset VDM_INSTALLATION_FILE + getConfigValue 'VDM_AUTHOR' '.package.author' || has_error=true + getConfigValue 'VDM_AUTHOR_EMAIL' '.package.author_email' || has_error=true + getConfigValue 'VDM_AUTHOR_URL' '.package.author_url' || has_error=true + getConfigValue 'VDM_UPDATE_SERVER' '.package.update_servers' || has_error=true + # check if we have some errors already + $has_error && return 13 + + # success + return 0 + else + # failed + return 17 + fi +} + +# set the target repository details +function getRepositoryDetails() { + # make sure we have package details + if [[ "${VDM_CONFIG_DATA}" =~ '"repository"' ]]; then + # little information of progress + _echo "[info] Loading the Repository Details..." + # check for errors + local has_error=false + # get the global config values if not set + getConfigValue 'VDM_PACKAGE_OWNER' '.repository.owner' || has_error=true + getConfigValue 'VDM_PACKAGE_REPO' '.repository.repo' || has_error=true + getConfigValue 'VDM_PACKAGE_TOKEN_NAME' '.repository.token_name' false || VDM_PACKAGE_TOKEN_NAME="VDM_GLOBAL_TOKEN" + getConfigValue 'VDM_PACKAGE_URL_NAME' '.repository.url_name' false || VDM_PACKAGE_URL_NAME="VDM_GLOBAL_URL" + getConfigValue 'VDM_PACKAGE_API_NAME' '.repository.api_name' false || VDM_PACKAGE_API_NAME="VDM_GLOBAL_API" + # check if we have some errors already + $has_error && return + # set the package (api/url/toke) + VDM_PACKAGE_TOKEN=${!VDM_PACKAGE_TOKEN_NAME} + VDM_PACKAGE_URL=${!VDM_PACKAGE_URL_NAME} + VDM_PACKAGE_API=${!VDM_PACKAGE_API_NAME} + # make globally available + export VDM_PACKAGE_TOKEN + export VDM_PACKAGE_URL + export VDM_PACKAGE_API + # success + return 0 + else + # failed + return 17 + fi +} + +# clear the main environment variables +function clearMainEnv() { + # clear all exported package details + # SET IN: getRepositoryDetails + unset VDM_PACKAGE_OWNER + unset VDM_PACKAGE_REPO + unset VDM_PACKAGE_TOKEN_NAME + unset VDM_PACKAGE_TOKEN + unset VDM_PACKAGE_API_NAME + unset VDM_PACKAGE_API + unset VDM_PACKAGE_URL_NAME + unset VDM_PACKAGE_URL + # SET IN: setPackageDir + unset VDM_PACKAGE_DIR + unset VDM_PACKAGE_GIT_DIR + unset VDM_PACKAGE_SRC_DIR + unset VDM_PACKAGE_LANG_DIR + unset VDM_PACKAGE_XML + unset VDM_FILES_XML + unset VDM_LANGUAGES_XML + unset VDM_README_MD + unset VDM_INSTALL_PHP + # SET IN: getPackageDetails + unset VDM_CONFIG_DATA + unset VDM_PACKAGER + unset VDM_PACKAGER_URL + unset VDM_GLOBAL_TOKEN + unset VDM_GLOBAL_API + unset VDM_PACKAGE_NAME + unset VDM_CODE_NAME + unset VDM_PACKAGE_VERSION + unset VDM_PACKAGE_VERSION_ID + unset VDM_NAME + unset VDM_DESCRIPTION + unset VDM_MIN_JOOMLA_VERSION + unset VDM_MAX_JOOMLA_VERSION + unset VDM_COPYRIGHT + unset VDM_COPYRIGHT_YEAR + unset VDM_LICENSE + unset VDM_LICENSE_FILE + unset VDM_LICENSE_FILE_PATH + unset VDM_INSTALLATION_FILE + unset VDM_AUTHOR + unset VDM_AUTHOR_EMAIL + unset VDM_AUTHOR_URL + unset VDM_UPDATE_SERVER + # SET IN: callGiteaAPI + unset VDM_API_BUCKET +} + +# clear all this projects files +function clearFiles() { + # always remove files + rm -fr "${VDM_PACKAGE_DIR:?}" + rm -fr "${VDM_PACKAGE_GIT_DIR:?}/${VDM_PACKAGE_REPO:?}" +} + +# get value from config +function getConfigValue() { + # get what we can from the config if not already set in the .env file + # so to set the value globally use the .env option + # to set per project use the config file of the project + # some local values + local value_key + # load the values + value_key="${2}" + # if has a value we are done + [ -n "${!1}" ] && return 0 + # get the value + # shellcheck disable=SC2034 + val=$(echo "${VDM_CONFIG_DATA}" | jq -r "$value_key") + # check the value not to be null + [ "${val}" = 'null' ] && { + # give little heads-up if not blocked + "${3:-true}" && echo >&2 "[error] We require ($value_key) for $PROGRAM_NAME v${PROGRAM_V} to work, but it's not found in $VDM_PACKAGE_CONF_FILE." + # we had no success + return 19 + } + # set the dynamic variable $1=(MUST BE VALID VARIABLE NAME) + eval "$1"=\"\$val\" + return 0 +} + +# set the Package Path +function setPackageDir() { + # little information of progress + _echo "[info] Setting the Package Directories..." + # the full project path + VDM_PACKAGE_DIR="${PACKAGE_DIR}/${VDM_PACKAGE_REPO}" + VDM_PACKAGE_GIT_DIR="${PACKAGE_DIR}/git" + VDM_PACKAGE_SRC_DIR="${VDM_PACKAGE_DIR}/src" + # always remove previous files (if found) + rm -fr "${VDM_PACKAGE_DIR:?}" + rm -fr "${VDM_PACKAGE_GIT_DIR:?}/${VDM_PACKAGE_REPO:?}" + # set the package language folder + VDM_PACKAGE_LANG_DIR="${VDM_PACKAGE_DIR}/languages" + # set the package xml + VDM_PACKAGE_XML="${VDM_PACKAGE_DIR}/${VDM_PACKAGE_NAME,,}.xml" + # set the files xml + VDM_FILES_XML="${PACKAGE_DIR}/files.xml" + # set the languages xml + VDM_LANGUAGES_XML="${PACKAGE_DIR}/languages.xml" + # set the extensions list of files + VDM_README_FILES_MD="${PACKAGE_DIR}/README_FILES.md" + # set the README + VDM_README_MD="${VDM_PACKAGE_DIR}/README.md" + # set the license file + VDM_LICENSE_FILE_PATH="${VDM_PACKAGE_DIR}/LICENSE" + # set the package install script + VDM_INSTALL_PHP="${VDM_PACKAGE_DIR}/install_${VDM_CODE_NAME,,}.php" + # makes the project path available + export VDM_PACKAGE_DIR + export VDM_PACKAGE_GIT_DIR + export VDM_PACKAGE_SRC_DIR + export VDM_PACKAGE_LANG_DIR + # makes the project file locations available + export VDM_PACKAGE_XML + export VDM_FILES_XML + export VDM_LANGUAGES_XML + export VDM_README_MD + export VDM_INSTALL_PHP + export VDM_LICENSE_FILE_PATH + # make sure the packages dir is created + mkdir -p "${VDM_PACKAGE_DIR}" || return 12 + #make sure the src dir is created + mkdir -p "${VDM_PACKAGE_SRC_DIR}" || return 12 + #make sure the languages dir is created + mkdir -p "${VDM_PACKAGE_LANG_DIR}" || return 12 + #make sure the git dir is created + mkdir -p "${VDM_PACKAGE_GIT_DIR}" || return 12 + # success + return 0 +} + +# set the Files +function setFiles() { + # little information of progress + _echo "[info] Loading the Files..." + # make sure its reset + echo -e '\t' > "${VDM_FILES_XML}" + echo "" > "${VDM_README_FILES_MD}" + # check for errors + local has_error=false + local has_files=false + # loop over the repos + i=0 + for owner in $(echo "${VDM_CONFIG_DATA}" | jq -r '.files[].owner'); + do + # get the config values needed + # shellcheck disable=SC2015 + [ -n "${owner}" ] && VDM_OWNER="${owner}" || continue + # check for errors + has_error=false + # get the global config values if not set + getConfigValue 'VDM_REPO' ".files[$i].repo" || has_error=true + getConfigValue 'VDM_TYPE' ".files[$i].type" || has_error=true + getConfigValue 'VDM_ID' ".files[$i].id" || has_error=true + getConfigValue 'VDM_ENABLED' ".files[$i].enabled" false || VDM_ENABLED=1 + # check if we have some errors already + if $has_error; then + clearFileEnv + continue + fi + getConfigValue 'VDM_TOKEN_NAME' ".files[$i].token_name" false || VDM_TOKEN_NAME="VDM_GLOBAL_TOKEN" + getConfigValue 'VDM_API_NAME' ".files[$i].api_name" false || VDM_API_NAME="VDM_GLOBAL_API" + getConfigValue 'VDM_URL_NAME' ".files[$i].url_name" false || VDM_URL_NAME="VDM_GLOBAL_URL" + getConfigValue 'VDM_MODE' ".files[$i].mode" false || VDM_MODE='tags' + # set additional + VDM_GROUP='' + VDM_CLIENT='' + VDM_TYPE_KEY='' + VDM_TYPE_VAL='' + if [ "$VDM_TYPE" = 'plugin' ]; then + # set the plugin group + getConfigValue 'VDM_GROUP' ".files[$i].group" || has_error=true + # set the key + VDM_TYPE_KEY="group" + VDM_TYPE_VAL="${VDM_GROUP}" + elif [ "$VDM_TYPE" = 'module' ] || [ "$VDM_TYPE" = 'template' ]; then + # set module & template client + getConfigValue 'VDM_CLIENT' ".files[$i].client" || has_error=true + # set the key + VDM_TYPE_KEY="client" + VDM_TYPE_VAL="${VDM_CLIENT}" + fi + # check if we have some errors already + if $has_error; then + clearFileEnv + continue + fi + # set the URL + VDM_URL=${!VDM_URL_NAME} + # set the API + VDM_API=${!VDM_API_NAME} + # set the token + VDM_TOKEN=${!VDM_TOKEN_NAME} + # export these values + export VDM_OWNER + export VDM_MODE + export VDM_ENABLED + export VDM_TYPE_KEY + export VDM_TYPE_VAL + export VDM_TOKEN + export VDM_API + export VDM_URL + # get this zip packages + if getZipFile; then + # set the xml details for this package + setFile + # check if this is the package version ID + if [ -n "${VDM_PACKAGE_VERSION_ID}" ] && + [ -z "${VDM_PACKAGE_VERSION}" ] && + [ "${VDM_PACKAGE_VERSION_ID}" = "${VDM_ID}" ] ; then + # set the package version + VDM_PACKAGE_VERSION="${VDM_ZIP_NAME}"; + export VDM_PACKAGE_VERSION + fi + # we have a file + has_files=true + fi + # increment + ((i++)) + # clear env + clearFileEnv + done + # make sure to close the files + echo -e '\t' >> "${VDM_FILES_XML}" + # check if we found a file + $has_files || return 13 + # success + return 0 +} + +# just to clear all file ENVs +function clearFileEnv() { + # SET IN: setFiles + unset VDM_OWNER + unset VDM_REPO + unset VDM_TYPE + unset VDM_ID + unset VDM_GROUP + unset VDM_CLIENT + unset VDM_TYPE_KEY + unset VDM_TYPE_VAL + unset VDM_TOKEN_NAME + unset VDM_TOKEN + unset VDM_API_NAME + unset VDM_API + unset VDM_URL_NAME + unset VDM_URL + unset VDM_MODE + # SET IN: getZipFile + unset VDM_ZIP_NAME + unset VDM_ZIP_MESSAGE +} + +# get the repository zip package +function getZipFile() { + # reset the zip details + VDM_ZIP_NAME='' + VDM_ZIP_MESSAGE='' + # check the mode + if [ "${VDM_MODE}" = 'tags' ] || [ "${VDM_MODE}" = 'releases' ]; then + # make API call + callGiteaAPI "${VDM_MODE}" "${VDM_OWNER}" "${VDM_REPO}" "${VDM_API}" "${VDM_TOKEN}" || return 11 + # get the name + if [ -n "${VDM_API_BUCKET}" ]; then + VDM_ZIP_NAME=$(echo "${VDM_API_BUCKET}" | jq -r ".name") + else + return 11 + fi + # get the message + if [ -n "${VDM_API_BUCKET}" ]; then + VDM_ZIP_MESSAGE=$(echo "${VDM_API_BUCKET}" | jq -r ".message") + else + return 11 + fi + # download the zip file if not already set + if [ ! -f "${VDM_PACKAGE_SRC_DIR}/${VDM_OWNER}__${VDM_REPO}__${VDM_ZIP_NAME}.zip" ]; then + # give message + _echo "[info] Downloading the (${VDM_OWNER}-${VDM_REPO}-${VDM_ZIP_NAME}.zip) package." + curl -s -L "${VDM_API}/repos/${VDM_OWNER}/${VDM_REPO}/archive/${VDM_ZIP_NAME}.zip?access_token=${VDM_TOKEN}" -o "${VDM_PACKAGE_SRC_DIR}/${VDM_OWNER}__${VDM_REPO}__${VDM_ZIP_NAME}.zip" + else + # zip already set + _echo "[error] ${VDM_OWNER}__${VDM_REPO}__${VDM_ZIP_NAME}.zip already set." + return 12 + fi + else + # get the name + VDM_ZIP_NAME="${VDM_MODE}" + # get the message + VDM_ZIP_MESSAGE="${VDM_MODE}" + # download the zip file if not already set + if [ ! -f "${VDM_PACKAGE_SRC_DIR}/${VDM_OWNER}__${VDM_REPO}__${VDM_ZIP_NAME}.zip" ]; then + # give message + _echo "[info] Downloading the (${VDM_OWNER}-${VDM_REPO}-${VDM_ZIP_NAME}.zip) package." + # download the zip file + curl -s -L "${VDM_API}/repos/${VDM_OWNER}/${VDM_REPO}/archive/${VDM_ZIP_NAME}.zip?access_token=${VDM_TOKEN}" -o "${VDM_PACKAGE_SRC_DIR}/${VDM_OWNER}__${VDM_REPO}__${VDM_ZIP_NAME}.zip" + else + # zip already set + _echo "[error] ${VDM_OWNER}__${VDM_REPO}__${VDM_ZIP_NAME}.zip already set." + return 12 + fi + fi + # always clear tab bucket + unset VDM_API_BUCKET + # move the tag values to global scope + export VDM_ZIP_NAME + export VDM_ZIP_MESSAGE + # success + return 0 +} + +# set the File Details +function setFile() { + # add the file xml details + { + echo -en '\t\t${VDM_OWNER}__${VDM_REPO}__${VDM_ZIP_NAME}.zip" + } >> "${VDM_FILES_XML}" + # set the readme list of extensions + { + echo -n "- [${VDM_OWNER}/${VDM_REPO}]" + echo -n "(https://${VDM_URL}/${VDM_OWNER}/${VDM_REPO})" + echo " [${VDM_ZIP_NAME}](https://${VDM_URL}/${VDM_OWNER}/${VDM_REPO}/archive/${VDM_ZIP_NAME}.zip)" + echo "> ${VDM_ZIP_MESSAGE}" + } >> "${VDM_README_FILES_MD}" +} + +# make API call +function callGiteaAPI() { + # the locals + local mode="${1}" + local owner="${2}" + local repo="${3}" + local api="${4}" + local token="${5}" + local zip_packages + local message + # each time reset + unset VDM_API_BUCKET + # give message + _echo "[info] Getting ${mode} information from ${owner}/${repo} repository." + # get the zip packages + zip_packages=$(curl -s -X 'GET' "${api}/repos/${owner}/${repo}/${mode}?access_token=${token}" -H 'accept: application/json') + # check for error + if [[ "${zip_packages}" =~ '"errors"' ]] && [[ "${zip_packages}" =~ '"message"' ]]; then + # get the message + message=$(echo "${zip_packages}" | jq -r ".message") + # check that we have tags (not ideal, but to catch wrong repo path) + _echo "[error] failed to get ${mode} from ${owner}/${repo} repository [${message}]." + # we an add more later + return 12 + elif [ "${zip_packages}" = '[]' ]; then + # check that we have tags (not ideal, but to catch wrong repo path) + _echo "[error] failed to get ${mode} from ${owner}/${repo} repository." + # we an add more later + return 12 + fi + # get the latest + VDM_API_BUCKET=$(echo "${zip_packages}" | jq ".[0]") + # success + export VDM_API_BUCKET + # success + return 0 +} + +# set the package language file and xml +function setLanguages() { + # little information of progress + _echo "[info] Loading the Languages..." + # make sure its reset + echo -e '\t' > "${VDM_LANGUAGES_XML}" + # check for errors + local has_error + # loop over the repos + i=0 + for vdm_lang_tag in $(echo "${VDM_CONFIG_DATA}" | jq -r '.languages[].tag'); + do + # check for errors + has_error=false + # get the config values needed + getConfigValue 'vdm_lang_ini' ".languages[$i].ini" || has_error=true + getConfigValue 'vdm_lang_key' ".languages[$i].key" || has_error=true + getConfigValue 'vdm_lang_value' ".languages[$i].value" || has_error=true + # check if we have some errors already + if $has_error; then + clearLangEnv + continue + fi + # set file name + # shellcheck disable=SC2154 + language_file_name="${vdm_lang_tag}.${VDM_PACKAGE_NAME,,}.${vdm_lang_ini}" + # set file path + language_file_path="${VDM_PACKAGE_LANG_DIR}/${vdm_lang_tag}/${language_file_name}" + # build the language string + # shellcheck disable=SC2154 + language_string="${vdm_lang_key}=" + language_string+='"' + # shellcheck disable=SC2154 + language_string+="${vdm_lang_value}" + language_string+='"' + # create dir for language and add to xml only once + if [ ! -d "${VDM_PACKAGE_LANG_DIR}/${vdm_lang_tag}" ]; then + # create the language directory + mkdir -p "${VDM_PACKAGE_LANG_DIR}/${vdm_lang_tag}" + fi + # add value to language file + if [ -f "${language_file_path}" ]; then + echo "${language_string}" >> "${language_file_path}" + else + # first time + echo "${language_string}" > "${language_file_path}" + # add to xml + setLanguageXml "${vdm_lang_tag}" "${vdm_lang_tag}/${language_file_name}" + fi + # increment + ((i++)) + # load the Project name to Readme when found + # shellcheck disable=SC1090 + [ "${vdm_lang_tag}" = "${VDM_PACKAGER_LANG}" ] && source "${language_file_path}" + # remove values + clearLangEnv + done + # make sure its reset + echo -e '\t' >> "${VDM_LANGUAGES_XML}" +} + +# just to clear all file ENVs +function clearLangEnv() { + # SET IN: setLanguages + unset vdm_lang_tag + unset vdm_lang_ini + unset vdm_lang_key + unset vdm_lang_value +} + +# set the Language XML Details +function setLanguageXml() { + # add the file details + { + echo -en '\t\t' + echo -n "${2}" + echo '' + } >> "${VDM_LANGUAGES_XML}" +} + +# set the Package XML Details +function setPackageXml() { + # little information of progress + _echo "[info] Setting the Package XML..." + # add the package details + { + echo '' + echo -n '' + # set the name + echo -en '\t' + echo -n "${VDM_NAME}" + echo '' + # set the package name + echo -en '\t' + echo -n "${VDM_CODE_NAME,,}" + echo '' + # set the version + echo -en '\t' + echo -n "${VDM_PACKAGE_VERSION:-1.0.0}" + echo '' + # set the creationDate + echo -en '\t' + echo -n "${CREATION_DATE}" + echo '' + # set the author + echo -en '\t' + echo -n "${VDM_AUTHOR}" + echo '' + # set the authorEmail + echo -en '\t' + echo -n "${VDM_AUTHOR_EMAIL}" + echo '' + # set the authorUrl + echo -en '\t' + echo -n "${VDM_AUTHOR_URL}" + echo '' + # set the copyright + echo -en '\t' + echo -n "${VDM_COPYRIGHT}" + echo '' + # set the copyrightyear + echo -en '\t' + echo -n "${VDM_COPYRIGHT_YEAR:-$CREATION_YEAR}" + echo '' + # set the license + echo -en '\t' + echo -n "${VDM_LICENSE}" + echo '' + # set the packager + echo -en '\t' + echo -n "${VDM_PACKAGER:-$PROGRAM_NAME}" + echo '' + # set the packagerurl + echo -en '\t' + echo -n "${VDM_PACKAGER_URL:-$PROGRAM_URL}" + echo '' + # set the description + echo -en '\t' + echo -n "${VDM_DESCRIPTION}" + echo '' + # set the script file if found + if [ -n "${VDM_INSTALLATION_FILE}" ]; then + echo -en '\t' + echo -n "install_${VDM_CODE_NAME,,}.php" + echo '' + fi + # set the update server if found + if [ -n "${VDM_UPDATE_SERVER}" ]; then + echo -e '\t' + echo -en '\t\t' + echo -n "${VDM_UPDATE_SERVER}" + echo '' + echo -e '\t' + fi + # add the languages + cat "${VDM_LANGUAGES_XML}" + # add the files + cat "${VDM_FILES_XML}" + # close the extension xml + echo '' + } > "${VDM_PACKAGE_XML}" + # remove file no longer needed + rm "${VDM_LANGUAGES_XML}" + rm "${VDM_FILES_XML}" +} + +# set the package README +function setReadMe() { + # little information of progress + _echo "[info] Setting the README..." + # add the Project Name to Readme + { + [ -n "${!VDM_NAME}" ] && echo -n "# ${!VDM_NAME}" || echo -n "# ${VDM_NAME}" + # add the version + echo " (${VDM_PACKAGE_VERSION:-1.0.0})" + echo "" + # set the Description + reg="[[:space:]]+" + if [[ "${VDM_DESCRIPTION}" =~ $reg ]]; then + echo "${VDM_DESCRIPTION}" + else + [ -n "${!VDM_DESCRIPTION}" ] && echo "${!VDM_DESCRIPTION}" || echo "${VDM_DESCRIPTION}" + fi + echo "" + echo "## Details" + echo "" + echo "- Packager: [${VDM_PACKAGER}](${VDM_PACKAGER_URL})" + echo "- Author: [${VDM_AUTHOR}](${VDM_AUTHOR_URL})" + echo "- Creation Date: ${CREATION_DATE}" + [ -n "${VDM_MAX_JOOMLA_VERSION}" ] && echo "- Max Joomla Version: J${VDM_MAX_JOOMLA_VERSION}" + echo "- Minimum Joomla Version: J${VDM_MIN_JOOMLA_VERSION}" + echo "" + echo "## Extensions" + # add the list of extensions + cat "${VDM_README_FILES_MD}" + echo "" + echo "### Copyright (${VDM_COPYRIGHT_YEAR:-$CREATION_YEAR})" + echo "> ${VDM_COPYRIGHT}" + echo "### License" + echo "> ${VDM_LICENSE}" + echo "" + } > "${VDM_README_MD}" + # remove the Readme files build + rm "${VDM_README_FILES_MD:?}" +} + +# set the license file +function setLicenseFile() { + local has_error=false + # check if the license file is passed via a URL + if [[ "${VDM_LICENSE_FILE}" =~ ^"http:" ]] || [[ "${VDM_LICENSE_FILE}" =~ ^"https:" ]]; then + # shellcheck disable=SC2143 + if [[ $(wget -S --spider "${VDM_LICENSE_FILE}" 2>&1 | grep 'HTTP/1.1 200 OK') ]]; then + wget --quiet "${VDM_LICENSE_FILE}" -O "${VDM_LICENSE_FILE_PATH}" + VDM_LICENSE_FILE="LICENSE" + else + echo >&2 "[error] The license:${VDM_LICENSE_FILE} is not a valid URL." + has_error=true + fi + elif [ -f "${LICENSE_DIR}/${VDM_LICENSE_FILE}" ]; then + # now copy the license file + cp "${LICENSE_DIR}/${VDM_LICENSE_FILE}" "${VDM_LICENSE_FILE_PATH}" + else + echo >&2 "[error] The license:${LICENSE_DIR}/${VDM_LICENSE_FILE} not found." + has_error=true + fi + # check if we have some errors + if $has_error; then + return 16 + fi + # little information of progress + _echo "[info] Setting the License File..." + return 0 +} + +# set the install file +function setInstallFile() { + local has_error=false + # check if the installation script file is passed via a URL + if [[ "${VDM_INSTALLATION_FILE}" =~ ^"http:" ]] || [[ "${VDM_INSTALLATION_FILE}" =~ ^"https:" ]]; then + # shellcheck disable=SC2143 + if [[ $(wget -S --spider "${VDM_INSTALLATION_FILE}" 2>&1 | grep 'HTTP/1.1 200 OK') ]]; then + wget --quiet "${VDM_INSTALLATION_FILE}" -O "${VDM_INSTALL_PHP}" + else + echo >&2 "[error] The installation script file:${VDM_INSTALLATION_FILE} is not a valid URL." + has_error=true + fi + elif [ -f "${VDM_INSTALLATION_FILE}" ]; then + # now copy the installation script file + cp "${VDM_INSTALLATION_FILE}" "${VDM_INSTALL_PHP}" + fi + # check if we have some errors already + if $has_error; then + return 16 + fi + # little information of progress + _echo "[info] Setting the Installation.php File..." + return 0 +} + +# get the package repository +function setRepository() { + # change to git directory + cd "${VDM_PACKAGE_GIT_DIR}" || return 22 + # check if the repository exist on our gitea instance + local update_repo + # shellcheck disable=SC2015 + if git ls-remote "git@${VDM_PACKAGE_URL}:${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}.git" -q >/dev/null 2>&1; then + getExistingRepository || return 23 + update_repo=true + else + setNewRepository || return 24 + update_repo=false + fi + # make sure we are in the correct dir and then remove all existing data + cd "${VDM_PACKAGE_GIT_DIR}/${VDM_PACKAGE_REPO}" || return 25 + # remove any existing files and folders from repository + rm -rf -- * || return 26 + # move all new files into repository + setRepositoryNewFiles || return 27 + # check if we have changes + if $update_repo && [[ -z $(git status --porcelain) ]]; then + _echo "[info] No changes found in (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository" + else + # check if we must update or create repository + if $update_repo; then + # make API call + callGiteaAPI "tags" "${VDM_PACKAGE_OWNER}" "${VDM_PACKAGE_REPO}" "${VDM_PACKAGE_API}" "${VDM_PACKAGE_TOKEN}" || return 28 + # get the name + if [ -n "${VDM_API_BUCKET}" ]; then + version_name=$(echo "${VDM_API_BUCKET}" | jq -r ".name") + else + return 28 + fi + # get the repository last tag + makeGitCommit "Update - ${VDM_PACKAGE_VERSION:-1.0.0}" "${VDM_PACKAGE_VERSION:-1.0.0}" "${version_name}" || return 28 + # give little notice of progress + _echo "[info] Pushing changes to (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository" + # make a normal push update + git push >/dev/null 2>&1 || return 30 + git push --tags >/dev/null 2>&1 || return 30 + else + # create new repo + setGitRepository || return 29 + # give little notice of progress + _echo "[info] Pushing (TO CREATE) changes to (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository" + # push to creat the repository (if allowed) + git push -u origin master >/dev/null 2>&1 || return 30 + git push --tags >/dev/null 2>&1 || return 30 + fi + fi + # success + return 0 +} + +# get the existing repository +function getExistingRepository() { + # little information of progress + _echo "[info] Getting (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository" + # clone the existing repository + git clone "git@${VDM_PACKAGE_URL}:${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}.git" >/dev/null 2>&1 || return 23 + # success + return 0 +} + +# set the new repository +function setNewRepository() { + # little information of progress + _echo "[info] Creating (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) folder" + # check if the repository exist on our gitea instance + mkdir -p "${VDM_PACKAGE_GIT_DIR}/${VDM_PACKAGE_REPO}" || return 24 + # success + return 0 +} + +# set new git repository +function setGitRepository() { + # little information of progress + _echo "[info] Initializing the (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository" + # initialize the repository + git init >/dev/null 2>&1 || return 29 + # add the first commit + makeGitCommit "First Commit - ${VDM_PACKAGE_VERSION:-1.0.0}" "${VDM_PACKAGE_VERSION:-1.0.0}" >/dev/null 2>&1 || return 28 + # little information of progress + _echo "[info] Adding remote branch to (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository" + # add the remote branch + git remote add origin "git@${VDM_PACKAGE_URL}:${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}.git" >/dev/null 2>&1 || return 29 + #success + return 0 +} + +# make the git commit +function makeGitCommit() { + # add all (or remove) + git add . >/dev/null 2>&1 || return 28 + # little information of progress + _echo "[info] Committing (${1}) to (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository" + # set the commit message + git commit -am"${1}" >/dev/null 2>&1 || return 28 + # check if the tag should be added + if [ "${2:-error}" != "error" ] && [ "${2:-error}" != "${3:-none}" ]; then + # little information of progress + _echo "[info] Adding TAG (${2}) to (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository" + # add the new tag + git tag "${2}" >/dev/null 2>&1 || return 28 + fi + # success + return 0 +} + +# add all the new files to the repository +function setRepositoryNewFiles() { + # little information of progress + _echo "[info] Moving new files into the (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) directory" + _echo "[info] Removing the ${VDM_PACKAGE_DIR:?} directory" + # move all the new files + if [ -d "${VDM_PACKAGE_DIR}" ]; then + mv "${VDM_PACKAGE_DIR:?}/"* "${VDM_PACKAGE_GIT_DIR}/${VDM_PACKAGE_REPO}" >/dev/null 2>&1 && + rm -rf "${VDM_PACKAGE_DIR:?}" >/dev/null 2>&1 || + return 27 + else + return 27 + fi + # success + return 0 +} + +# give the echo messages +# only if not set to be quiet +function _echo() { + if (("$QUIET" == 0)); then + echo "$1" + fi +} + +# remove the program if installed +function runUninstall() { + # now remove the script + if [ -f "/usr/local/bin/${PROGRAM_CODE}" ]; then + sudo rm -f "/usr/local/bin/${PROGRAM_CODE}" + echo "[info] ${PROGRAM_NAME} v${PROGRAM_VERSION} has been completely uninstalled." + else + echo "[info] ${PROGRAM_NAME} v${PROGRAM_VERSION} is not installed." + fi +} + +# update the script with the latest version +function runUpdate() { + # remove the current version + if [ -f "/usr/local/bin/${PROGRAM_CODE}" ]; then + # just backup in case of failure + sudo mv "/usr/local/bin/${PROGRAM_CODE}" "/usr/local/bin/${PROGRAM_CODE}.bak" + fi + # pull the latest version. Master is always the latest + if sudo curl --fail -L "https://git.vdm.dev/api/v1/repos/octoleo/${PROGRAM_CODE}/raw/src/${PROGRAM_CODE}?ref=${branch:-master}" -o "/usr/local/bin/${PROGRAM_CODE}" 2>/dev/null; then + # give success message + echo "[success] Update was successful." + # do we have a backup + if [ -f "/usr/local/bin/${PROGRAM_CODE}.bak" ]; then + # lets remove it now + sudo rm -f "/usr/local/bin/${PROGRAM_CODE}.bak" + fi + else + # show the error + echo >&2 "[error] Update failed! Please try again later." + # do we have a backup + if [ -f "/usr/local/bin/${PROGRAM_CODE}.bak" ]; then + # move backup back + sudo mv "/usr/local/bin/${PROGRAM_CODE}.bak" "/usr/local/bin/${PROGRAM_CODE}" + fi + fi + # always set the permission again if we have a file + if [ -f "/usr/local/bin/${PROGRAM_CODE}" ]; then + # the we make sure its executable + sudo chmod +x "/usr/local/bin/${PROGRAM_CODE}" + fi + # always exit so the new script can load + exit 0 +} + +# help message ʕ•ᴥ•ʔ +function show_help() { + cat < + Packager name + example: ${PROGRAM_CODE} -p="Vast Development Method" + ====================================================== + -pu | --packager-url= + Packager url + example: ${PROGRAM_CODE} -pu="https://git.vdm.dev/" + ====================================================== + -e | --env= + load the environment variables file + example: ${PROGRAM_CODE} --env=/src/.env + ====================================================== + --conf | --config= + load the configuration for the package in json format + file-example: src/example.json + example: ${PROGRAM_CODE} --config=config.json + ====================================================== + -t | --token= + load the global token + example: ${PROGRAM_CODE} --token=xxxxxxxxxxxxxxxxxxxxxxxxx + ====================================================== + -u | --url= + Global url of the Gitea instance + example: ${PROGRAM_CODE} --url="git.vdm.dev" + ====================================================== + -a | --api= + Global api of the Gitea instance + example: ${PROGRAM_CODE} --api="https://git.vdm.dev/api/v1" + ====================================================== + -q | --quiet + mute all output messages + example: ${PROGRAM_CODE} --quiet + ====================================================== + --update + to update your install + example: ${PROGRAM_CODE} --update + ====================================================== + --uninstall + to uninstall this script + example: ${PROGRAM_CODE} --uninstall + ====================================================== + -h|--help + display this help menu + example: ${PROGRAM_CODE} -h + example: ${PROGRAM_CODE} --help + ====================================================== + ${PROGRAM_NAME} v${PROGRAM_VERSION} + ====================================================== +EOF +} + +# SET THE DEFAULTS ##################################### +# get start time +# shellcheck disable=SC2034 +START_BUILD=$(date +"%s") +# use UTC+00:00 time also called zulu +# shellcheck disable=SC2034 +START_DATE=$(TZ=":ZULU" date +"%m/%d/%Y @ %R (UTC)") +CREATION_DATE=$(TZ=":ZULU" date +"%B %Y") +CREATION_YEAR=$(TZ=":ZULU" date +"%Y") +# the quiet switch +QUIET="${QUIET:-0}" +# we set the packager directory +tmp_path="/home/$USER/${PROGRAM_CODE}" +PACKAGE_DIR="${PACKAGE_DIR:-$tmp_path}" +# we set the licenses directory +tmp_path="/home/$USER/${PROGRAM_CODE}/licenses" +LICENSE_DIR="${LICENSE_DIR:-$tmp_path}" +# the environment variables path +tmp_path="/home/$USER/.config/${PROGRAM_CODE}/.env" +VDM_ENV_FILE_PATH="${VDM_ENV_FILE_PATH:-$tmp_path}" +# car this tmp out +unset tmp_path + +# check if we have options +while :; do + case $1 in + -h | --help) + show_help # Display a usage synopsis. + exit + ;; + -q | --quiet) + QUIET=1 + ;; + --uninstall) + runUninstall + shift + ;; + --update) + runUpdate + shift + ;; + -e | --env) # Takes an option argument; ensure it has been specified. + if [ "$2" ]; then + VDM_ENV_FILE_PATH=$2 + shift + else + echo '[error] "--env" requires a non-empty option argument.' + exit 17 + fi + ;; + -e=?* | --env=?*) + VDM_ENV_FILE_PATH=${1#*=} # Delete everything up to "=" and assign the remainder. + ;; + -e= | --env=) # Handle the case of an empty --packages= + echo '[error] "--env=" requires a non-empty option argument.' + exit 17 + ;; + --conf | --config) # Takes an option argument; ensure it has been specified. + if [ "$2" ]; then + VDM_PACKAGE_CONF_FILE=$2 + shift + else + echo '[error] "--conf" requires a non-empty option argument.' + exit 17 + fi + ;; + --conf=?* | --config=?*) + VDM_PACKAGE_CONF_FILE=${1#*=} # Delete everything up to "=" and assign the remainder. + ;; + --conf= | --config=) # Handle the case of an empty --packages= + echo '[error] "--conf=" requires a non-empty option argument.' + exit 17 + ;; + -p | --packager) # Takes an option argument; ensure it has been specified. + if [ "$2" ]; then + VDM_PACKAGER=$2 + shift + else + echo '[error] "--packager" requires a non-empty option argument.' + exit 17 + fi + ;; + -p=?* | --packager=?*) + VDM_PACKAGER=${1#*=} # Delete everything up to "=" and assign the remainder. + ;; + -p= | --packager=) # Handle the case of an empty --packages= + echo '[error] "--packager=" requires a non-empty option argument.' + exit 17 + ;; + -pu | --packager-url) # Takes an option argument; ensure it has been specified. + if [ "$2" ]; then + VDM_PACKAGER_URL=$2 + shift + else + echo '[error] "--packager-url" requires a non-empty option argument.' + exit 17 + fi + ;; + -pu=?* | --packager-url=?*) + VDM_PACKAGER_URL=${1#*=} # Delete everything up to "=" and assign the remainder. + ;; + -pu= | --packager-url=) # Handle the case of an empty --packager-url= + echo '[error] "--packager-url=" requires a non-empty option argument.' + exit 17 + ;; + -t | --token) # Takes an option argument; ensure it has been specified. + if [ "$2" ]; then + VDM_GLOBAL_TOKEN=$2 + shift + else + echo '[error] "--token" requires a non-empty option argument.' + exit 17 + fi + ;; + -t=?* | --token=?*) + # shellcheck disable=SC2034 + VDM_GLOBAL_TOKEN=${1#*=} # Delete everything up to "=" and assign the remainder. + ;; + -t= | --token=) # Handle the case of an empty --packages= + echo '[error] "--token=" requires a non-empty option argument.' + exit 17 + ;; + -a | --api) # Takes an option argument; ensure it has been specified. + if [ "$2" ]; then + VDM_GLOBAL_API=$2 + shift + else + echo '[error] "--api" requires a non-empty option argument.' + exit 17 + fi + ;; + -a=?* | --api=?*) + # shellcheck disable=SC2034 + VDM_GLOBAL_API=${1#*=} # Delete everything up to "=" and assign the remainder. + ;; + -a= | --api=) # Handle the case of an empty --packages= + echo '[error] "--api=" requires a non-empty option argument.' + exit 17 + ;; + -u | --url) # Takes an option argument; ensure it has been specified. + if [ "$2" ]; then + VDM_GLOBAL_URL=$2 + shift + else + echo '[error] "--url" requires a non-empty option argument.' + exit 17 + fi + ;; + -u=?* | --url=?*) + # shellcheck disable=SC2034 + VDM_GLOBAL_URL=${1#*=} # Delete everything up to "=" and assign the remainder. + ;; + -u= | --url=) # Handle the case of an empty --packages= + echo '[error] "--url=" requires a non-empty option argument.' + exit 17 + ;; + *) # Default case: No more options, so break out of the loop. + break ;; + esac + shift +done + +# load local environment variables +# shellcheck disable=SC1090 +[ -f "${VDM_ENV_FILE_PATH}" ] && source "${VDM_ENV_FILE_PATH}" + +# check if the config is passed via a URL +if [[ "${VDM_PACKAGE_CONF_FILE}" =~ ^"http:" ]] || [[ "${VDM_PACKAGE_CONF_FILE}" =~ ^"https:" ]]; then + # shellcheck disable=SC2143 + if [[ $(wget -S --spider "${VDM_PACKAGE_CONF_FILE}" 2>&1 | grep 'HTTP/1.1 200 OK') ]]; then + mkdir -p "/home/$USER/.config/${PROGRAM_CODE}" + wget --quiet "${VDM_PACKAGE_CONF_FILE}" -O "/home/$USER/.config/${PROGRAM_CODE}/conf.json" + VDM_PACKAGE_CONF_FILE="/home/$USER/.config/${PROGRAM_CODE}/conf.json" + else + echo >&2 "[error] The config:${VDM_PACKAGE_CONF_FILE} is not a valid URL. Aborting." + exit 18 + fi +fi + +# make sure whe have a configuration file +[ -f "${VDM_PACKAGE_CONF_FILE}" ] || { + echo >&2 "[error] The config:${VDM_PACKAGE_CONF_FILE:-empty_value} could not be found. Aborting." + exit 18 +} + +# run Main ┬┴┬┴┤(・_├┬┴┬┴ +main + +exit 0