├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── README_fr.md ├── YEP.md ├── actions.toml ├── check_process ├── conf └── app.src ├── config_panel.toml ├── doc ├── .gitkeep ├── DESCRIPTION.md ├── DESCRIPTION_fr.md ├── DISCLAIMER.md ├── DISCLAIMER_fr.md └── screenshots │ └── .gitkeep ├── hooks ├── post_app_install └── post_app_remove ├── manifest.json └── scripts ├── _common.sh ├── actions ├── clean_backups ├── close_fallback ├── deploy_fallback ├── force_backup ├── reset_default_config ├── update_dns └── update_from_fallback ├── backup ├── config ├── install ├── remove ├── restore └── upgrade /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently. 4 | 5 | --- 6 | 7 | **How to post a meaningful bug report** 8 | 1. *Read this whole template first.* 9 | 2. *Determine if you are on the right place:* 10 | - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change_url...), you are on the right place!* 11 | - *Otherwise, the issue may be due to the app itself. Refer to its documentation or repository for help.* 12 | - *When in doubt, post here and we will figure it out together.* 13 | 3. *Delete the italic comments as you write over them below, and remove this guide.* 14 | --- 15 | 16 | ### Describe the bug 17 | 18 | *A clear and concise description of what the bug is.* 19 | 20 | ### Context 21 | 22 | - Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...* 23 | - YunoHost version: x.x.x 24 | - I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...* 25 | - Are you in a special context or did you perform some particular tweaking on your YunoHost instance?: *no / yes* 26 | - If yes, please explain: 27 | - Using, or trying to install package version/branch: 28 | - If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`* 29 | 30 | ### Steps to reproduce 31 | 32 | - *If you performed a command from the CLI, the command itself is enough. For example:* 33 | ```sh 34 | sudo yunohost app install the_app 35 | ``` 36 | - *If you used the webadmin, please perform the equivalent command from the CLI first.* 37 | - *If the error occurs in your browser, explain what you did:* 38 | 1. *Go to '...'* 39 | 2. *Click on '...'* 40 | 3. *Scroll down to '...'* 41 | 4. *See error* 42 | 43 | ### Expected behavior 44 | 45 | *A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.* 46 | 47 | ### Logs 48 | 49 | *When an operation fails, YunoHost provides a simple way to share the logs.* 50 | - *In the webadmin, the error message contains a link to the relevant log page. On that page, you will be able to 'Share with Yunopaste'. If you missed it, the logs of previous operations are also available under Tools > Logs.* 51 | - *In command line, the command to share the logs is displayed at the end of the operation and looks like `yunohost log display [log name] --share`. If you missed it, you can find the log ID of a previous operation using `yunohost log list`.* 52 | 53 | *After sharing the log, please copypaste directly the link provided by YunoHost (to help readability, no need to copypaste the entire content of the log here, just the link is enough...)* 54 | 55 | *If applicable and useful, add screenshots to help explain your problem.* 56 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Problem 2 | 3 | - *Description of why you made this PR* 4 | 5 | ## Solution 6 | 7 | - *And how do you fix that problem* 8 | 9 | ## PR Status 10 | 11 | - [ ] Code finished and ready to be reviewed/tested 12 | - [ ] The fix/enhancement were manually tested (if applicable) 13 | 14 | ## Automatic tests 15 | 16 | Automatic tests can be triggered on https://ci-apps-dev.yunohost.org/ *after creating the PR*, by commenting "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!". (N.B. : for this to work you need to be a member of the Yunohost-Apps organization) 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.sw[op] 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | ## Unreleased 5 | - Nothing for now... 6 | 7 | ## 0.93~ynh1 - 2022-12-26 8 | 9 | #### Fixed 10 | - Various fixes 11 | 12 | ## 0.92~ynh1 - 2022-06-27 13 | 14 | #### Fixed 15 | - Fix permissions 16 | 17 | ## 0.91~ynh1 - 2021-12-07 18 | 19 | #### Fixed 20 | - Fix backup hooks 21 | 22 | ## 0.9~ynh1 - 2021-05-04 23 | 24 | #### Fixed 25 | - [Fix YunoHost 4.1](https://github.com/maniackcrudelis/Fallback-server/commit/92a12a6b3566979b1e2a3f809fd12b45ce856851) 26 | 27 | ## [0.8~ynh3](https://github.com/YunoHost-Apps/fallback_ynh/pull/22) - 2020-04-09 28 | 29 | #### Fixed 30 | - [Actions and config_panel tests](https://github.com/YunoHost-Apps/fallback_ynh/commit/f50ae479b740c20e3773497d44c0edd4bd143dd7) 31 | 32 | 33 | ## [0.8~ynh2](https://github.com/YunoHost-Apps/fallback_ynh/pull/21) - 2020-01-04 34 | 35 | #### Fixed 36 | - [Fix config-panel](https://github.com/YunoHost-Apps/fallback_ynh/pull/21/commits/c311c1d1de9ad1a0bdefbe961e87cbb1886b9978) 37 | 38 | 39 | ## [0.8~ynh1](https://github.com/YunoHost-Apps/fallback_ynh/pull/20) - 2019-11-20 40 | 41 | #### Changed 42 | - [Normalization from example_ynh](https://github.com/YunoHost-Apps/fallback_ynh/commit/28afc3a7c7b3604e993cb782423275b6929267e9) 43 | * [Update to v0.8](https://github.com/YunoHost-Apps/fallback_ynh/commit/ba212244ea2c852fc3b3faf939ab35e3523fd28a) 44 | 45 | #### Added 46 | - [Add a changelog](https://github.com/YunoHost-Apps/fallback_ynh/commit/bde776613f72d3f851f6f86e766a5559c28ba684) 47 | * [Add actions and use toml](https://github.com/YunoHost-Apps/fallback_ynh/commit/88ddc2d61050809b85f2be857dc4f78a39da2388) 48 | 49 | 50 | ## [0.71~ynh3](https://github.com/YunoHost-Apps/fallback_ynh/pull/14) - 2019-02-03 51 | 52 | #### Changed 53 | - [Add progression bar](https://github.com/YunoHost-Apps/fallback_ynh/pull/14/commits/ad582f7b9b0097ee46b5b127964025215b5e830e) 54 | - [Changelog & html email](https://github.com/YunoHost-Apps/fallback_ynh/pull/14/commits/90b7a72981ffc9920b302726f2a13a76e85e7acf) 55 | 56 | 57 | ## [0.71~ynh2](https://github.com/YunoHost-Apps/fallback_ynh/pull/13) - 2019-01-21 58 | 59 | #### Changed 60 | - [Update to last standart](https://github.com/YunoHost-Apps/fallback_ynh/pull/13/commits/b8aec6a588324062141c748b2f44471ed7d96e35) 61 | - [Advertise config-panel and actions](https://github.com/YunoHost-Apps/fallback_ynh/pull/13/commits/ee9d34939fdad0c0bb86580314f5ee078032fbc7) 62 | 63 | 64 | ## [0.71~ynh1](https://github.com/YunoHost-Apps/fallback_ynh/pull/12) - 2018-11-28 65 | 66 | #### Changed 67 | * [Update to v0.71](https://github.com/YunoHost-Apps/fallback_ynh/pull/12/commits/e4d7e072bd153477252e4f72b10e09c8466d585e) 68 | 69 | 70 | ## [0.7~ynh1](https://github.com/YunoHost-Apps/fallback_ynh/pull/11) - 2018-11-24 71 | 72 | #### Changed 73 | * [Update to v0.7](https://github.com/YunoHost-Apps/fallback_ynh/pull/11/commits/02f0633256acca40a5b041ef917103659a9b3eb2) 74 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 5 | 6 | # Fallback server for YunoHost 7 | 8 | [![Integration level](https://dash.yunohost.org/integration/fallback.svg)](https://dash.yunohost.org/appci/app/fallback) ![Working status](https://ci-apps.yunohost.org/ci/badges/fallback.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/fallback.maintain.svg) 9 | [![Install Fallback server with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=fallback) 10 | 11 | *[Lire ce readme en français.](./README_fr.md)* 12 | 13 | > *This package allows you to install Fallback server quickly and simply on a YunoHost server. 14 | If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* 15 | 16 | ## Overview 17 | 18 | Fallback is a special app, only by command line interface, which provide a way to have a secondary server which you can used if your main server goes down. 19 | This other server will allow you to deploy a copy of your server to bring back you to internet during your break down. 20 | 21 | 22 | **Shipped version:** 0.93~ynh1 23 | ## Disclaimers / important information 24 | 25 | ## Configuration 26 | 27 | After the installation, you should not have anything else to configure. 28 | If you want anyway, you can find the list of app to backup in the file `/home/yunohost.app/fallback/app_list` and a global configuration in this other file `/home/yunohost.app/fallback/config.conf`. 29 | 30 | ## Additionnal informations 31 | 32 | ### How it works 33 | 34 | This app is made of 2 parts, you have to install it with the `main server` option on your main server, and again, with the `fallback server` option on the other server you want to use as rescue server. 35 | > You should keep this other server only for that purpose. And maybe also to make some other backups. And it's obviously better if you can have this other server in another place than the previous one. 36 | 37 | After the installation, every night, the main server will make some backups and send them to your fallback server. 38 | At least, it'll make a backup of your system. You can ask to backup your apps too, by editing the file `/home/yunohost.app/fallback/app_list` 39 | Before make any backup, it will compare with the last backup. And will make a new one, only if there any news on it. Just to preserve your bandwith. 40 | > These backups will be encrypted, unless you ask to not. 41 | 42 | If you have an issue with your main server, so you can use your fallback server and restore your nightly backups and run with this server during your break down. 43 | Let's see how this works. 44 | 45 | #### What I have to do in case of break down of my main server ? 46 | 47 | So, here we are, you have a failure with your main server. That had to happen ! 48 | Don't worry, jump on your fallback server and use the deploy script. 49 | `/home/yunohost.app/fallback/deploy_fallback` 50 | > You can also use the 'Deploy the fallback server.' action from your admin panel. 51 | 52 | This script will backup your fallback server first and then restore the backup from your main server. 53 | This restore will change your fallback server and give him the configuration of your main server, and restore the apps you've selected in your app_list. 54 | Now this server will became your main server, received your emails and run your apps. 55 | > In fact, there just a "small thing", you have to change your dns to indicate the new IP of your server. Let's see that at the end of this doc please. 56 | > In order to ease usage of 'actions', the fallback server should have an associated domain name, like fallback.mydomain.tld 57 | 58 | #### So, now my main server is fixed. But I need to get all the stuff happened on the fallback. 59 | 60 | If you're done with your fallback server, use the other script, just next to the previous one. 61 | `/home/yunohost.app/fallback/close_fallback` 62 | > You can also use the 'Close the fallback server.' action from your admin panel. 63 | 64 | This script will backup your fallback system and the apps you've previously restored on it. And put all of that aside. 65 | Then, it will remove all of that of your system and restore the backup it made when you used `deploy_fallback`. Like that, nothing happenned on this server. 66 | 67 | So, all your data produced on your fallback are now aside. Waiting for you. 68 | Return on your main server, and use this script. 69 | `/home/yunohost.app/fallback/update_from_fallback` 70 | > You can also use the 'Update from your fallback server' action from your admin panel. 71 | 72 | To finish, this script will get the backups from the fallback and restore them on your main server. To update your data and keep your main server up to date with what you've done on your fallback. 73 | To be more carefull, each restoration will be preceed by a backup. Just in case. 74 | 75 | #### And... How I'm supposed to change my IP quickly in all the dns ? 76 | 77 | That's a difficult question... 78 | And that needs more experimentation... 79 | But, there a way to do that simply. Use a dynamic dns entry at your registrar (if it allow it), even if you have a static ip. And update this ip if you have to switch to your fallback. 80 | Depend of your registrar, you should have a CLI tools to do that simplier. 81 | 82 | ## :red_circle: Antifeatures 83 | 84 | - **Package not maintained**: This YunoHost package is not maintained and needs adoption. 85 | 86 | ## Documentation and resources 87 | 88 | * Official app website: 89 | * Upstream app code repository: 90 | * YunoHost documentation for this app: 91 | * Report a bug: 92 | 93 | ## Developer info 94 | 95 | Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/fallback_ynh/tree/testing). 96 | 97 | To try the testing branch, please proceed like that. 98 | 99 | ``` bash 100 | sudo yunohost app install https://github.com/YunoHost-Apps/fallback_ynh/tree/testing --debug 101 | or 102 | sudo yunohost app upgrade fallback -u https://github.com/YunoHost-Apps/fallback_ynh/tree/testing --debug 103 | ``` 104 | 105 | **More info regarding app packaging:** 106 | -------------------------------------------------------------------------------- /README_fr.md: -------------------------------------------------------------------------------- 1 | 5 | 6 | # Fallback server pour YunoHost 7 | 8 | [![Niveau d’intégration](https://dash.yunohost.org/integration/fallback.svg)](https://dash.yunohost.org/appci/app/fallback) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/fallback.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/fallback.maintain.svg) 9 | [![Installer Fallback server avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=fallback) 10 | 11 | *[Read this readme in english.](./README.md)* 12 | 13 | > *Ce package vous permet d’installer Fallback server rapidement et simplement sur un serveur YunoHost. 14 | Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l’installer et en profiter.* 15 | 16 | ## Vue d’ensemble 17 | 18 | Fallback est une application spéciale, uniquement en ligne de commande, qui vous donne le moyen de disposer d'un second serveur que vous pourrez utiliser si le premier tombe en panne. 19 | Cet autre serveur va vous permettre de déployer une copie de votre serveur pour retrouver vos services internet durant la panne. 20 | 21 | 22 | **Version incluse :** 0.93~ynh1 23 | ## Avertissements / informations importantes 24 | 25 | ## Configuration 26 | 27 | Après l'installation, vous ne devriez pas avoir quoi que ce soit d'autre à configurer. 28 | Si vous souhaitez tout de même le faire, vous trouverez la liste des app à sauvegarder dans le fichier `/home/yunohost.app/fallback/app_list` et une configuration globale dans cet autre fichier `/home/yunohost.app/fallback/config.conf`. 29 | 30 | ## Informations additionnelles 31 | 32 | ### Comment ça fonctionne 33 | 34 | Cette app est consitutée de 2 parties, vous devez l'installer avec l'option `main server` sur votre serveur principal, et une seconde fois, avec l'option `fallback server` sur l'autre serveur, qui vous voulez utiliser comme serveur de secours. 35 | > Vous devriez garder cet autre serveur uniquement pour cet usage. Ou alors pour y mettre quelques autres backups. Et bien sûr, il est préférable que ce serveur soit à un autre endroit. 36 | > Afin de simplifier l'usage des 'actions', le serveur de secours devrait bénéficier d'un nom de domaine associé, comme fallback.mondomain.tld 37 | 38 | Après l'installation, chaque nuit, le serveur principal va faire des sauvegardes et les envoyer sur votre serveur de secours. 39 | Au minimum, il fera une sauvegarde du système. Vous pouvez demander la sauvegarde de vos applications aussi, en éditant le fichier `/home/yunohost.app/fallback/app_list` 40 | Avant de faire un backup, il vérifiera avec celui de la nuit précédente. Et fera une nouvelle sauvegarde seulement si il y a quelque chose de nouveau. Afin de préserver votre bande passante. 41 | > Ces backups seront chiffrés, sauf si vous avez demandé l'inverse. 42 | 43 | Si vous avez un problème avec votre serveur principal, vous pouvez maintenant utiliser votre serveur de secours, restaurer votre sauvegarde de la nuit dernière, et utiliser ce serveur le temps de la panne. 44 | Voyons comment ça marche. 45 | 46 | #### Que dois-je faire en cas de panne de mon serveur principal ? 47 | 48 | Voilà, nous y sommes, votre serveur principal est panne, fallait bien que ça arrive ! 49 | Pas d'inquiétude, sautez sur votre serveur de secours et utiliser le script de déploiement. 50 | `/home/yunohost.app/fallback/deploy_fallback` 51 | > Vous pouvez également utiliser l'action 'Deploy the fallback server.' depuis votre panel administrateur. 52 | 53 | Ce script va commencer par faire un backup de votre serveur de secours, puis restaurer le backup de votre serveur principal. 54 | Cette restauration va transformer votre serveur de secours en lui donnant la configuration de votre serveur principal. Ensuite, il va restaurer les applications sélectionnées dans votre fichier app_list. 55 | A présent, ce serveur va devenir votre serveur principal, recevoir vos mails et faire tourner vos apps. 56 | > En fait, il y a juste un "petit détail", il faut modifier votre dns pour indiquer la nouvelle adresse de votre serveur. Voyons ça à la fin de cette doc. 57 | 58 | #### Bon, maintenant mon serveur est réparé. Mais j'ai besoin de récupérer ce qui s'est passé sur mon serveur de secours. 59 | 60 | Si vous avez terminé avec votre serveur de secours, utiliser l'autre script, juste à côté du précédent. 61 | `/home/yunohost.app/fallback/close_fallback` 62 | > Vous pouvez également utiliser l'action 'Close the fallback server.' depuis votre panel administrateur. 63 | 64 | Ce script va faire un backup du système de votre serveur de secours et des apps précédemment restaurées. Et mettre ces backups de côtés. 65 | 66 | Ensuite, il va nettoyer le système et restaurer le backup créé lors de l'exécution du script `deploy_fallback`. Ainsi, rien ne se sera passé sur ce server. 67 | 68 | Donc, toutes vos données produites sur votre serveur de secours sont maintenant mise de côté. Vous attendant gentillement. 69 | Retourner donc sur votre serveur principal et utiliser ce script. 70 | `/home/yunohost.app/fallback/update_from_fallback` 71 | > Vous pouvez également utiliser l'action 'Update from your fallback server' depuis votre panel administrateur. 72 | 73 | Pour terminer, ce script va télécharger les backups depuis votre serveur de secours et les restaurer sur votre serveur principal. Pour mettre à jour vos données et garder votre serveur principal à jour avec ce que vous avez fait sur le serveur de secours. 74 | Pour être plus prudent, chaque restauration sera précédée d'un backup, juste au cas où. 75 | 76 | #### Et... Comment je suis censé changer mon IP rapidement dans les dns ? 77 | 78 | C'est une question difficile... 79 | Et ça nécessite plus d'expérimentation... 80 | Mais, il y a un moyen simple de faire ça. Utiliser une entrée de dns dynamique chez votre registrar (si il vous le permet), même si vous avez une IP statique. Et mettez à jour cette IP si vous devez basculer sur votre serveur de secours. 81 | Selon votre registrar, vous devriez disposer d'un outil en ligne de commande pour faire simplement. 82 | 83 | ## :red_circle: Fonctions indésirables 84 | 85 | - **Package not maintained**: This YunoHost package is not maintained and needs adoption. 86 | 87 | ## Documentations et ressources 88 | 89 | * Site officiel de l’app : 90 | * Dépôt de code officiel de l’app : 91 | * Documentation YunoHost pour cette app : 92 | * Signaler un bug : 93 | 94 | ## Informations pour les développeurs 95 | 96 | Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/fallback_ynh/tree/testing). 97 | 98 | Pour essayer la branche testing, procédez comme suit. 99 | 100 | ``` bash 101 | sudo yunohost app install https://github.com/YunoHost-Apps/fallback_ynh/tree/testing --debug 102 | ou 103 | sudo yunohost app upgrade fallback -u https://github.com/YunoHost-Apps/fallback_ynh/tree/testing --debug 104 | ``` 105 | 106 | **Plus d’infos sur le packaging d’applications :** -------------------------------------------------------------------------------- /YEP.md: -------------------------------------------------------------------------------- 1 | #### [Level 0](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-0) 2 | [YEP 1.1 - Nommer son app et son dépot](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-11) 3 | `Validated` 4 | [YEP 1.2 - Inscrire l'app sur un "répertoire" connu](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-12) 5 | `Validated` 6 | 7 | #### [Level 1](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-1) 8 | [YEP 2.2 - Utiliser bash pour les scripts principaux](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-22) 9 | `Validated` 10 | [YEP 2.5 - Copier correctement des fichiers](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-25) 11 | `Don't know` 12 | [YEP 2.7 - Donner des permissions suffisantes aux instructions bash](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-27) 13 | `Validated` 14 | [YEP 2.15 - Suivre les instructions d'installation de l'application](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-215) 15 | `Validated` 16 | 17 | #### [Level 2](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-2) 18 | [YEP 1.5 - Mettre à jour régulièrement le statut de l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-11) 19 | `Validated` 20 | [YEP 2.18.2 - Gérer l'installation à la racine d’un nom de domaine](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2182) 21 | `Not applicable` - *Automatically verified.* 22 | [YEP 2.18.3 - Gérer l'installation sur un sous-domaine](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2183) 23 | `Not applicable` - *Automatically verified.* 24 | [YEP 2.18.4 - Gérer l'installation sur un chemin /path](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2184) 25 | `Not applicable` - *Automatically verified.* 26 | [YEP 4.6 - Gère le multi-instance](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-11) 27 | `Not yet validated` - *Automatically verified.* 28 | 29 | #### [Level 3](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-3) 30 | [YEP 2.3 - Sauvegarder les réponses lors de l'installation](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-23) 31 | `Validated` 32 | 33 | #### [Level 4](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-4) 34 | [YEP 4.1 - Lier au ldap](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-41) 35 | `Not applicable` 36 | [YEP 4.2 - Lier l'authentification au sso](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-42) 37 | `Not applicable` 38 | 39 | #### [Level 5](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-5) 40 | [YEP 1.3 - Indiquer la licence associée au paquet](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-13) 41 | `Validated` 42 | [YEP 2.1 - Respecter le format du manifeste](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-21) 43 | `Validated` - *Automatically verified.* 44 | [YEP 2.12 - Utiliser les commandes pratiques (helpers)](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-212) 45 | `Validated` 46 | [YEP 2.18.1 - Lancer le script d'installation d'une webapp correctement](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2181) 47 | `Not applicable` 48 | 49 | #### [Level 6](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-6) 50 | [YEP 1.4 - Informer sur l'intention de maintenir un paquet](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-14) 51 | `Validated` 52 | [YEP 1.6 - Se tenir informé sur l'évolution du packaging d'apps](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-16) 53 | `Validated` 54 | [YEP 1.7 - Ajouter l'app à l'organisation YunoHost-Apps](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-17) 55 | `Validated` - *Automatically verified.* 56 | [YEP 1.8 - Publier des demandes de test](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-18) 57 | `Validated` 58 | [YEP 1.9 - Documenter l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-19) 59 | `Validated` 60 | [YEP 1.10 - Garder un historique de version propre](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-110) 61 | `Don't know` 62 | [YEP 2.9 - Enlever toutes traces de l'app lors de la suppression](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-29) 63 | `Validated` 64 | [YEP 3.3 - Faciliter le contrôle de l'intégrité des sources](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-33) 65 | `Validated` 66 | [YEP 3.5 - Suivre les recommendations de la documentation de l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-35) 67 | `Validated` 68 | [YEP 3.6 - Mettre à jour les versions contenant des CVE](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-36) 69 | `Validated` 70 | [YEP 4.3 - Fournir un script de sauvegarde YunoHost fonctionnel](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-43) 71 | `Validated` - *Automatically verified.* 72 | [YEP 4.4 - Fournir un script de restauration YunoHost fonctionnel](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-44) 73 | `Validated` - *Automatically verified.* 74 | 75 | #### [Level 7](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-7) 76 | [YEP 2.6 - Annuler l'action si les valeurs d'entrées sont incorrectes](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-26) 77 | `Validated` 78 | [YEP 3.2 - Ouvrir un port correctement](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-32) 79 | `Not applicable` 80 | 81 | #### [Level 8](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-8) 82 | [YEP 2.4 - Détecter et gérer les erreurs](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-24) 83 | `Validated` 84 | [YEP 2.8 - Modifier correctement une configuration système](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-28) 85 | `Validated` 86 | [YEP 2.16 - Vérifier la disponibilité des dépendances sur ARM, x86 et x64](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-216) 87 | `Not yet validated` - *Automatically verified.* 88 | [YEP 2.18.5 - Gérer la tuile YunoHost pour faciliter la navigation entre les applications](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2185) 89 | `Not applicable` 90 | [YEP 3.4 - Isoler l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-34) 91 | `Validated` 92 | [YEP 4.5 - Utiliser les hooks](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-45) 93 | `Validated` 94 | 95 | #### [Level 9](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-9) 96 | [YEP 2.10 - Configurer les logs de l'application](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-210) 97 | `Validated` 98 | [YEP 2.11 - Utiliser une variable plutôt que l'app id directement](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-211) 99 | `Validated` 100 | [YEP 2.13 - Traduire le paquet en anglais](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-213) 101 | `Partially validated` 102 | [YEP 2.14 - Remplir correctement un fichier de conf](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-214) 103 | `Not yet validated` 104 | [YEP 2.17 - Prendre en compte la version d'origine lors des mises à jour](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-217) 105 | `Validated` 106 | [YEP 4.2.1 - Déconnexion](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-421) 107 | `Not applicable` 108 | 109 | #### Other YEP 110 | [YEP 3.1 - Ne pas demander ou stocker de mot de passe LDAP](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-31) 111 | `Validated` 112 | [YEP 4.7 - Ajouter un module à la CLI](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-47) 113 | `Not applicable` 114 | [YEP 4.8 - Ajouter un module à l'admin web](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-48) 115 | `Not applicable` 116 | 117 | State of each YEP can be one of these: `Validated`, `Partially validated`, `Not yet validated`, `Not applicable`, `Don't know`. 118 | -------------------------------------------------------------------------------- /actions.toml: -------------------------------------------------------------------------------- 1 | [force_backup] 2 | name = "[Main server] Create a new backup" 3 | command = "/bin/bash scripts/actions/force_backup" 4 | # user = "root" # optional 5 | # cwd = "/" # optional 6 | # accepted_return_codes = [0, 1, 2, 3] # optional 7 | accepted_return_codes = [0] 8 | description = "Run Fallback to create a new backup and send it." 9 | 10 | [clean_backups] 11 | name = "[Main server] Clean all previous backup files" 12 | command = "/bin/bash scripts/actions/clean_backups" 13 | # user = "root" # optional 14 | # cwd = "/" # optional 15 | # accepted_return_codes = [0, 1, 2, 3] # optional 16 | accepted_return_codes = [0] 17 | description = "Remove all previous backup files made by Fallback." 18 | 19 | [update_from_fallback] 20 | name = "[Main server] Update from your fallback server" 21 | command = "/bin/bash scripts/actions/update_from_fallback" 22 | # user = "root" # optional 23 | # cwd = "/" # optional 24 | # accepted_return_codes = [0, 1, 2, 3] # optional 25 | accepted_return_codes = [0] 26 | description = "Update the main server with the backup from your fallback server." 27 | 28 | 29 | [reset_default_config] 30 | name = "Reset the config file and restore a default one." 31 | command = "/bin/bash scripts/actions/reset_default_config \"both\"" 32 | # user = "root" # optional 33 | # cwd = "/" # optional 34 | # accepted_return_codes = [0, 1, 2, 3] # optional 35 | accepted_return_codes = [0] 36 | description = "Reset the config file config.conf or auto_check.conf." 37 | 38 | [update_dns] 39 | name = "Update your DNS to point your domain to this server." 40 | command = "/bin/bash scripts/actions/update_dns" 41 | # user = "root" # optional 42 | # cwd = "/" # optional 43 | # accepted_return_codes = [0, 1, 2, 3] # optional 44 | accepted_return_codes = [0] 45 | description = "In order to use that action, your 'auto_check.conf' file has to be set with 'auto_update_DNS=1' and 'auto_update_script' filled with a working script." 46 | 47 | 48 | [deploy_fallback] 49 | name = "[Fallback server] Deploy the fallback server." 50 | command = "/bin/bash scripts/actions/deploy_fallback" 51 | # user = "root" # optional 52 | # cwd = "/" # optional 53 | # accepted_return_codes = [0, 1, 2, 3] # optional 54 | accepted_return_codes = [0] 55 | description = "Deploy the fallback server to replace your broken main server." 56 | 57 | [close_fallback] 58 | name = "[Fallback server] Close the fallback server." 59 | command = "/bin/bash scripts/actions/close_fallback" 60 | # user = "root" # optional 61 | # cwd = "/" # optional 62 | # accepted_return_codes = [0, 1, 2, 3] # optional 63 | accepted_return_codes = [0] 64 | description = "Close the fallback server to return it to its fallback state. On the main server, use 'update_from_fallback' to update your data" 65 | -------------------------------------------------------------------------------- /check_process: -------------------------------------------------------------------------------- 1 | ;; Test install main server 2 | ; Manifest 3 | install_type="main server" 4 | encrypt=1 5 | encryption_pwd="password" 6 | ssh_host="ci-apps.yunohost.org" 7 | ssh_port="22" 8 | auto_detect_failure=0 9 | auto_deploy=0 10 | ; Actions 11 | ; Config_panel 12 | main_server.encryption.encrypt=0|1 13 | main_server.encryption.encryption_pwd=password1 14 | main_server.ssh_config.ssh_host=domain.tld 15 | main_server.ssh_config.ssh_port=23 16 | global.config.email_type=0|1 17 | ; Checks 18 | pkg_linter=1 19 | setup_sub_dir=0 20 | setup_root=0 21 | setup_nourl=1 22 | setup_private=0 23 | setup_public=0 24 | upgrade=1 25 | upgrade=1 from_commit=3d20e9d852fcf695a1a1419317a81bf315a009ce 26 | backup_restore=1 27 | multi_instance=0 28 | port_already_use=0 29 | change_url=0 30 | actions=0 31 | config_panel=1 32 | ;; Test install fallback server 33 | ; Manifest 34 | install_type="fallback server" 35 | encrypt=1 36 | pub_key="public_key..." 37 | auto_detect_failure=1 38 | delay_before_incident="1h" 39 | contact_mail="none" 40 | auto_deploy=1 41 | ; Actions 42 | ; Config_panel 43 | fallback_server.ssh_config.pub_key=my_public_key 44 | fallback_server.auto_deploy.auto_detect_failure=0|1 45 | fallback_server.auto_deploy.delay_before_incident=120 46 | fallback_server.auto_deploy.contact_mail=none@domain.tld 47 | fallback_server.auto_deploy.auto_deploy=1|0 48 | global.config.email_type=0|1 49 | ; Checks 50 | setup_nourl=1 51 | upgrade=1 52 | backup_restore=1 53 | actions=0 54 | config_panel=1 55 | ;;; Levels 56 | Level 5=auto 57 | ;;; Options 58 | Email= 59 | Notification=change 60 | ;;; Upgrade options 61 | ; commit=3d20e9d852fcf695a1a1419317a81bf315a009ce 62 | name=18 Sep 2017 v0.3 63 | manifest_arg=install_type=main server&encrypt=1&encryption_pwd=password&ssh_host=ci-apps.yunohost.org&ssh_port=22& 64 | -------------------------------------------------------------------------------- /conf/app.src: -------------------------------------------------------------------------------- 1 | SOURCE_URL=https://github.com/maniackcrudelis/Fallback-server/archive/refs/tags/v0.93.tar.gz 2 | SOURCE_SUM=6bde6e54730a813654bdd033d55b351db32ed43875f2b25b998bbdea8296b970 3 | SOURCE_SUM_PRG=sha256sum 4 | SOURCE_FORMAT=tar.gz 5 | SOURCE_IN_SUBDIR=true 6 | SOURCE_FILENAME= 7 | SOURCE_EXTRACT=true 8 | -------------------------------------------------------------------------------- /config_panel.toml: -------------------------------------------------------------------------------- 1 | version = "1.0" 2 | name = "Fallback configuration panel" 3 | 4 | [main_server] 5 | name = "Fallback, main server configuration" 6 | 7 | 8 | [main_server.encryption] 9 | name = "Encryption" 10 | 11 | [main_server.encryption.encrypt] 12 | ask = "Do you want to encrypt your backups?" 13 | type = "boolean" 14 | default = true 15 | 16 | [main_server.encryption.encryption_pwd] 17 | ask = "Set the password for encryption" 18 | type = "password" 19 | optional = true 20 | help = "A password is needed if encryption is activated." 21 | 22 | 23 | [main_server.ssh_config] 24 | name = "ssh configuration" 25 | 26 | [main_server.ssh_config.ssh_host] 27 | ask = "Domain name for the fallback server ?" 28 | type = "text" 29 | optional = true 30 | help = "This server has to be up, for the ssh-keyscan command." 31 | 32 | [main_server.ssh_config.ssh_port] 33 | ask = "Port for the ssh connection to the fallback server?" 34 | type = "number" 35 | default = 22 36 | optional = true 37 | 38 | 39 | [fallback_server] 40 | name = "Fallback, fallback server configuration" 41 | 42 | 43 | [fallback_server.ssh_config] 44 | name = "ssh configuration" 45 | 46 | [fallback_server.ssh_config.pub_key] 47 | ask = "Public key from your main server?" 48 | type = "text" 49 | optional = true 50 | 51 | 52 | [fallback_server.auto_deploy] 53 | name = "Auto deployement" 54 | 55 | [fallback_server.auto_deploy.auto_detect_failure] 56 | ask = "Auto detect a failure of the main server?" 57 | type = "boolean" 58 | default = true 59 | 60 | [fallback_server.auto_deploy.delay_before_incident] 61 | ask = "Delay before declaring an incident with the main server." 62 | type = "number" 63 | default = 60 64 | optional = true 65 | help = "Value in minutes" 66 | 67 | [fallback_server.auto_deploy.contact_mail] 68 | ask = "Email address to contact in case of failure." 69 | type = "text" 70 | optional = true 71 | 72 | [fallback_server.auto_deploy.auto_deploy] 73 | ask = "Deploy automatically the fallback in case of failure?" 74 | type = "boolean" 75 | default = false 76 | 77 | 78 | [global] 79 | name = "Global configuration" 80 | 81 | [global.config] 82 | name = "Global configuration" 83 | 84 | [global.config.email_type] 85 | ask = "Send HTML email to admin?" 86 | type = "boolean" 87 | default = true 88 | help = "Allow app scripts to send HTML mails instead of plain text." 89 | -------------------------------------------------------------------------------- /doc/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YunoHost-Apps/fallback_ynh/7c5711d7e88db56ed6522045d06d457b7a3bc681/doc/.gitkeep -------------------------------------------------------------------------------- /doc/DESCRIPTION.md: -------------------------------------------------------------------------------- 1 | Fallback is a special app, only by command line interface, which provide a way to have a secondary server which you can used if your main server goes down. 2 | This other server will allow you to deploy a copy of your server to bring back you to internet during your break down. 3 | -------------------------------------------------------------------------------- /doc/DESCRIPTION_fr.md: -------------------------------------------------------------------------------- 1 | Fallback est une application spéciale, uniquement en ligne de commande, qui vous donne le moyen de disposer d'un second serveur que vous pourrez utiliser si le premier tombe en panne. 2 | Cet autre serveur va vous permettre de déployer une copie de votre serveur pour retrouver vos services internet durant la panne. 3 | -------------------------------------------------------------------------------- /doc/DISCLAIMER.md: -------------------------------------------------------------------------------- 1 | ## Configuration 2 | 3 | After the installation, you should not have anything else to configure. 4 | If you want anyway, you can find the list of app to backup in the file `/home/yunohost.app/fallback/app_list` and a global configuration in this other file `/home/yunohost.app/fallback/config.conf`. 5 | 6 | ## Additionnal informations 7 | 8 | ### How it works 9 | 10 | This app is made of 2 parts, you have to install it with the `main server` option on your main server, and again, with the `fallback server` option on the other server you want to use as rescue server. 11 | > You should keep this other server only for that purpose. And maybe also to make some other backups. And it's obviously better if you can have this other server in another place than the previous one. 12 | 13 | After the installation, every night, the main server will make some backups and send them to your fallback server. 14 | At least, it'll make a backup of your system. You can ask to backup your apps too, by editing the file `/home/yunohost.app/fallback/app_list` 15 | Before make any backup, it will compare with the last backup. And will make a new one, only if there any news on it. Just to preserve your bandwith. 16 | > These backups will be encrypted, unless you ask to not. 17 | 18 | If you have an issue with your main server, so you can use your fallback server and restore your nightly backups and run with this server during your break down. 19 | Let's see how this works. 20 | 21 | #### What I have to do in case of break down of my main server ? 22 | 23 | So, here we are, you have a failure with your main server. That had to happen ! 24 | Don't worry, jump on your fallback server and use the deploy script. 25 | `/home/yunohost.app/fallback/deploy_fallback` 26 | > You can also use the 'Deploy the fallback server.' action from your admin panel. 27 | 28 | This script will backup your fallback server first and then restore the backup from your main server. 29 | This restore will change your fallback server and give him the configuration of your main server, and restore the apps you've selected in your app_list. 30 | Now this server will became your main server, received your emails and run your apps. 31 | > In fact, there just a "small thing", you have to change your dns to indicate the new IP of your server. Let's see that at the end of this doc please. 32 | > In order to ease usage of 'actions', the fallback server should have an associated domain name, like fallback.mydomain.tld 33 | 34 | #### So, now my main server is fixed. But I need to get all the stuff happened on the fallback. 35 | 36 | If you're done with your fallback server, use the other script, just next to the previous one. 37 | `/home/yunohost.app/fallback/close_fallback` 38 | > You can also use the 'Close the fallback server.' action from your admin panel. 39 | 40 | This script will backup your fallback system and the apps you've previously restored on it. And put all of that aside. 41 | Then, it will remove all of that of your system and restore the backup it made when you used `deploy_fallback`. Like that, nothing happenned on this server. 42 | 43 | So, all your data produced on your fallback are now aside. Waiting for you. 44 | Return on your main server, and use this script. 45 | `/home/yunohost.app/fallback/update_from_fallback` 46 | > You can also use the 'Update from your fallback server' action from your admin panel. 47 | 48 | To finish, this script will get the backups from the fallback and restore them on your main server. To update your data and keep your main server up to date with what you've done on your fallback. 49 | To be more carefull, each restoration will be preceed by a backup. Just in case. 50 | 51 | #### And... How I'm supposed to change my IP quickly in all the dns ? 52 | 53 | That's a difficult question... 54 | And that needs more experimentation... 55 | But, there a way to do that simply. Use a dynamic dns entry at your registrar (if it allow it), even if you have a static ip. And update this ip if you have to switch to your fallback. 56 | Depend of your registrar, you should have a CLI tools to do that simplier. 57 | -------------------------------------------------------------------------------- /doc/DISCLAIMER_fr.md: -------------------------------------------------------------------------------- 1 | ## Configuration 2 | 3 | Après l'installation, vous ne devriez pas avoir quoi que ce soit d'autre à configurer. 4 | Si vous souhaitez tout de même le faire, vous trouverez la liste des app à sauvegarder dans le fichier `/home/yunohost.app/fallback/app_list` et une configuration globale dans cet autre fichier `/home/yunohost.app/fallback/config.conf`. 5 | 6 | ## Informations additionnelles 7 | 8 | ### Comment ça fonctionne 9 | 10 | Cette app est consitutée de 2 parties, vous devez l'installer avec l'option `main server` sur votre serveur principal, et une seconde fois, avec l'option `fallback server` sur l'autre serveur, qui vous voulez utiliser comme serveur de secours. 11 | > Vous devriez garder cet autre serveur uniquement pour cet usage. Ou alors pour y mettre quelques autres backups. Et bien sûr, il est préférable que ce serveur soit à un autre endroit. 12 | > Afin de simplifier l'usage des 'actions', le serveur de secours devrait bénéficier d'un nom de domaine associé, comme fallback.mondomain.tld 13 | 14 | Après l'installation, chaque nuit, le serveur principal va faire des sauvegardes et les envoyer sur votre serveur de secours. 15 | Au minimum, il fera une sauvegarde du système. Vous pouvez demander la sauvegarde de vos applications aussi, en éditant le fichier `/home/yunohost.app/fallback/app_list` 16 | Avant de faire un backup, il vérifiera avec celui de la nuit précédente. Et fera une nouvelle sauvegarde seulement si il y a quelque chose de nouveau. Afin de préserver votre bande passante. 17 | > Ces backups seront chiffrés, sauf si vous avez demandé l'inverse. 18 | 19 | Si vous avez un problème avec votre serveur principal, vous pouvez maintenant utiliser votre serveur de secours, restaurer votre sauvegarde de la nuit dernière, et utiliser ce serveur le temps de la panne. 20 | Voyons comment ça marche. 21 | 22 | #### Que dois-je faire en cas de panne de mon serveur principal ? 23 | 24 | Voilà, nous y sommes, votre serveur principal est panne, fallait bien que ça arrive ! 25 | Pas d'inquiétude, sautez sur votre serveur de secours et utiliser le script de déploiement. 26 | `/home/yunohost.app/fallback/deploy_fallback` 27 | > Vous pouvez également utiliser l'action 'Deploy the fallback server.' depuis votre panel administrateur. 28 | 29 | Ce script va commencer par faire un backup de votre serveur de secours, puis restaurer le backup de votre serveur principal. 30 | Cette restauration va transformer votre serveur de secours en lui donnant la configuration de votre serveur principal. Ensuite, il va restaurer les applications sélectionnées dans votre fichier app_list. 31 | A présent, ce serveur va devenir votre serveur principal, recevoir vos mails et faire tourner vos apps. 32 | > En fait, il y a juste un "petit détail", il faut modifier votre dns pour indiquer la nouvelle adresse de votre serveur. Voyons ça à la fin de cette doc. 33 | 34 | #### Bon, maintenant mon serveur est réparé. Mais j'ai besoin de récupérer ce qui s'est passé sur mon serveur de secours. 35 | 36 | Si vous avez terminé avec votre serveur de secours, utiliser l'autre script, juste à côté du précédent. 37 | `/home/yunohost.app/fallback/close_fallback` 38 | > Vous pouvez également utiliser l'action 'Close the fallback server.' depuis votre panel administrateur. 39 | 40 | Ce script va faire un backup du système de votre serveur de secours et des apps précédemment restaurées. Et mettre ces backups de côtés. 41 | 42 | Ensuite, il va nettoyer le système et restaurer le backup créé lors de l'exécution du script `deploy_fallback`. Ainsi, rien ne se sera passé sur ce server. 43 | 44 | Donc, toutes vos données produites sur votre serveur de secours sont maintenant mise de côté. Vous attendant gentillement. 45 | Retourner donc sur votre serveur principal et utiliser ce script. 46 | `/home/yunohost.app/fallback/update_from_fallback` 47 | > Vous pouvez également utiliser l'action 'Update from your fallback server' depuis votre panel administrateur. 48 | 49 | Pour terminer, ce script va télécharger les backups depuis votre serveur de secours et les restaurer sur votre serveur principal. Pour mettre à jour vos données et garder votre serveur principal à jour avec ce que vous avez fait sur le serveur de secours. 50 | Pour être plus prudent, chaque restauration sera précédée d'un backup, juste au cas où. 51 | 52 | #### Et... Comment je suis censé changer mon IP rapidement dans les dns ? 53 | 54 | C'est une question difficile... 55 | Et ça nécessite plus d'expérimentation... 56 | Mais, il y a un moyen simple de faire ça. Utiliser une entrée de dns dynamique chez votre registrar (si il vous le permet), même si vous avez une IP statique. Et mettez à jour cette IP si vous devez basculer sur votre serveur de secours. 57 | Selon votre registrar, vous devriez disposer d'un outil en ligne de commande pour faire simplement. 58 | -------------------------------------------------------------------------------- /doc/screenshots/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YunoHost-Apps/fallback_ynh/7c5711d7e88db56ed6522045d06d457b7a3bc681/doc/screenshots/.gitkeep -------------------------------------------------------------------------------- /hooks/post_app_install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | app=$YNH_APP_INSTANCE_NAME 4 | final_path=__FINALPATH__ 5 | 6 | app_list="$final_path/send_process/app_list" 7 | 8 | if ! grep ": $app\$" "$app_list" 9 | then 10 | echo "[]: $app" >> "$app_list" 11 | sort "$app_list" --output="$app_list" 12 | fi 13 | -------------------------------------------------------------------------------- /hooks/post_app_remove: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | app=$YNH_APP_INSTANCE_NAME 4 | final_path=__FINALPATH__ 5 | 6 | app_list="$final_path/send_process/app_list" 7 | 8 | if grep ": $app\$" "$app_list" 9 | then 10 | sed -i "/: $app\$/d" "$app_list" 11 | sort "$app_list" --output="$app_list" 12 | fi 13 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Fallback server", 3 | "id": "fallback", 4 | "packaging_format": 1, 5 | "description": { 6 | "en": "YunoHost Fallback server", 7 | "fr": "Serveur de secours YunoHost" 8 | }, 9 | "version": "0.93~ynh1", 10 | "url": "https://github.com/maniackcrudelis/Fallback-server", 11 | "upstream": { 12 | "license": "GPL-3.0", 13 | "website": "https://github.com/maniackcrudelis/Fallback-server", 14 | "code": "https://github.com/maniackcrudelis/Fallback-server" 15 | }, 16 | "license": "GPL-3.0", 17 | "maintainer": { 18 | "name": "", 19 | "email": "" 20 | }, 21 | "previous_maintainers": [{ 22 | "name": "Maniack Crudelis", 23 | "email": "maniackc_dev@crudelis.fr" 24 | }], 25 | "requirements": { 26 | "yunohost": ">= 4.3.0" 27 | }, 28 | "multi_instance": false, 29 | "services": [ 30 | ], 31 | "arguments": { 32 | "install": [ 33 | { 34 | "name": "install_type", 35 | "type": "string", 36 | "ask": { 37 | "en": "Choose which kind of installation you want.", 38 | "fr": "Choisissez le type d'installation que vous souhaitez" 39 | }, 40 | "choices": ["main server", "fallback server"], 41 | "default": "main server", 42 | "help": { 43 | "en": "Choose 'main server' if you make an installation on your real server. Or 'fallback server' if it's your backup server.", 44 | "fr": "Choisissez 'main server' si vous effectuez une installation sur votre vrai serveur. Ou 'fallback server' si c'est votre serveur de secours." 45 | } 46 | }, 47 | { 48 | "name": "encrypt", 49 | "type": "boolean", 50 | "ask": { 51 | "en": "[main server only] Do you want to encrypt your backups ?", 52 | "fr": "[main server seulement] Voulez-vous chiffrer vos sauvegardes ?" 53 | }, 54 | "default": true, 55 | "help": { 56 | "en": "You should desactive the encryption only if your fallback server is really safe.", 57 | "fr": "Vous ne devriez désactiver le chiffrement que si le serveur de secours est vraiment sûr." 58 | } 59 | }, 60 | { 61 | "name": "encryption_pwd", 62 | "type": "password", 63 | "ask": { 64 | "en": "[main server only] Set the password for encryption.", 65 | "fr": "[main server seulement] Définissez le mot de passe de chiffrement." 66 | }, 67 | "help": { 68 | "en": "It's needed if you not turn off the encryption.", 69 | "fr": "C'est nécessaire si vous n'avez pas désactivé le chiffrement." 70 | }, 71 | "optional": true 72 | }, 73 | { 74 | "name": "ssh_host", 75 | "type": "string", 76 | "ask": { 77 | "en": "[main server only] Set the domain name (or ip adress) for the fallback server.", 78 | "fr": "[main server seulement] Définissez le nom de domaine (ou l'adresse ip) du serveur de secours." 79 | }, 80 | "example": "domain.tld", 81 | "help": { 82 | "en": "This server has to be up, for the ssh-keyscan command.", 83 | "fr": "Ce serveur doit être en route, pour la commande ssh-keyscan." 84 | }, 85 | "optional": true 86 | }, 87 | { 88 | "name": "ssh_port", 89 | "type": "string", 90 | "ask": { 91 | "en": "[main server only] Set the port for the ssh connection.", 92 | "fr": "[main server seulement] Définissez le port pour la connexion ssh." 93 | }, 94 | "default": "22", 95 | "optional": true 96 | }, 97 | { 98 | "name": "pub_key", 99 | "type": "string", 100 | "ask": { 101 | "en": "[fallback server only] Put here the public ssh key.", 102 | "fr": "[fallback server seulement] Placez ici la clé publique ssh." 103 | }, 104 | "help": { 105 | "en": "The public key will be given at the end of the install process for the main server.", 106 | "fr": "La clé publique ssh vous sera fournie à la fin de l'installation du serveur principal." 107 | }, 108 | "optional": true 109 | }, 110 | { 111 | "name": "auto_detect_failure", 112 | "type": "boolean", 113 | "ask": { 114 | "en": "[fallback server only] Auto detect a failure of the main server ?", 115 | "fr": "[fallback server seulement] Détection automatique d'une panne du serveur principal ?" 116 | }, 117 | "default": true 118 | }, 119 | { 120 | "name": "delay_before_incident", 121 | "type": "string", 122 | "ask": { 123 | "en": "[fallback server only] Delay before declaring an incident with the main server.", 124 | "fr": "[fallback server seulement] Délai avant de déclarer un incident avec le serveur principal." 125 | }, 126 | "help": { 127 | "en": "Only for failure auto detection.", 128 | "fr": "Uniquement pour la détection automatique de panne." 129 | }, 130 | "choices": ["5min", "1h", "4h", "8h", "12h", "24h"], 131 | "default": "1h", 132 | "optional": true 133 | }, 134 | { 135 | "name": "contact_mail", 136 | "type": "string", 137 | "ask": { 138 | "en": "[fallback server only] Email address to contact in case of failure.", 139 | "fr": "[fallback server seulement] Adresse e-mail à contacter en cas de panne." 140 | }, 141 | "help": { 142 | "en": "Only for failure auto detection.
Should be obviously an address on another server !", 143 | "fr": "Uniquement pour la détection automatique de panne.
Devrait évidemment être une adresse sur un autre serveur !" 144 | }, 145 | "optional": true 146 | }, 147 | { 148 | "name": "auto_deploy", 149 | "type": "boolean", 150 | "ask": { 151 | "en": "[fallback server only] Deploy automatically the fallback in case of failure.", 152 | "fr": "[fallback server seulement] Déployer automatiquement le fallback en cas de panne." 153 | }, 154 | "help": { 155 | "en": "Only for failure auto detection.", 156 | "fr": "Uniquement pour la détection automatique de panne." 157 | }, 158 | "default": false 159 | } 160 | ] 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /scripts/_common.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # COMMON VARIABLES 5 | #================================================= 6 | 7 | # dependencies used by the app 8 | pkg_dependencies="ccrypt rsync mlocate" 9 | 10 | #================================================= 11 | # PACKAGE CHECK BYPASSING... 12 | #================================================= 13 | 14 | IS_PACKAGE_CHECK () { 15 | if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ] 16 | then 17 | return 0 18 | else 19 | return 1 20 | fi 21 | } 22 | 23 | #================================================= 24 | # FUTUR OFFICIAL HELPERS 25 | #================================================= 26 | 27 | 28 | #================================================= 29 | # EXPERIMENTAL HELPERS 30 | #================================================= 31 | 32 | # Send an email to inform the administrator 33 | # 34 | # usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type] 35 | # | arg: -m --app_message= - The file with the content to send to the administrator. 36 | # | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root 37 | # example: "root admin@domain" 38 | # If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you 39 | # example: "root admin@domain user1 user2" 40 | # | arg: -t, --type= - Type of mail, could be 'backup', 'change_url', 'install', 'remove', 'restore', 'upgrade' 41 | ynh_send_readme_to_admin() { 42 | # Declare an array to define the options of this helper. 43 | declare -Ar args_array=( [m]=app_message= [r]=recipients= [t]=type= ) 44 | local app_message 45 | local recipients 46 | local type 47 | # Manage arguments with getopts 48 | 49 | ynh_handle_getopts_args "$@" 50 | app_message="${app_message:-}" 51 | recipients="${recipients:-root}" 52 | type="${type:-install}" 53 | 54 | # Get the value of admin_mail_html 55 | admin_mail_html=$(ynh_app_setting_get $app admin_mail_html) 56 | admin_mail_html="${admin_mail_html:-0}" 57 | 58 | # Retrieve the email of users 59 | find_mails () { 60 | local list_mails="$1" 61 | local mail 62 | local recipients=" " 63 | # Read each mail in argument 64 | for mail in $list_mails 65 | do 66 | # Keep root or a real email address as it is 67 | if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@" 68 | then 69 | recipients="$recipients $mail" 70 | else 71 | # But replace an user name without a domain after by its email 72 | if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null) 73 | then 74 | recipients="$recipients $mail" 75 | fi 76 | fi 77 | done 78 | echo "$recipients" 79 | } 80 | recipients=$(find_mails "$recipients") 81 | 82 | # Subject base 83 | local mail_subject="☁️🆈🅽🅷☁️: \`$app\`" 84 | 85 | # Adapt the subject according to the type of mail required. 86 | if [ "$type" = "backup" ]; then 87 | mail_subject="$mail_subject has just been backup." 88 | elif [ "$type" = "change_url" ]; then 89 | mail_subject="$mail_subject has just been moved to a new URL!" 90 | elif [ "$type" = "remove" ]; then 91 | mail_subject="$mail_subject has just been removed!" 92 | elif [ "$type" = "restore" ]; then 93 | mail_subject="$mail_subject has just been restored!" 94 | elif [ "$type" = "upgrade" ]; then 95 | mail_subject="$mail_subject has just been upgraded!" 96 | else # install 97 | mail_subject="$mail_subject has just been installed!" 98 | fi 99 | 100 | local mail_message="This is an automated message from your beloved YunoHost server. 101 | 102 | Specific information for the application $app. 103 | 104 | $(if [ -n "$app_message" ] 105 | then 106 | cat "$app_message" 107 | else 108 | echo "...No specific information..." 109 | fi) 110 | 111 | --- 112 | Automatic diagnosis data from YunoHost 113 | 114 | __PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')__PRE_TAG2__" 115 | 116 | # Store the message into a file for further modifications. 117 | echo "$mail_message" > mail_to_send 118 | 119 | # If a html email is required. Apply html tags to the message. 120 | if [ "$admin_mail_html" -eq 1 ] 121 | then 122 | # Insert 'br' tags at each ending of lines. 123 | ynh_replace_string "$" "
" mail_to_send 124 | 125 | # Insert starting HTML tags 126 | sed --in-place '1s@^@\n\n\n\n@' mail_to_send 127 | 128 | # Keep tabulations 129 | ynh_replace_string " " "\ \ " mail_to_send 130 | ynh_replace_string "\t" "\ \ " mail_to_send 131 | 132 | # Insert url links tags 133 | ynh_replace_string "__URL_TAG1__\(.*\)__URL_TAG2__\(.*\)__URL_TAG3__" "\1" mail_to_send 134 | 135 | # Insert pre tags 136 | ynh_replace_string "__PRE_TAG1__" "
" mail_to_send
137 | 		ynh_replace_string "__PRE_TAG2__" "<\pre>" mail_to_send
138 | 
139 | 		# Insert finishing HTML tags
140 | 		echo -e "\n\n" >> mail_to_send
141 | 
142 | 	# Otherwise, remove tags to keep a plain text.
143 | 	else
144 | 		# Remove URL tags
145 | 		ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send
146 | 		ynh_replace_string "__URL_TAG2__" ": " mail_to_send
147 | 
148 | 		# Remove PRE tags
149 | 		ynh_replace_string "__PRE_TAG[1-2]__" "" mail_to_send
150 | 	fi
151 | 
152 | 	# Define binary to use for mail command
153 | 	if [ -e /usr/bin/bsd-mailx ]
154 | 	then
155 | 		local mail_bin=/usr/bin/bsd-mailx
156 | 	else
157 | 		local mail_bin=/usr/bin/mail.mailutils
158 | 	fi
159 | 
160 | 	if [ "$admin_mail_html" -eq 1 ]
161 | 	then
162 | 		content_type="text/html"
163 | 	else
164 | 		content_type="text/plain"
165 | 	fi
166 | 
167 | 	# Send the email to the recipients
168 | 	cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients"
169 | }
170 | 
171 | #=================================================
172 | 
173 | ynh_maintenance_mode_ON () {
174 | 	# Load value of $path_url and $domain from the config if their not set
175 | 	if [ -z $path_url ]; then
176 | 		path_url=$(ynh_app_setting_get $app path)
177 | 	fi
178 | 	if [ -z $domain ]; then
179 | 		domain=$(ynh_app_setting_get $app domain)
180 | 	fi
181 | 
182 | 	mkdir -p /var/www/html/
183 | 	
184 | 	# Create an html to serve as maintenance notice
185 | 	echo "
186 | 
187 | 
188 | 
189 | Your app $app is currently under maintenance!
190 | 
196 | 
197 | 
198 | 

Your app $app is currently under maintenance!

199 |

This app has been put under maintenance by your administrator at $(date)

200 |

Please wait until the maintenance operation is done. This page will be reloaded as soon as your app will be back.

201 | 202 | 203 | " > "/var/www/html/maintenance.$app.html" 204 | 205 | # Create a new nginx config file to redirect all access to the app to the maintenance notice instead. 206 | echo "# All request to the app will be redirected to ${path_url}_maintenance and fall on the maintenance notice 207 | rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/? redirect; 208 | # Use another location, to not be in conflict with the original config file 209 | location ${path_url}_maintenance/ { 210 | alias /var/www/html/ ; 211 | 212 | try_files maintenance.$app.html =503; 213 | 214 | # Include SSOWAT user panel. 215 | include conf.d/yunohost_panel.conf.inc; 216 | }" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" 217 | 218 | # The current config file will redirect all requests to the root of the app. 219 | # To keep the full path, we can use the following rewrite rule: 220 | # rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/\$1? redirect; 221 | # The difference will be in the $1 at the end, which keep the following queries. 222 | # But, if it works perfectly for a html request, there's an issue with any php files. 223 | # This files are treated as simple files, and will be downloaded by the browser. 224 | # Would be really be nice to be able to fix that issue. So that, when the page is reloaded after the maintenance, the user will be redirected to the real page he was. 225 | 226 | systemctl reload nginx 227 | } 228 | 229 | ynh_maintenance_mode_OFF () { 230 | # Load value of $path_url and $domain from the config if their not set 231 | if [ -z $path_url ]; then 232 | path_url=$(ynh_app_setting_get $app path) 233 | fi 234 | if [ -z $domain ]; then 235 | domain=$(ynh_app_setting_get $app domain) 236 | fi 237 | 238 | # Rewrite the nginx config file to redirect from ${path_url}_maintenance to the real url of the app. 239 | echo "rewrite ^${path_url}_maintenance/(.*)$ ${path_url}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" 240 | systemctl reload nginx 241 | 242 | # Sleep 4 seconds to let the browser reload the pages and redirect the user to the app. 243 | sleep 4 244 | 245 | # Then remove the temporary files used for the maintenance. 246 | rm "/var/www/html/maintenance.$app.html" 247 | rm "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" 248 | 249 | systemctl reload nginx 250 | } 251 | 252 | #================================================= 253 | 254 | # Create a changelog for an app after an upgrade. 255 | # 256 | # The changelog is printed into the file ./changelog for the time of the upgrade. 257 | # 258 | # In order to create a changelog, ynh_app_changelog will get info from /etc/yunohost/apps/$app/status.json 259 | # In order to find the current commit use by the app. 260 | # The remote repository, and the branch. 261 | # The changelog will be only the commits since the current revision. 262 | # 263 | # Because of the need of those info, ynh_app_changelog works only 264 | # with apps that have been installed from a list. 265 | # 266 | # usage: ynh_app_changelog 267 | ynh_app_changelog () { 268 | get_value_from_settings () 269 | { 270 | local value="$1" 271 | # Extract a value from the status.json file of an installed app. 272 | 273 | grep "$value\": \"" /etc/yunohost/apps/$app/status.json | sed "s/.*$value\": \"\([^\"]*\).*/\1/" 274 | } 275 | 276 | local current_revision="$(get_value_from_settings revision)" 277 | local repo="$(get_value_from_settings url)" 278 | local branch="$(get_value_from_settings branch)" 279 | # ynh_app_changelog works only with an app installed from a list. 280 | if [ -z "$current_revision" ] || [ -z "$repo" ] || [ -z "$branch" ] 281 | then 282 | ynh_print_warn "Unable to build the changelog..." 283 | touch changelog 284 | return 0 285 | fi 286 | 287 | # Fetch the history of the repository, without cloning it 288 | mkdir git_history 289 | (cd git_history 290 | ynh_exec_warn_less git init 291 | ynh_exec_warn_less git remote add -f origin $repo 292 | # Get the line of the current commit of the installed app in the history. 293 | local line_to_head=$(git log origin/$branch --pretty=oneline | grep --line-number "$current_revision" | cut -d':' -f1) 294 | # Cut the history before the current commit, to keep only newer commits. 295 | # Then use sed to reorganise each lines and have a nice list of commits since the last upgrade. 296 | # This list is redirected into the file changelog 297 | git log origin/$branch --pretty=oneline | head --lines=$(($line_to_head-1)) | sed 's/^\([[:alnum:]]*\)\(.*\)/*(\1) -> \2/g' > ../changelog) 298 | # Remove 'Merge pull request' commits 299 | sed -i '/Merge pull request #[[:digit:]]* from/d' changelog 300 | # As well as conflict resolving commits 301 | sed -i '/Merge branch .* into/d' changelog 302 | 303 | # Get the value of admin_mail_html 304 | admin_mail_html=$(ynh_app_setting_get $app admin_mail_html) 305 | admin_mail_html="${admin_mail_html:-0}" 306 | 307 | # If a html email is required. Apply html to the changelog. 308 | if [ "$admin_mail_html" -eq 1 ] 309 | then 310 | sed -in-place "s@\*(\([[:alnum:]]*\)) -> \(.*\)@* __URL_TAG1__\2__URL_TAG2__${repo}/commit/\1__URL_TAG3__@g" changelog 311 | fi 312 | } 313 | 314 | #================================================= 315 | 316 | # Check the amount of available RAM 317 | # 318 | # usage: ynh_check_ram [--required=RAM required in Mb] [--no_swap|--only_swap] [--free_ram] 319 | # | arg: -r, --required= - Amount of RAM required in Mb. The helper will return 0 is there's enough RAM, or 1 otherwise. 320 | # If --required isn't set, the helper will print the amount of RAM, in Mb. 321 | # | arg: -s, --no_swap - Ignore swap 322 | # | arg: -o, --only_swap - Ignore real RAM, consider only swap. 323 | # | arg: -f, --free_ram - Count only free RAM, not the total amount of RAM available. 324 | ynh_check_ram () { 325 | # Declare an array to define the options of this helper. 326 | declare -Ar args_array=( [r]=required= [s]=no_swap [o]=only_swap [f]=free_ram ) 327 | local required 328 | local no_swap 329 | local only_swap 330 | # Manage arguments with getopts 331 | ynh_handle_getopts_args "$@" 332 | required=${required:-} 333 | no_swap=${no_swap:-0} 334 | only_swap=${only_swap:-0} 335 | 336 | local total_ram=$(vmstat --stats --unit M | grep "total memory" | awk '{print $1}') 337 | local total_swap=$(vmstat --stats --unit M | grep "total swap" | awk '{print $1}') 338 | local total_ram_swap=$(( total_ram + total_swap )) 339 | 340 | local free_ram=$(vmstat --stats --unit M | grep "free memory" | awk '{print $1}') 341 | local free_swap=$(vmstat --stats --unit M | grep "free swap" | awk '{print $1}') 342 | local free_ram_swap=$(( free_ram + free_swap )) 343 | 344 | # Use the total amount of ram 345 | local ram=$total_ram_swap 346 | if [ $free_ram -eq 1 ] 347 | then 348 | # Use the total amount of free ram 349 | ram=$free_ram_swap 350 | if [ $no_swap -eq 1 ] 351 | then 352 | # Use only the amount of free ram 353 | ram=$free_ram 354 | elif [ $only_swap -eq 1 ] 355 | then 356 | # Use only the amount of free swap 357 | ram=$free_swap 358 | fi 359 | else 360 | if [ $no_swap -eq 1 ] 361 | then 362 | # Use only the amount of free ram 363 | ram=$total_ram 364 | elif [ $only_swap -eq 1 ] 365 | then 366 | # Use only the amount of free swap 367 | ram=$total_swap 368 | fi 369 | fi 370 | 371 | if [ -n "$required" ] 372 | then 373 | # Return 1 if the amount of ram isn't enough. 374 | if [ $ram -lt $required ] 375 | then 376 | return 1 377 | else 378 | return 0 379 | fi 380 | 381 | # If no RAM is required, return the amount of available ram. 382 | else 383 | echo $ram 384 | fi 385 | } 386 | -------------------------------------------------------------------------------- /scripts/actions/clean_backups: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # GENERIC STARTING 5 | #================================================= 6 | # IMPORT GENERIC HELPERS 7 | #================================================= 8 | 9 | source scripts/_common.sh 10 | source /usr/share/yunohost/helpers 11 | 12 | #================================================= 13 | # MANAGE SCRIPT FAILURE 14 | #================================================= 15 | 16 | # Exit if an error occurs during the execution of the script 17 | ynh_abort_if_errors 18 | 19 | #================================================= 20 | # RETRIEVE ARGUMENTS 21 | #================================================= 22 | 23 | app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} 24 | 25 | final_path=$(ynh_app_setting_get --app=$app --key=final_path) 26 | install_type=$(ynh_app_setting_get --app=$app --key=install_type) 27 | 28 | #================================================= 29 | # CHECK IF ARGUMENTS ARE CORRECT 30 | #================================================= 31 | 32 | #================================================= 33 | # CHECK IF AN ACTION HAS TO BE DONE 34 | #================================================= 35 | 36 | if [ "$install_type" == "fallback" ] 37 | then 38 | ynh_die --message="This action can be performed only on a Main server type installation of the app." --ret_code=0 39 | fi 40 | 41 | #================================================= 42 | # SPECIFIC ACTION 43 | #================================================= 44 | # CLEAN ALL BACKUP FILES 45 | #================================================= 46 | ynh_script_progression --message="Cleaning all backup files" --weight=9 47 | 48 | # Get the backup directory from the config file 49 | backup_dir="$(grep "^main_storage_dir=" "$final_path/send_process/config.conf" | cut -d= -f2)" 50 | 51 | while read backup_file <&3 52 | do 53 | if [ -n "$backup_file" ] 54 | then 55 | ynh_print_info --message="Clean backup file $backup_file" 56 | ynh_secure_remove --file="$backup_dir/backup/$backup_file" 57 | fi 58 | done 3<<< $(ls -1 "$backup_dir/backup" | grep ".tar.gz$") 59 | 60 | #================================================= 61 | # END OF SCRIPT 62 | #================================================= 63 | 64 | ynh_script_progression --message="Execution completed" --last 65 | -------------------------------------------------------------------------------- /scripts/actions/close_fallback: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # GENERIC STARTING 5 | #================================================= 6 | # IMPORT GENERIC HELPERS 7 | #================================================= 8 | 9 | source scripts/_common.sh 10 | source /usr/share/yunohost/helpers 11 | 12 | #================================================= 13 | # MANAGE SCRIPT FAILURE 14 | #================================================= 15 | 16 | # Exit if an error occurs during the execution of the script 17 | ynh_abort_if_errors 18 | 19 | #================================================= 20 | # RETRIEVE ARGUMENTS 21 | #================================================= 22 | 23 | app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} 24 | 25 | final_path=$(ynh_app_setting_get --app=$app --key=final_path) 26 | install_type=$(ynh_app_setting_get --app=$app --key=install_type) 27 | 28 | #================================================= 29 | # CHECK IF ARGUMENTS ARE CORRECT 30 | #================================================= 31 | 32 | #================================================= 33 | # CHECK IF AN ACTION HAS TO BE DONE 34 | #================================================= 35 | 36 | if [ "$install_type" == "main" ] 37 | then 38 | ynh_die --message="This action can be performed only on a Fallback server type installation of the app." --ret_code=0 39 | fi 40 | 41 | #================================================= 42 | # SPECIFIC ACTION 43 | #================================================= 44 | # FORCE A NEW BACKUP 45 | #================================================= 46 | ynh_script_progression --message="Closing the fallback..." --weight=9 47 | 48 | if IS_PACKAGE_CHECK 49 | then 50 | ynh_print_info --message="Do not alter the status of the fallback in Package_check." 51 | else 52 | ynh_exec_warn $final_path/deploy_process/close_fallback.sh auto 53 | fi 54 | 55 | #================================================= 56 | # END OF SCRIPT 57 | #================================================= 58 | 59 | ynh_script_progression --message="Execution completed" --last 60 | -------------------------------------------------------------------------------- /scripts/actions/deploy_fallback: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # GENERIC STARTING 5 | #================================================= 6 | # IMPORT GENERIC HELPERS 7 | #================================================= 8 | 9 | source scripts/_common.sh 10 | source /usr/share/yunohost/helpers 11 | 12 | #================================================= 13 | # MANAGE SCRIPT FAILURE 14 | #================================================= 15 | 16 | # Exit if an error occurs during the execution of the script 17 | ynh_abort_if_errors 18 | 19 | #================================================= 20 | # RETRIEVE ARGUMENTS 21 | #================================================= 22 | 23 | app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} 24 | 25 | final_path=$(ynh_app_setting_get --app=$app --key=final_path) 26 | install_type=$(ynh_app_setting_get --app=$app --key=install_type) 27 | 28 | #================================================= 29 | # CHECK IF ARGUMENTS ARE CORRECT 30 | #================================================= 31 | 32 | #================================================= 33 | # CHECK IF AN ACTION HAS TO BE DONE 34 | #================================================= 35 | 36 | if [ "$install_type" == "main" ] 37 | then 38 | ynh_die --message="This action can be performed only on a Fallback server type installation of the app." --ret_code=0 39 | fi 40 | 41 | #================================================= 42 | # SPECIFIC ACTION 43 | #================================================= 44 | # FORCE A NEW BACKUP 45 | #================================================= 46 | ynh_script_progression --message="Deploying the fallback..." --weight=9 47 | 48 | if IS_PACKAGE_CHECK 49 | then 50 | ynh_print_info --message="Do not actually deploy the fallback in Package_check." 51 | else 52 | ynh_exec_warn $final_path/deploy_process/deploy_fallback.sh auto 53 | fi 54 | 55 | #================================================= 56 | # END OF SCRIPT 57 | #================================================= 58 | 59 | ynh_script_progression --message="Execution completed" --last 60 | -------------------------------------------------------------------------------- /scripts/actions/force_backup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # GENERIC STARTING 5 | #================================================= 6 | # IMPORT GENERIC HELPERS 7 | #================================================= 8 | 9 | source scripts/_common.sh 10 | source /usr/share/yunohost/helpers 11 | 12 | #================================================= 13 | # MANAGE SCRIPT FAILURE 14 | #================================================= 15 | 16 | # Exit if an error occurs during the execution of the script 17 | ynh_abort_if_errors 18 | 19 | #================================================= 20 | # RETRIEVE ARGUMENTS 21 | #================================================= 22 | 23 | app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} 24 | 25 | final_path=$(ynh_app_setting_get --app=$app --key=final_path) 26 | install_type=$(ynh_app_setting_get --app=$app --key=install_type) 27 | 28 | #================================================= 29 | # CHECK IF ARGUMENTS ARE CORRECT 30 | #================================================= 31 | 32 | #================================================= 33 | # CHECK IF AN ACTION HAS TO BE DONE 34 | #================================================= 35 | 36 | if [ "$install_type" == "fallback" ] 37 | then 38 | ynh_die --message="This action can be performed only on a Main server type installation of the app." --ret_code=0 39 | fi 40 | 41 | #================================================= 42 | # SPECIFIC ACTION 43 | #================================================= 44 | # FORCE A NEW BACKUP 45 | #================================================= 46 | ynh_script_progression --message="Forcing a new backup..." --weight=9 47 | 48 | ynh_exec_warn nice -n10 $final_path/send_process/send_backup.sh 49 | 50 | #================================================= 51 | # END OF SCRIPT 52 | #================================================= 53 | 54 | ynh_script_progression --message="Execution completed" --last 55 | -------------------------------------------------------------------------------- /scripts/actions/reset_default_config: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # GENERIC STARTING 5 | #================================================= 6 | # IMPORT GENERIC HELPERS 7 | #================================================= 8 | 9 | source scripts/_common.sh 10 | source /usr/share/yunohost/helpers 11 | 12 | #================================================= 13 | # MANAGE SCRIPT FAILURE 14 | #================================================= 15 | 16 | # Exit if an error occurs during the execution of the script 17 | ynh_abort_if_errors 18 | 19 | #================================================= 20 | # RETRIEVE ARGUMENTS 21 | #================================================= 22 | 23 | app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} 24 | 25 | final_path=$(ynh_app_setting_get --app=$app --key=final_path) 26 | ssh_host=$(ynh_app_setting_get --app=$app --key=ssh_host) 27 | ssh_port=$(ynh_app_setting_get --app=$app --key=ssh_port) 28 | encrypt=$(ynh_app_setting_get --app=$app --key=encrypt) 29 | delay_before_incident=$(ynh_app_setting_get --app=$app --key=delay_before_incident) 30 | contact_mail=$(ynh_app_setting_get --app=$app --key=contact_mail) 31 | auto_deploy=$(ynh_app_setting_get --app=$app --key=auto_deploy) 32 | install_type=$(ynh_app_setting_get --app=$app --key=install_type) 33 | 34 | #================================================= 35 | # SORT OUT THE CONFIG FILE TO HANDLE 36 | #================================================= 37 | 38 | file="$1" 39 | 40 | if [ "$file" = "both" ]; then 41 | if [ "$install_type" = "main" ]; then 42 | config_file="$final_path/send_process/config.conf" 43 | else 44 | config_file="$final_path/deploy_process/auto_check.conf" 45 | fi 46 | fi 47 | 48 | #================================================= 49 | # SPECIFIC ACTION 50 | #================================================= 51 | # RESET THE CONFIG FILE 52 | #================================================= 53 | ynh_script_progression --message="Reseting the config file..." 54 | 55 | # Verify the checksum and backup the file if it's different 56 | ynh_backup_if_checksum_is_different --file="$config_file" 57 | 58 | if [ "$file" = "both" ] 59 | then 60 | if [ "$install_type" = "main" ] 61 | then 62 | # Get the default file and overwrite the current config 63 | cp "${config_file}.modele" "$config_file" 64 | 65 | # Recreate the default config 66 | ynh_replace_string --match_string="ssh_user=.*" --replace_string="ssh_user=$app" --target_file="$config_file" 67 | ynh_replace_string --match_string="ssh_host=.*" --replace_string="ssh_host=$ssh_host" --target_file="$config_file" 68 | ynh_replace_string --match_string="ssh_port=.*" --replace_string="ssh_port=$ssh_port" --target_file="$config_file" 69 | 70 | data_dir="/home/yunohost.app/$app/fallback_backup" 71 | ynh_replace_string --match_string="main_storage_dir=.*" --replace_string="main_storage_dir=$data_dir" --target_file="$config_file" 72 | ynh_replace_string --match_string="encrypt=.*" --replace_string="encrypt=$encrypt" --target_file="$config_file" 73 | 74 | ssh_key="$final_path/send_process/ssh_key" 75 | ynh_replace_string --match_string="ssh_key=.*" --replace_string="ssh_key=$ssh_key" --target_file="$config_file" 76 | 77 | passkey="$final_path/send_process/passkey" 78 | ynh_replace_string --match_string="pass_file=.*" --replace_string="pass_file=$passkey" --target_file="$config_file" 79 | else 80 | # Get the default file and overwrite the current config 81 | cp "${config_file}.modele" "$config_file" 82 | 83 | # Recreate the default config 84 | ynh_replace_string --match_string="delay_before_incident=.*" --replace_string="delay_before_incident=$delay_before_incident" --target_file="$config_file" 85 | ynh_replace_string --match_string="contact_mail=.*" --replace_string="contact_mail=$contact_mail" --target_file="$config_file" 86 | ynh_replace_string --match_string="auto_deploy=.*" --replace_string="auto_deploy=$auto_deploy" --target_file="$config_file" 87 | ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="$config_file" 88 | fi 89 | fi 90 | 91 | # Calculate and store the config file checksum into the app settings 92 | ynh_store_file_checksum --file="$config_file" 93 | 94 | #================================================= 95 | # END OF SCRIPT 96 | #================================================= 97 | 98 | ynh_script_progression --message="Execution completed" --last 99 | -------------------------------------------------------------------------------- /scripts/actions/update_dns: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # GENERIC STARTING 5 | #================================================= 6 | # IMPORT GENERIC HELPERS 7 | #================================================= 8 | 9 | source scripts/_common.sh 10 | source /usr/share/yunohost/helpers 11 | 12 | #================================================= 13 | # MANAGE SCRIPT FAILURE 14 | #================================================= 15 | 16 | # Exit if an error occurs during the execution of the script 17 | ynh_abort_if_errors 18 | 19 | #================================================= 20 | # RETRIEVE ARGUMENTS 21 | #================================================= 22 | 23 | app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} 24 | 25 | final_path=$(ynh_app_setting_get --app=$app --key=final_path) 26 | install_type=$(ynh_app_setting_get --app=$app --key=install_type) 27 | 28 | #================================================= 29 | # CHECK IF ARGUMENTS ARE CORRECT 30 | #================================================= 31 | 32 | #================================================= 33 | # CHECK IF AN ACTION HAS TO BE DONE 34 | #================================================= 35 | 36 | if [ "$install_type" == "main" ] 37 | then 38 | ynh_die --message="This action can be performed only on a Fallback server type installation of the app." --ret_code=0 39 | fi 40 | 41 | if [ $(grep "^auto_update_DNS=" "$final_path/deploy_process/auto_check.conf" | cut -d'=' -f2) -ne 1 ] 42 | then 43 | ynh_die --message="Please set the setting auto_update_DNS to 1 into your $final_path/deploy_process/auto_check.conf in order to use this action." --ret_code=0 44 | fi 45 | 46 | #================================================= 47 | # SPECIFIC ACTION 48 | #================================================= 49 | # GET DNS CONFIGURATION 50 | #================================================= 51 | ynh_script_progression --message="Checking DNS configuration of the fallback..." --weight=1 52 | 53 | # And the script to use to do it 54 | auto_update_script=$(grep "^auto_update_script=" "$final_path/deploy_process/auto_check.conf" | cut -d'=' -f2) 55 | 56 | if [ "auto_update_script" == "$final_path/DynHost/..." ] 57 | then 58 | ynh_die --message="Your current configuration in \"$final_path/deploy_process/auto_check.conf\" does not specify the script to use to update your DNS. Please configure a script to use and retry." --ret_code=0 59 | fi 60 | 61 | #================================================= 62 | # FORCE A NEW BACKUP 63 | #================================================= 64 | ynh_script_progression --message="Updating the DNS..." --weight=9 65 | 66 | ynh_exec_warn "$auto_update_script" 67 | 68 | #================================================= 69 | # END OF SCRIPT 70 | #================================================= 71 | 72 | ynh_script_progression --message="Execution completed" --last 73 | -------------------------------------------------------------------------------- /scripts/actions/update_from_fallback: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # GENERIC STARTING 5 | #================================================= 6 | # IMPORT GENERIC HELPERS 7 | #================================================= 8 | 9 | source scripts/_common.sh 10 | source /usr/share/yunohost/helpers 11 | 12 | #================================================= 13 | # MANAGE SCRIPT FAILURE 14 | #================================================= 15 | 16 | # Exit if an error occurs during the execution of the script 17 | ynh_abort_if_errors 18 | 19 | #================================================= 20 | # RETRIEVE ARGUMENTS 21 | #================================================= 22 | 23 | app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} 24 | 25 | final_path=$(ynh_app_setting_get --app=$app --key=final_path) 26 | install_type=$(ynh_app_setting_get --app=$app --key=install_type) 27 | 28 | #================================================= 29 | # CHECK IF ARGUMENTS ARE CORRECT 30 | #================================================= 31 | 32 | #================================================= 33 | # CHECK IF AN ACTION HAS TO BE DONE 34 | #================================================= 35 | 36 | if [ "$install_type" == "fallback" ] 37 | then 38 | ynh_die --message="This action can be performed only on a Main server type installation of the app." --ret_code=0 39 | fi 40 | 41 | #================================================= 42 | # SPECIFIC ACTION 43 | #================================================= 44 | # UPDATE THE SERVER FROM FALLBACK 45 | #================================================= 46 | ynh_script_progression --message="Updating the server from fallback..." --weight=9 47 | 48 | if IS_PACKAGE_CHECK 49 | then 50 | ynh_print_info --message="Do not alter the status of the fallback in Package_check." 51 | else 52 | ynh_exec_warn nice -n10 $final_path/update_from_fallback_process/update_from_fallback.sh auto 53 | fi 54 | 55 | #================================================= 56 | # END OF SCRIPT 57 | #================================================= 58 | 59 | ynh_script_progression --message="Execution completed" --last 60 | -------------------------------------------------------------------------------- /scripts/backup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # GENERIC START 5 | #================================================= 6 | # IMPORT GENERIC HELPERS 7 | #================================================= 8 | 9 | # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts 10 | source ../settings/scripts/_common.sh 11 | source /usr/share/yunohost/helpers 12 | 13 | #================================================= 14 | # MANAGE SCRIPT FAILURE 15 | #================================================= 16 | 17 | # Exit if an error occurs during the execution of the script 18 | ynh_abort_if_errors 19 | 20 | #================================================= 21 | # LOAD SETTINGS 22 | #================================================= 23 | ynh_print_info --message="Loading installation settings..." 24 | 25 | app=$YNH_APP_INSTANCE_NAME 26 | 27 | install_type=$(ynh_app_setting_get --app=$app --key=install_type) 28 | final_path=$(ynh_app_setting_get --app=$app --key=final_path) 29 | auto_detect_failure=$(ynh_app_setting_get --app=$app --key=auto_detect_failure) 30 | datadir=$(ynh_app_setting_get --app=$app --key=datadir) 31 | 32 | #================================================= 33 | # DECLARE DATA AND CONF FILES TO BACKUP 34 | #================================================= 35 | ynh_print_info --message="Declaring files to be backed up..." 36 | 37 | #================================================= 38 | # BACKUP THE APP MAIN DIR 39 | #================================================= 40 | 41 | ynh_backup --src_path="$final_path" 42 | 43 | #================================================= 44 | # BACKUP THE DATA DIR 45 | #================================================= 46 | 47 | ynh_backup --src_path="$datadir" --is_big 48 | 49 | #================================================= 50 | # SPECIFIC BACKUP 51 | #================================================= 52 | 53 | if [ "$install_type" == "main" ] 54 | then 55 | 56 | #================================================= 57 | # BACKUP LOGROTATE 58 | #================================================= 59 | 60 | ynh_backup --src_path="/etc/logrotate.d/$app" 61 | 62 | #================================================= 63 | # BACKUP THE CRON FILE 64 | #================================================= 65 | 66 | ynh_backup --src_path="/etc/cron.d/$app" 67 | else 68 | #================================================= 69 | # BACKUP USER DIRECTORIES 70 | #================================================= 71 | 72 | ynh_backup --src_path="/home/$app/bin" 73 | ynh_backup --src_path="/home/$app/lib" 74 | ynh_backup --src_path="/home/$app/lib64" 75 | ynh_backup --src_path="/home/$app/.ssh" 76 | 77 | #================================================= 78 | # BACKUP THE CRON FILE 79 | #================================================= 80 | 81 | if [ $auto_detect_failure -eq 1 ] 82 | then 83 | ynh_backup --src_path="/etc/cron.d/auto_deploy_fallback" 84 | fi 85 | fi 86 | 87 | #================================================= 88 | # END OF SCRIPT 89 | #================================================= 90 | 91 | ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." 92 | -------------------------------------------------------------------------------- /scripts/config: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # GENERIC STARTING 5 | #================================================= 6 | # IMPORT GENERIC HELPERS 7 | #================================================= 8 | 9 | source _common.sh 10 | source /usr/share/yunohost/helpers 11 | 12 | #================================================= 13 | # RETRIEVE ARGUMENTS 14 | #================================================= 15 | 16 | app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} 17 | 18 | final_path=$(ynh_app_setting_get --app=$app --key=final_path) 19 | install_type=$(ynh_app_setting_get --app=$app --key=install_type) 20 | 21 | #================================================= 22 | # SPECIFIC CODE 23 | #================================================= 24 | # DECLARE GENERIC FUNCTION 25 | #================================================= 26 | 27 | config_file_main="$final_path/send_process/config.conf" 28 | config_file_fallback="$final_path/deploy_process/auto_check.conf" 29 | 30 | passkey="$final_path/send_process/passkey" 31 | 32 | get_config_value() { 33 | option_name="$1" 34 | config_file=$2 35 | # Get the value of this option in the config file 36 | grep "^$option_name=" "${!config_file}" 2> /dev/null | cut -d= -f2 37 | } 38 | 39 | #================================================= 40 | # LOAD VALUES 41 | #================================================= 42 | 43 | # Load the real value from the app config or elsewhere. 44 | # Then get the value from the form. 45 | # If the form has a value for a variable, take the value from the form, 46 | # Otherwise, keep the value from the app config. 47 | 48 | # Encryption 49 | old_encrypt="$(get_config_value encrypt config_file_main)" 50 | encrypt="${YNH_CONFIG_MAIN_SERVER_ENCRYPTION_ENCRYPT:-$old_encrypt}" 51 | if [ -z "$encrypt" ]; then 52 | encrypt=0 53 | fi 54 | # Encryption password 55 | old_encrypt_password="$(cat $passkey 2> /dev/null)" 56 | encrypt_password="${YNH_CONFIG_MAIN_SERVER_ENCRYPTION_ENCRYPTION_PWD:-$old_encrypt_password}" 57 | 58 | # ssh_host 59 | old_ssh_host="$(get_config_value ssh_host config_file_main)" 60 | ssh_host="${YNH_CONFIG_MAIN_SERVER_SSH_CONFIG_SSH_HOST:-$old_ssh_host}" 61 | # ssh_port 62 | old_ssh_port="$(get_config_value ssh_port config_file_main)" 63 | ssh_port="${YNH_CONFIG_MAIN_SERVER_SSH_CONFIG_SSH_PORT:-$old_ssh_port}" 64 | 65 | # pub_key 66 | old_pub_key="$(ynh_app_setting_get --app=$app --key=pub_key)" 67 | pub_key="${YNH_CONFIG_FALLBACK_SERVER_SSH_CONFIG_PUB_KEY:-$old_pub_key}" 68 | # auto_detect_failure 69 | old_auto_detect_failure=$(ynh_app_setting_get --app=$app --key=auto_detect_failure) 70 | auto_detect_failure="${YNH_CONFIG_FALLBACK_SERVER_AUTO_DEPLOY_AUTO_DETECT_FAILURE:-$old_auto_detect_failure}" 71 | if [ -z "$auto_detect_failure" ]; then 72 | auto_detect_failure=0 73 | fi 74 | # delay_before_incident 75 | old_delay_before_incident="$(get_config_value delay_before_incident config_file_fallback)" 76 | delay_before_incident="${YNH_CONFIG_FALLBACK_SERVER_AUTO_DEPLOY_DELAY_BEFORE_INCIDENT:-$old_delay_before_incident}" 77 | # contact_mail 78 | old_contact_mail="$(get_config_value contact_mail config_file_fallback)" 79 | contact_mail="${YNH_CONFIG_FALLBACK_SERVER_AUTO_DEPLOY_CONTACT_MAIL:-$old_contact_mail}" 80 | # auto_deploy 81 | old_auto_deploy="$(get_config_value auto_deploy config_file_fallback)" 82 | auto_deploy="${YNH_CONFIG_FALLBACK_SERVER_AUTO_DEPLOY_AUTO_DEPLOY:-$old_auto_deploy}" 83 | if [ -z "$auto_deploy" ]; then 84 | auto_deploy=0 85 | fi 86 | 87 | # Type of admin mail configuration 88 | old_admin_mail_html="$(ynh_app_setting_get --app=$app --key=admin_mail_html)" 89 | admin_mail_html="${YNH_CONFIG_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_html}" 90 | 91 | #================================================= 92 | # SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND 93 | #================================================= 94 | 95 | show_config() { 96 | # here you are supposed to read some config file/database/other then print the values 97 | # ynh_return "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value" 98 | 99 | ynh_return "YNH_CONFIG_MAIN_SERVER_ENCRYPTION_ENCRYPT=$encrypt" 100 | ynh_return "YNH_CONFIG_MAIN_SERVER_ENCRYPTION_ENCRYPTION_PWD=" 101 | 102 | ynh_return "YNH_CONFIG_MAIN_SERVER_SSH_CONFIG_SSH_HOST=$ssh_host" 103 | ynh_return "YNH_CONFIG_MAIN_SERVER_SSH_CONFIG_SSH_PORT=$ssh_port" 104 | 105 | ynh_return "YNH_CONFIG_FALLBACK_SERVER_SSH_CONFIG_PUB_KEY=$pub_key" 106 | ynh_return "YNH_CONFIG_FALLBACK_SERVER_AUTO_DEPLOY_AUTO_DETECT_FAILURE=$auto_detect_failure" 107 | ynh_return "YNH_CONFIG_FALLBACK_SERVER_AUTO_DEPLOY_DELAY_BEFORE_INCIDENT=$delay_before_incident" 108 | ynh_return "YNH_CONFIG_FALLBACK_SERVER_AUTO_DEPLOY_CONTACT_MAIL=$contact_mail" 109 | ynh_return "YNH_CONFIG_FALLBACK_SERVER_AUTO_DEPLOY_AUTO_DEPLOY=$auto_deploy" 110 | 111 | ynh_return "YNH_CONFIG_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html" 112 | } 113 | 114 | #================================================= 115 | # MODIFY THE CONFIGURATION 116 | #================================================= 117 | 118 | apply_config() { 119 | if [ "$install_type" = "main" ] 120 | then 121 | # Change the password if needed 122 | if [ "$encrypt" = "1" ] 123 | then 124 | test -n "$encrypt_password" || ynh_die --message="The password for encryption can't be empty if you choose to enable encryption." 125 | # Replace the password by the previous one 126 | passkey="$final_path/send_process/passkey" 127 | echo "$encrypt_password" > "$passkey" 128 | chmod 400 "$passkey" 129 | ynh_replace_string --match_string="^pass_file=.*" --replace_string="pass_file=$passkey" --target_file="$config_file_main" 130 | fi 131 | 132 | # Change encrypt in the config file 133 | ynh_replace_string --match_string="^encrypt=.*" --replace_string="encrypt=$encrypt" --target_file="$config_file_main" 134 | 135 | # Change ssh_host in the config file 136 | ynh_replace_string --match_string="^ssh_host=.*" --replace_string="ssh_host=$ssh_host" --target_file="$config_file_main" 137 | # Change ssh_port in the config file 138 | ynh_replace_string --match_string="^ssh_port=.*" --replace_string="ssh_port=$ssh_port" --target_file="$config_file_main" 139 | 140 | else 141 | # Add the public ssh key to authorized_keys 142 | # Secure the ssh key 143 | pub_key="no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty $pub_key" 144 | # Then add the key 145 | grep --quiet "$pub_key" "/home/$app/.ssh/authorized_keys" || \ 146 | echo "$pub_key" >> "/home/$app/.ssh/authorized_keys" 147 | 148 | # Change auto_detect_failure feature 149 | if [ "$auto_detect_failure" = "1" ] && [ "$old_auto_detect_failure" = "0" ] 150 | then 151 | # Put in place the cron file 152 | ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="$final_path/deploy_process/auto_deploy_fallback.cron" 153 | cp $final_path/deploy_process/auto_deploy_fallback.cron /etc/cron.d/auto_deploy_fallback 154 | ynh_app_setting_set --app=$app --key=auto_detect_failure --value=1 155 | elif [ "$auto_detect_failure" = "0" ] && [ "$old_auto_detect_failure" = "1" ] 156 | then 157 | rm "/etc/cron.d/auto_deploy_fallback" 158 | ynh_app_setting_set --app=$app --key=auto_detect_failure --value=0 159 | fi 160 | # Change delay_before_incident in the config file 161 | ynh_replace_string --match_string="^delay_before_incident=.*" --replace_string="delay_before_incident=$delay_before_incident" --target_file="$config_file_fallback" 162 | ynh_app_setting_set --app=$app --key=delay_before_incident --value="$delay_before_incident" 163 | 164 | if [ $delay_before_incident -le 5 ] 165 | then 166 | cron_delay="*/1 *" 167 | elif [ $delay_before_incident -le 60 ] 168 | then 169 | cron_delay="*/10 *" 170 | elif [ $delay_before_incident -le 240 ] 171 | then 172 | cron_delay="*/30 *" 173 | else 174 | cron_delay="0 */1" 175 | fi 176 | # Reconfigure the cron file 177 | if [ -e "/etc/cron.d/auto_deploy_fallback" ] 178 | then 179 | ynh_replace_string --match_string="^.* root" --replace_string="$cron_delay * * * root" --target_file="/etc/cron.d/auto_deploy_fallback" 180 | fi 181 | # Change contact_mail in the config file 182 | ynh_replace_string --match_string="^contact_mail=.*" --replace_string="contact_mail=$contact_mail" --target_file="$config_file_fallback" 183 | ynh_app_setting_set --app=$app --key=contact_mail --value="$contact_mail" 184 | # Change auto_deploy in the config file 185 | ynh_replace_string --match_string="^auto_deploy=.*" --replace_string="auto_deploy=$auto_deploy" --target_file="$config_file_fallback" 186 | ynh_app_setting_set --app=$app --key=auto_deploy --value="$auto_deploy" 187 | fi 188 | 189 | # Set admin_mail_html 190 | ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html" 191 | } 192 | 193 | #================================================= 194 | # GENERIC FINALIZATION 195 | #================================================= 196 | ynh_app_config_run $1 197 | -------------------------------------------------------------------------------- /scripts/install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # GENERIC START 5 | #================================================= 6 | # IMPORT GENERIC HELPERS 7 | #================================================= 8 | 9 | source _common.sh 10 | source /usr/share/yunohost/helpers 11 | 12 | #================================================= 13 | # MANAGE SCRIPT FAILURE 14 | #================================================= 15 | 16 | # Exit if an error occurs during the execution of the script 17 | ynh_abort_if_errors 18 | 19 | #================================================= 20 | # RETRIEVE ARGUMENTS FROM THE MANIFEST 21 | #================================================= 22 | 23 | install_type=$YNH_APP_ARG_INSTALL_TYPE 24 | encrypt=$YNH_APP_ARG_ENCRYPT 25 | encryption_pwd=$YNH_APP_ARG_ENCRYPTION_PWD 26 | ssh_host=$YNH_APP_ARG_SSH_HOST 27 | ssh_port=$YNH_APP_ARG_SSH_PORT 28 | 29 | pub_key="$YNH_APP_ARG_PUB_KEY" 30 | auto_detect_failure=$YNH_APP_ARG_AUTO_DETECT_FAILURE 31 | delay_before_incident=$YNH_APP_ARG_DELAY_BEFORE_INCIDENT 32 | contact_mail=$YNH_APP_ARG_CONTACT_MAIL 33 | auto_deploy=$YNH_APP_ARG_AUTO_DEPLOY 34 | 35 | app=$YNH_APP_INSTANCE_NAME 36 | 37 | #================================================= 38 | # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS 39 | #================================================= 40 | ynh_script_progression --message="Validating installation parameters..." 41 | 42 | if [ "$install_type" == "main server" ]; then 43 | install_type=main 44 | elif [ "$install_type" == "fallback server" ]; then 45 | install_type=fallback 46 | else 47 | ynh_die --message="Install type not recognized" 48 | fi 49 | 50 | if [ "$install_type" == "main" ] 51 | then 52 | if [ $encrypt -eq 1 ]; then 53 | test -n "$encryption_pwd" || ynh_die --message="encryption_pwd can't be empty if you choose a 'main server' installation with encryption." 54 | fi 55 | test -n "$ssh_host" || ynh_die --message="ssh_host can't be empty if you choose a 'main server' installation." 56 | test -n "$ssh_port" || ynh_die --message="ssh_port can't be empty if you choose a 'main server' installation." 57 | else 58 | test -n "$pub_key" || ynh_die --message="pub_key can't be empty if you choose a 'fallback server' installation" 59 | fi 60 | 61 | final_path=/opt/yunohost/$app 62 | test ! -e "$final_path" || ynh_die --message="This path already contains a folder" 63 | 64 | #================================================= 65 | # STORE SETTINGS FROM MANIFEST 66 | #================================================= 67 | ynh_script_progression --message="Storing installation settings..." --weight=2 68 | 69 | ynh_app_setting_set --app=$app --key=install_type --value=$install_type 70 | ynh_app_setting_set --app=$app --key=encrypt --value=$encrypt 71 | if [ "$install_type" == "main" ] 72 | then 73 | ynh_app_setting_set --app=$app --key=ssh_host --value=$ssh_host 74 | ynh_app_setting_set --app=$app --key=ssh_port --value=$ssh_port 75 | else 76 | ynh_app_setting_set --app=$app --key=pub_key --value="$pub_key" 77 | ynh_app_setting_set --app=$app --key=auto_detect_failure --value="$auto_detect_failure" 78 | ynh_app_setting_set --app=$app --key=delay_before_incident --value="$delay_before_incident" 79 | ynh_app_setting_set --app=$app --key=contact_mail --value="$contact_mail" 80 | ynh_app_setting_set --app=$app --key=auto_deploy --value="$auto_deploy" 81 | fi 82 | ynh_app_setting_set --app=$app --key=admin_mail_html --value=1 83 | 84 | #================================================= 85 | # STANDARD MODIFICATIONS 86 | #================================================= 87 | # INSTALL DEPENDENCIES 88 | #================================================= 89 | ynh_script_progression --message="Installing dependencies..." --weight=14 90 | 91 | ynh_install_app_dependencies $pkg_dependencies 92 | 93 | #================================================= 94 | # DOWNLOAD, CHECK AND UNPACK SOURCE 95 | #================================================= 96 | ynh_script_progression --message="Setting up source files..." --weight=4 97 | 98 | ynh_app_setting_set --app=$app --key=final_path --value=$final_path 99 | # Download, check integrity, uncompress and patch the source from app.src 100 | ynh_setup_source --dest_dir="$final_path" 101 | 102 | chmod 400 "$final_path/DynHost/cred" 103 | 104 | #================================================= 105 | # SPECIFIC SETUP 106 | #================================================= 107 | # CREATE DATA DIRECTORY 108 | #================================================= 109 | ynh_script_progression --message="Creating a data directory..." 110 | 111 | datadir=/home/yunohost.app/$app 112 | ynh_app_setting_set --app=$app --key=datadir --value=$datadir 113 | 114 | mkdir -p $datadir 115 | 116 | if [ "$install_type" == "main" ] 117 | then 118 | #================================================= 119 | # CONFIG FOR THE MAIN SERVER 120 | #================================================= 121 | # MODIFY THE CONFIG 122 | #================================================= 123 | ynh_script_progression --message="Configuring Fallback..." 124 | 125 | configfile="$final_path/send_process/config.conf" 126 | cp "${configfile}.modele" "$configfile" 127 | ynh_replace_string --match_string="ssh_user=.*" --replace_string="ssh_user=$app" --target_file="$configfile" 128 | ynh_replace_string --match_string="ssh_host=.*" --replace_string="ssh_host=$ssh_host" --target_file="$configfile" 129 | ynh_replace_string --match_string="ssh_port=.*" --replace_string="ssh_port=$ssh_port" --target_file="$configfile" 130 | 131 | ynh_replace_string --match_string="main_storage_dir=.*" --replace_string="main_storage_dir=$datadir/fallback_backup" --target_file="$configfile" 132 | ynh_replace_string --match_string="encrypt=.*" --replace_string="encrypt=$encrypt" --target_file="$configfile" 133 | 134 | #================================================= 135 | # CREATE A SSH KEY 136 | #================================================= 137 | ynh_script_progression --message="Creating a ssh key..." --weight=3 138 | 139 | ssh_key="$final_path/send_process/ssh_key" 140 | ssh-keygen -t rsa -b 4096 -N "" -f "$ssh_key" > /dev/null 141 | chown root: "$ssh_key" 142 | chmod 400 "$ssh_key" 143 | pub_key="${ssh_key}.pub" 144 | ynh_replace_string --match_string="ssh_key=.*" --replace_string="ssh_key=$ssh_key" --target_file="$configfile" 145 | 146 | mkdir -p /root/.ssh 147 | ssh-keyscan -t rsa $ssh_host >> /root/.ssh/known_hosts 148 | 149 | #================================================= 150 | # FILL THE APPS LIST 151 | #================================================= 152 | ynh_script_progression --message="Filling the apps list..." 153 | 154 | echo "#000# For each app you want to backup, precede by [.]" > "$final_path/send_process/app_list" 155 | yunohost app list | grep id: | sed 's/.*id:/[]:/' >> "$final_path/send_process/app_list" 156 | ynh_replace_string --match_string=".*: fallback" --replace_string="[-]: fallback" --target_file="$final_path/send_process/app_list" 157 | 158 | #================================================= 159 | # SET THE CRON 160 | #================================================= 161 | 162 | echo "0 1 * * * root \"$final_path/send_process/send_backup.sh\" > /dev/null" > /etc/cron.d/$app 163 | 164 | #================================================= 165 | # CREATE DIRECTORIES 166 | #================================================= 167 | 168 | mkdir -p "$final_path/send_process/checksum" 169 | mkdir -p "$datadir/fallback_backup/backup" 170 | 171 | #================================================= 172 | # STORE THE PASSWORD FOR ENCRYPTION 173 | #================================================= 174 | 175 | passkey="$final_path/send_process/passkey" 176 | ynh_replace_string --match_string="pass_file=.*" --replace_string="pass_file=$passkey" --target_file="$configfile" 177 | echo "$encryption_pwd" > "$passkey" 178 | chmod 400 "$passkey" 179 | 180 | #================================================= 181 | # STORE A CHECKSUM OF THIS CONFIG FILE 182 | #================================================= 183 | 184 | # Calculate and store the config file checksum into the app settings 185 | ynh_store_file_checksum --file="$configfile" 186 | 187 | else 188 | #================================================= 189 | # CONFIG FOR THE FALLBACK SERVER 190 | #================================================= 191 | # CREATE DEDICATED USER 192 | #================================================= 193 | ynh_script_progression --message="Configuring system user..." --weight=2 194 | 195 | if ! ynh_system_user_exists --username=$app 196 | then 197 | useradd -d "/home/$app" --system --user-group $app --shell /bin/bash 198 | fi 199 | 200 | # Allow the user to use ssh 201 | adduser $app ssh.app 202 | 203 | #================================================= 204 | # ADD THE SSH PUBLIC KEY 205 | #================================================= 206 | 207 | mkdir -p "/home/$app/.ssh" 208 | # Secure the ssh key 209 | echo -n "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty " >> "/home/$app/.ssh/authorized_keys" 210 | # Then add the key 211 | echo "$pub_key" >> "/home/$app/.ssh/authorized_keys" 212 | 213 | #================================================= 214 | # SET THE USER IN DEPLOY_FALLBACK SCRIPTS 215 | #================================================= 216 | 217 | ynh_replace_string --match_string="\(local_archive_dir=\"/home/\)fallback" --replace_string="\1$app" --target_file="$final_path/deploy_process/deploy_fallback.sh" 218 | ynh_replace_string --match_string="\(local_archive_dir=\"/home/\)fallback" --replace_string="\1$app" --target_file="$final_path/deploy_process/close_fallback.sh" 219 | ynh_replace_string --match_string="\(local_archive_dir=\"/home/\)fallback" --replace_string="\1$app" --target_file="$final_path/deploy_process/auto_deploy_fallback.sh" 220 | 221 | #================================================= 222 | # SET A CHROOT FOR THE SSH USER 223 | #================================================= 224 | ynh_script_progression --message="Setting a chroot for the ssh user..." --weight=2 225 | 226 | chroot_dir="/home/$app" 227 | 228 | # Create directories for the binaries 229 | mkdir -p $chroot_dir/{bin,lib,lib64} 230 | 231 | # Copy the ld-linux file, according to the architecture 232 | copy_ld-linux () { 233 | ! test -e "$1" || cp "$1" "$chroot_dir/$2/" 234 | } 235 | copy_ld-linux /lib/ld-linux.so.2 lib 236 | copy_ld-linux /lib64/ld-linux-x86-64.so.2 lib64 237 | copy_ld-linux /lib/ld-linux-armhf.so.3 lib 238 | 239 | # Copy binary and its libraries into the chroot. 240 | ssh_chroot_copy_binary () { 241 | # Find and copy the binary file 242 | cp `which $1` "$chroot_dir/bin/$(basename $1)" 243 | # Then search for its libraries 244 | while read lib_file 245 | do 246 | # Filter lib without path 247 | if echo "$lib_file" | grep --quiet "=> /" 248 | then 249 | # Keep only the path of this lib 250 | local lib_path=$(echo "$lib_file" | awk '{print $3}') 251 | cp $lib_path "$chroot_dir/lib/" 252 | fi 253 | done <<< "$(ldd `which $1`)" 254 | } 255 | 256 | # Copy bash in the chroot 257 | ssh_chroot_copy_binary bash 258 | # Then rsync 259 | ssh_chroot_copy_binary rsync 260 | 261 | # Create the directory for rsync 262 | mkdir -p $chroot_dir/backup 263 | 264 | # The parent directory shall belong to root 265 | chown $app: -R "$chroot_dir" 266 | chown root: "$chroot_dir" 267 | chmod 755 -R "$chroot_dir" 268 | # Set the permissions for the ssh key 269 | chmod 644 "$chroot_dir/.ssh/authorized_keys" 270 | 271 | # Set the chroot in the ssh config 272 | echo " 273 | Match User $app # Automatically added by $app 274 | ChrootDirectory /home/%u # Automatically added by $app 275 | AllowTcpForwarding no # Automatically added by $app 276 | X11Forwarding no # Automatically added by $app" >> /etc/ssh/sshd_config 277 | 278 | # Reload ssh service 279 | ynh_systemd_action --action=reload --service_name=ssh 280 | 281 | #================================================= 282 | # CONFIGURE AUTO DEPLOYMENT 283 | #================================================= 284 | ynh_script_progression --message="Configuring auto deployment..." 285 | 286 | auto_check_config_file="$final_path/deploy_process/auto_check.conf" 287 | cp "${auto_check_config_file}.modele" "$auto_check_config_file" 288 | 289 | # If failure auto detection is activated 290 | if [ $auto_detect_failure -eq 1 ] 291 | then 292 | # Convert delay_before_incident in minutes 293 | case $delay_before_incident in 294 | 5min ) delay_before_incident=5; cron_delay="*/1 *" ;; 295 | 1h ) delay_before_incident=60; cron_delay="*/10 *" ;; 296 | 4h ) delay_before_incident=240; cron_delay="*/30 *" ;; 297 | 8h ) delay_before_incident=480; cron_delay="0 */1" ;; 298 | 12h ) delay_before_incident=720; cron_delay="0 */1" ;; 299 | 24h ) delay_before_incident=1440; cron_delay="0 */1" ;; 300 | esac 301 | 302 | # Fill the config file 303 | ynh_replace_string --match_string="delay_before_incident=.*" --replace_string="delay_before_incident=$delay_before_incident" --target_file="$auto_check_config_file" 304 | # Send email at root if there no email 305 | if [ -z "$contact_mail" ] 306 | then 307 | ynh_print_info --message="Seems that you forgot to fill in a contact email address. root is going to be used instead." 308 | contact_mail=root 309 | ynh_app_setting_set --app=$app --key=contact_mail --value="$contact_mail" 310 | fi 311 | ynh_replace_string --match_string="contact_mail=.*" --replace_string="contact_mail=$contact_mail" --target_file="$auto_check_config_file" 312 | ynh_replace_string --match_string="auto_deploy=.*" --replace_string="auto_deploy=$auto_deploy" --target_file="$auto_check_config_file" 313 | ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="$auto_check_config_file" 314 | 315 | # Put in place the cron file 316 | ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="$final_path/deploy_process/auto_deploy_fallback.cron" 317 | cp $final_path/deploy_process/auto_deploy_fallback.cron /etc/cron.d/auto_deploy_fallback 318 | # And configure it 319 | ynh_replace_string --match_string="? ?" --replace_string="$cron_delay" --target_file="/etc/cron.d/auto_deploy_fallback" 320 | fi 321 | 322 | #================================================= 323 | # STORE A CHECKSUM OF THIS CONFIG FILE 324 | #================================================= 325 | 326 | # Calculate and store the config file checksum into the app settings 327 | ynh_store_file_checksum --file="$auto_check_config_file" 328 | fi 329 | 330 | #================================================= 331 | # SET LINKS FOR THE ADMIN USER 332 | #================================================= 333 | 334 | if [ "$install_type" == "main" ]; then 335 | ln -s "$final_path/send_process/app_list" "$datadir/app_list" 336 | ln -s "$final_path/send_process/config.conf" "$datadir/config.conf" 337 | ln -s "$final_path/update_from_fallback_process/update_from_fallback.sh" "$datadir/update_from_fallback" 338 | else 339 | ln -s "$final_path/deploy_process/deploy_fallback.sh" "$datadir/deploy_fallback" 340 | ln -s "$final_path/deploy_process/close_fallback.sh" "$datadir/close_fallback" 341 | fi 342 | 343 | #================================================= 344 | # CONFIGURE HOOKS 345 | #================================================= 346 | 347 | ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../hooks/post_app_install" 348 | ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../hooks/post_app_remove" 349 | 350 | #================================================= 351 | # GENERIC FINALIZATION 352 | #================================================= 353 | # SECURE FILES AND DIRECTORIES 354 | #================================================= 355 | 356 | # Set permissions to app files 357 | chown -R root: $final_path 358 | 359 | if [ "$install_type" == "main" ] 360 | then 361 | #================================================= 362 | # SETUP LOGROTATE 363 | #================================================= 364 | ynh_script_progression --message="Configuring log rotation..." 365 | 366 | mkdir -p /var/log/$app 367 | ln -s /var/log/$app/$app.log "$final_path/send_process/send_backup.log" 368 | # Use logrotate to manage application logfile(s) 369 | ynh_use_logrotate 370 | 371 | #================================================= 372 | # DISCLAIMER 373 | #================================================= 374 | 375 | ynh_print_info --message=" 376 | By default, no apps will be backuped for your fallback server. To select which apps you want to backup, please have a look at the app_list file in $datadir/app_list. 377 | Please take note of your public ssh key. This will be usefull during the installation on your fallback server." >&2 378 | ynh_print_info --message="$(cat "$pub_key")" >&2 379 | fi 380 | 381 | #================================================= 382 | # SEND A README FOR THE ADMIN 383 | #================================================= 384 | 385 | # Get main domain and buid the url of the admin panel of the app. 386 | admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" 387 | 388 | if [ $encrypt -eq 1 ] 389 | then 390 | encrypt_infos="Your password for encryption is '$encryption_pwd' 391 | 392 | " 393 | else 394 | encrypt_infos="" 395 | fi 396 | 397 | if [ "$install_type" == "main" ] 398 | then 399 | Informations="${encrypt_infos}By default, no apps will be backuped for your fallback server. To select which apps you want to backup, please have a look at the app_list file in $datadir/app_list. 400 | 401 | Please take note of your public ssh key. This will be usefull during the installation on your fallback server : 402 | $(cat "$pub_key") 403 | 404 | Fallback is going to backup and send its backup every night. 405 | If you want to change the frequency, have a look to the file /etc/cron.d/$app. 406 | 407 | You can also find a config file at /home/yunohost.app/fallback/config.conf" 408 | else 409 | domain=$(yunohost domain list | grep -m1 "-" | awk '{print $2}') 410 | if [ -n "$domain" ] 411 | then 412 | domain="$domain or " 413 | else 414 | domain="" 415 | fi 416 | Informations="This server is now your fallback, you should keep this server only for this purpose. 417 | 418 | Credentials for the ssh connexion from the other part of this app: 419 | - ssh_host: $domain$(hostname) 420 | - ssh_user: $app 421 | - ssh_port: $(grep "^Port " /etc/ssh/sshd_config | awk '{print $2}')" 422 | 423 | if [ $auto_detect_failure -eq 1 ] 424 | then 425 | Informations="$Informations 426 | 427 | Failure auto detection is activated on this fallback. In case of failure of your main server, you should receive an email on $contact_mail to inform you. 428 | To modify the configuration related to this option, please have a look at $auto_check_config_file" 429 | fi 430 | fi 431 | 432 | echo "$Informations 433 | 434 | For more information about how to use this app, please read the __URL_TAG1__readme__URL_TAG2__https://github.com/YunoHost-Apps/fallback_ynh/blob/master/README.md#how-it-works__URL_TAG3__. 435 | 436 | You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__. 437 | You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__. 438 | 439 | If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/fallback_ynh__URL_TAG3__." > mail_to_send 440 | 441 | ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=install 442 | 443 | #================================================= 444 | # END OF SCRIPT 445 | #================================================= 446 | 447 | ynh_script_progression --message="Installation of $app completed" --last 448 | -------------------------------------------------------------------------------- /scripts/remove: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # GENERIC START 5 | #================================================= 6 | # IMPORT GENERIC HELPERS 7 | #================================================= 8 | 9 | source _common.sh 10 | source /usr/share/yunohost/helpers 11 | 12 | #================================================= 13 | # LOAD SETTINGS 14 | #================================================= 15 | ynh_script_progression --message="Loading installation settings..." --weight=2 16 | 17 | app=$YNH_APP_INSTANCE_NAME 18 | 19 | install_type=$(ynh_app_setting_get --app=$app --key=install_type) 20 | final_path=$(ynh_app_setting_get --app=$app --key=final_path) 21 | datadir=$(ynh_app_setting_get --app=$app --key=datadir) 22 | ssh_host=$(ynh_app_setting_get --app=$app --key=ssh_host) 23 | 24 | #================================================= 25 | # STANDARD REMOVE 26 | #================================================= 27 | # REMOVE LOGROTATE CONFIGURATION 28 | #================================================= 29 | 30 | if [ "$install_type" == "main" ] 31 | then 32 | 33 | ynh_script_progression --message="Removing logrotate configuration..." 34 | 35 | # Remove the app-specific logrotate config 36 | ynh_remove_logrotate 37 | ynh_secure_remove --file="/var/log/$app" 38 | fi 39 | 40 | #================================================= 41 | # REMOVE APP MAIN DIR 42 | #================================================= 43 | ynh_script_progression --message="Removing app main directory..." 44 | 45 | # Remove the app directory securely 46 | ynh_secure_remove --file="$final_path" 47 | 48 | #================================================= 49 | # REMOVE DATA DIR 50 | #================================================= 51 | ynh_script_progression --message="Removing app data directory..." --weight=2 52 | 53 | ynh_secure_remove --file="$datadir" 54 | 55 | #================================================= 56 | # REMOVE DEPENDENCIES 57 | #================================================= 58 | ynh_script_progression --message="Removing dependencies..." --weight=7 59 | 60 | # Remove metapackage and its dependencies 61 | ynh_remove_app_dependencies 62 | 63 | #================================================= 64 | # SPECIFIC REMOVE 65 | #================================================= 66 | 67 | if [ "$install_type" == "main" ] 68 | then 69 | #================================================= 70 | # REMOVE THE CRON FILE 71 | #================================================= 72 | 73 | ynh_secure_remove --file="/etc/cron.d/$app" 74 | 75 | #================================================= 76 | # REMOVE THE HOST FROM THE KNOWN HOST LIST 77 | #================================================= 78 | 79 | sed -i "/$ssh_host/d" /root/.ssh/known_hosts 80 | 81 | #================================================= 82 | # REMOVE DEDICATED USER 83 | #================================================= 84 | ynh_script_progression --message="Removing the dedicated system user..." 85 | 86 | ynh_system_user_delete --username=$app 87 | ynh_secure_remove --file="/home/$app" 88 | 89 | #================================================= 90 | # REMOVE THE CHROOT FROM THE SSH CONFIG 91 | #================================================= 92 | ynh_script_progression --message="Removing the chroot from the ssh config..." 93 | 94 | sed -i "/# Automatically added by $app/d" /etc/ssh/sshd_config 95 | 96 | # Reload ssh service 97 | ynh_systemd_action --action=reload --service_name=ssh 98 | else 99 | #================================================= 100 | # REMOVE THE CRON FILE 101 | #================================================= 102 | 103 | ynh_secure_remove --file="/etc/cron.d/auto_deploy_fallback" 104 | fi 105 | 106 | #================================================= 107 | # END OF SCRIPT 108 | #================================================= 109 | 110 | ynh_script_progression --message="Removal of $app completed" --last 111 | -------------------------------------------------------------------------------- /scripts/restore: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # GENERIC START 5 | #================================================= 6 | # IMPORT GENERIC HELPERS 7 | #================================================= 8 | 9 | # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts 10 | source ../settings/scripts/_common.sh 11 | source /usr/share/yunohost/helpers 12 | 13 | #================================================= 14 | # MANAGE SCRIPT FAILURE 15 | #================================================= 16 | 17 | # Exit if an error occurs during the execution of the script 18 | ynh_abort_if_errors 19 | 20 | #================================================= 21 | # LOAD SETTINGS 22 | #================================================= 23 | ynh_script_progression --message="Loading installation settings..." --weight=3 24 | 25 | app=$YNH_APP_INSTANCE_NAME 26 | 27 | install_type=$(ynh_app_setting_get --app=$app --key=install_type) 28 | final_path=$(ynh_app_setting_get --app=$app --key=final_path) 29 | ssh_host=$(ynh_app_setting_get --app=$app --key=ssh_host) 30 | ssh_port=$(ynh_app_setting_get --app=$app --key=ssh_port) 31 | pub_key="$(ynh_app_setting_get --app=$app --key=pub_key)" 32 | auto_detect_failure=$(ynh_app_setting_get --app=$app --key=auto_detect_failure) 33 | datadir=$(ynh_app_setting_get --app=$app --key=datadir) 34 | 35 | #================================================= 36 | # CHECK IF THE APP CAN BE RESTORED 37 | #================================================= 38 | ynh_script_progression --message="Validating restoration parameters..." 39 | 40 | test ! -d $final_path \ 41 | || ynh_die --message="There is already a directory: $final_path " 42 | 43 | #================================================= 44 | # STANDARD RESTORATION STEPS 45 | #================================================= 46 | # RESTORE THE APP MAIN DIR 47 | #================================================= 48 | ynh_script_progression --message="Restoring the app main directory..." 49 | 50 | ynh_restore_file --origin_path="$final_path" 51 | 52 | #================================================= 53 | # SPECIFIC RESTORATION 54 | #================================================= 55 | # REINSTALL DEPENDENCIES 56 | #================================================= 57 | ynh_script_progression --message="Reinstalling dependencies..." --weight=9 58 | 59 | # Define and install dependencies 60 | ynh_install_app_dependencies $pkg_dependencies 61 | 62 | if [ "$install_type" == "main" ] 63 | then 64 | 65 | #================================================= 66 | # ADD THE HOST TO THE KNOWN HOST LIST 67 | #================================================= 68 | ynh_script_progression --message="Adding the host to the known host list..." --weight=3 69 | 70 | mkdir -p /root/.ssh 71 | ssh-keyscan -t rsa $ssh_host >> /root/.ssh/known_hosts 2> /dev/null 72 | 73 | #================================================= 74 | # RESTORE THE LOGROTATE CONFIGURATION 75 | #================================================= 76 | 77 | ynh_restore_file --origin_path="/etc/logrotate.d/$app" 78 | 79 | #================================================= 80 | # RESTORE THE CRON FILE 81 | #================================================= 82 | 83 | ynh_restore_file --origin_path="/etc/cron.d/$app" 84 | 85 | else 86 | #================================================= 87 | # RECREATE DEDICATED USER 88 | #================================================= 89 | 90 | if ! ynh_system_user_exists --username=$app 91 | then 92 | ynh_script_progression --message="Recreating the dedicated system user..." 93 | useradd -d "/home/$app" --system --user-group $app --shell /bin/bash 94 | fi 95 | 96 | # Allow the user to use ssh 97 | adduser $app ssh.app 98 | 99 | #================================================= 100 | # RESTORE USER DIRECTORIES 101 | #================================================= 102 | ynh_script_progression --message="Restoring user directories..." --weight=2 103 | 104 | ynh_restore_file --origin_path="/home/$app/bin" 105 | ynh_restore_file --origin_path="/home/$app/lib" 106 | ynh_restore_file --origin_path="/home/$app/lib64" 107 | ynh_restore_file --origin_path="/home/$app/.ssh" 108 | 109 | # Update the ssh config 110 | if ! grep "# Automatically added by $app" /etc/ssh/sshd_config 111 | then 112 | ynh_script_progression --message="Update the ssh config" 113 | 114 | echo " 115 | Match User $app # Automatically added by $app 116 | ChrootDirectory /home/%u # Automatically added by $app 117 | AllowTcpForwarding no # Automatically added by $app 118 | X11Forwarding no # Automatically added by $app" >> /etc/ssh/sshd_config 119 | 120 | # Reload ssh service 121 | ynh_systemd_action --action=reload --service_name=ssh 122 | fi 123 | 124 | #================================================= 125 | # RESTORE THE CRON FILE 126 | #================================================= 127 | 128 | if [ $auto_detect_failure -eq 1 ] 129 | then 130 | ynh_restore_file --origin_path="/etc/cron.d/auto_deploy_fallback" 131 | fi 132 | fi 133 | 134 | #================================================= 135 | # RECREATE DIRECTORIES 136 | #================================================= 137 | 138 | mkdir -p "$datadir/fallback_backup/backup" 139 | if [ "$install_type" == "main" ] 140 | then 141 | mkdir -p /var/log/$app 142 | else 143 | mkdir -p /home/$app/backup 144 | fi 145 | 146 | #================================================= 147 | # SET LINKS FOR THE ADMIN USER 148 | #================================================= 149 | 150 | if [ "$install_type" == "main" ]; then 151 | ln -sf "$final_path/send_process/app_list" "$datadir/app_list" 152 | ln -sf "$final_path/send_process/config.conf" "$datadir/config.conf" 153 | ln -sf "$final_path/update_from_fallback_process/update_from_fallback.sh" "$datadir/update_from_fallback" 154 | else 155 | ln -sf "$final_path/deploy_process/deploy_fallback.sh" "$datadir/deploy_fallback" 156 | ln -sf "$final_path/deploy_process/close_fallback.sh" "$datadir/close_fallback" 157 | fi 158 | 159 | #================================================= 160 | # GENERIC FINALIZATION 161 | #================================================= 162 | # SECURE FILES AND DIRECTORIES 163 | #================================================= 164 | 165 | if [ "$install_type" == "fallback" ] 166 | then 167 | # The parent directory shall belong to root 168 | chown $app: -R "/home/$app" 169 | chown root: "/home/$app" 170 | chmod 755 -R "/home/$app" 171 | # Set the permissions for the ssh key 172 | chmod 644 "$chroot_dir/.ssh/authorized_keys" 173 | fi 174 | 175 | #================================================= 176 | # SEND A README FOR THE ADMIN 177 | #================================================= 178 | 179 | # Get main domain and buid the url of the admin panel of the app. 180 | admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" 181 | 182 | if [ "$install_type" == "main" ] 183 | then 184 | Informations="By default, no apps will be backuped for your fallback server. To select which apps you want to backup, please have a look at the app_list file in $datadir/app_list. 185 | 186 | Please take note of your public ssh key. This will be usefull during the installation on your fallback server : 187 | $pub_key 188 | 189 | Fallback is going to backup and send its backup every night. 190 | If you want to change the frequency, have a look to the file /etc/cron.d/$app. 191 | 192 | You can also find a config file at /home/yunohost.app/fallback/config.conf" 193 | else 194 | domain=$(yunohost domain list | grep -m1 "-" | awk '{print $2}') 195 | if [ -n "$domain" ] 196 | then 197 | domain="$domain or " 198 | else 199 | domain="" 200 | fi 201 | Informations="This server is now your fallback, you should keep this server only for this purpose. 202 | 203 | Credentials for the ssh connexion from the other part of this app: 204 | - ssh_host: $domain$(hostname) 205 | - ssh_user: $app 206 | - ssh_port: $(grep "^Port " /etc/ssh/sshd_config | awk '{print $2}')" 207 | 208 | if [ $auto_detect_failure -eq 1 ] 209 | then 210 | Informations="$Informations 211 | 212 | Failure auto detection is activated on this fallback. In case of failure of your main server. 213 | To modify the configuration related to this option, please have a look at $final_path/deploy_process/auto_check.conf" 214 | fi 215 | fi 216 | 217 | echo "$Informations 218 | 219 | For more information about how to use this app, please read the __URL_TAG1__readme__URL_TAG2__https://github.com/YunoHost-Apps/fallback_ynh/blob/master/README.md#how-it-works__URL_TAG3__. 220 | 221 | You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__. 222 | You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__. 223 | 224 | If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/fallback_ynh__URL_TAG3__." > mail_to_send 225 | 226 | ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=restore 227 | 228 | #================================================= 229 | # END OF SCRIPT 230 | #================================================= 231 | 232 | ynh_script_progression --message="Restoration completed for $app" --last 233 | -------------------------------------------------------------------------------- /scripts/upgrade: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # GENERIC START 5 | #================================================= 6 | # IMPORT GENERIC HELPERS 7 | #================================================= 8 | 9 | source _common.sh 10 | source /usr/share/yunohost/helpers 11 | 12 | #================================================= 13 | # LOAD SETTINGS 14 | #================================================= 15 | ynh_script_progression --message="Loading installation settings..." --weight=4 16 | 17 | app=$YNH_APP_INSTANCE_NAME 18 | 19 | install_type=$(ynh_app_setting_get --app=$app --key=install_type) 20 | encrypt=$(ynh_app_setting_get --app=$app --key=encrypt) 21 | final_path=$(ynh_app_setting_get --app=$app --key=final_path) 22 | ssh_host=$(ynh_app_setting_get --app=$app --key=ssh_host) 23 | ssh_port=$(ynh_app_setting_get --app=$app --key=ssh_port) 24 | pub_key="$(ynh_app_setting_get --app=$app --key=pub_key)" 25 | auto_detect_failure=$(ynh_app_setting_get --app=$app --key=auto_detect_failure) 26 | datadir=$(ynh_app_setting_get --app=$app --key=datadir) 27 | 28 | # Optional parameters from config-panel feature 29 | contact_mail=$(ynh_app_setting_get --app=$app --key=contact_mail) 30 | auto_deploy=$(ynh_app_setting_get --app=$app --key=auto_deploy) 31 | delay_before_incident=$(ynh_app_setting_get --app=$app --key=delay_before_incident) 32 | 33 | #================================================= 34 | # CHECK VERSION 35 | #================================================= 36 | ynh_script_progression --message="Checking version..." 37 | 38 | upgrade_type=$(ynh_check_app_version_changed) 39 | 40 | #================================================= 41 | # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP 42 | #================================================= 43 | ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=5 44 | 45 | # Backup the current version of the app 46 | ynh_backup_before_upgrade 47 | ynh_clean_setup () { 48 | # Restore it if the upgrade fails 49 | ynh_restore_upgradebackup 50 | } 51 | # Exit if an error occurs during the execution of the script 52 | ynh_abort_if_errors 53 | 54 | #================================================= 55 | # STANDARD UPGRADE STEPS 56 | #================================================= 57 | # ENSURE DOWNWARD COMPATIBILITY 58 | #================================================= 59 | ynh_script_progression --message="Ensuring downward compatibility..." 60 | 61 | if [ "$install_type" == "fallback" ] 62 | then 63 | # If auto_detect_failure setting doesn't exist 64 | if [ -z "$auto_detect_failure" ]; then 65 | auto_detect_failure=0 66 | ynh_app_setting_set --app=$app --key=auto_detect_failure --value=$auto_detect_failure 67 | fi 68 | # If delay_before_incident setting doesn't exist 69 | if [ -z "$delay_before_incident" ]; then 70 | delay_before_incident=$(grep "^delay_before_incident=" "$final_path/deploy_process/auto_check.conf" | cut -d= -f2) 71 | ynh_app_setting_set --app=$app --key=delay_before_incident --value=$delay_before_incident 72 | fi 73 | # If contact_mail setting doesn't exist 74 | if [ -z "$contact_mail" ]; then 75 | contact_mail=$(grep "^contact_mail=" "$final_path/deploy_process/auto_check.conf" | cut -d= -f2) 76 | ynh_app_setting_set --app=$app --key=contact_mail --value=$contact_mail 77 | fi 78 | # If auto_deploy setting doesn't exist 79 | if [ -z "$auto_deploy" ]; then 80 | auto_deploy=$(grep "^auto_deploy=" "$final_path/deploy_process/auto_check.conf" | cut -d= -f2) 81 | ynh_app_setting_set --app=$app --key=auto_deploy --value=$auto_deploy 82 | fi 83 | fi 84 | 85 | # If datadir doesn't exist, create it 86 | if [ -z "$datadir" ]; then 87 | datadir=/home/yunohost.app/$app 88 | ynh_app_setting_set --app=$app --key=datadir --value=$datadir 89 | fi 90 | 91 | #================================================= 92 | # DOWNLOAD, CHECK AND UNPACK SOURCE 93 | #================================================= 94 | 95 | if [ "$upgrade_type" == "UPGRADE_APP" ] 96 | then 97 | ynh_script_progression --message="Upgrading source files..." --weight=2 98 | # Do not replace credentials 99 | mv "$final_path/DynHost/cred" "$final_path/DynHost/cred_backup" 100 | # Download, check integrity, uncompress and patch the source from app.src 101 | ynh_setup_source --dest_dir="$final_path" 102 | mv "$final_path/DynHost/cred_backup" "$final_path/DynHost/cred" 103 | fi 104 | 105 | #================================================= 106 | # UPGRADE DEPENDENCIES 107 | #================================================= 108 | ynh_script_progression --message="Upgrading dependencies..." --weight=9 109 | 110 | ynh_install_app_dependencies $pkg_dependencies 111 | 112 | #================================================= 113 | # SPECIFIC UPGRADE 114 | #================================================= 115 | 116 | if [ "$install_type" == "main" ] 117 | then 118 | #================================================= 119 | # CONFIG FOR THE MAIN SERVER 120 | #================================================= 121 | # MODIFY THE CONFIG 122 | #================================================= 123 | 124 | if [ "$upgrade_type" == "UPGRADE_APP" ] 125 | then 126 | ynh_script_progression --message="Reconfiguring Fallback..." 127 | configfile="$final_path/send_process/config.conf" 128 | ynh_replace_string --match_string="ssh_user=.*" --replace_string="ssh_user=$app" --target_file="$configfile" 129 | ynh_replace_string --match_string="ssh_host=.*" --replace_string="ssh_host=$ssh_host" --target_file="$configfile" 130 | ynh_replace_string --match_string="ssh_port=.*" --replace_string="ssh_port=$ssh_port" --target_file="$configfile" 131 | ynh_replace_string --match_string="ssh_key=.*" --replace_string="ssh_key=$final_path/send_process/ssh_key" --target_file="$configfile" 132 | 133 | ynh_replace_string --match_string="main_storage_dir=.*" --replace_string="main_storage_dir=$datadir/fallback_backup" --target_file="$configfile" 134 | ynh_replace_string --match_string="encrypt=.*" --replace_string="encrypt=$encrypt" --target_file="$configfile" 135 | fi 136 | 137 | #================================================= 138 | # UPDATE THE CRON 139 | #================================================= 140 | ynh_script_progression --message="Updating the cron..." 141 | 142 | echo "0 1 * * * root \"$final_path/send_process/send_backup.sh\" > /dev/null" > /etc/cron.d/$app 143 | 144 | else 145 | #================================================= 146 | # CONFIG FOR THE FALLBACK SERVER 147 | #================================================= 148 | # CREATE DEDICATED USER 149 | #================================================= 150 | 151 | if ! ynh_system_user_exists --username=$app 152 | then 153 | ynh_script_progression --message="Making sure dedicated system user exists..." 154 | useradd -d "/home/$app" --system --user-group $app --shell /bin/bash 155 | fi 156 | 157 | # Allow the user to use ssh 158 | adduser $app ssh.app 159 | 160 | #================================================= 161 | # SET THE USER IN DEPLOY_FALLBACK SCRIPTS 162 | #================================================= 163 | 164 | if [ "$upgrade_type" == "UPGRADE_APP" ] 165 | then 166 | ynh_replace_string --match_string="\(local_archive_dir=\"/home/\)USER" --replace_string="\1$app" --target_file="$final_path/deploy_process/deploy_fallback.sh" 167 | ynh_replace_string --match_string="\(local_archive_dir=\"/home/\)USER" --replace_string="\1$app" --target_file="$final_path/deploy_process/close_fallback.sh" 168 | fi 169 | 170 | #================================================= 171 | # UPDATE THE CHROOT FOR THE SSH USER 172 | #================================================= 173 | ynh_script_progression --message="Updating the chroot for the ssh user..." 174 | 175 | chroot_dir="/home/$app" 176 | 177 | # Create directories for the binaries 178 | mkdir -p $chroot_dir/{bin,lib,lib64} 179 | 180 | # Copy the ld-linux file, according to the architecture 181 | copy_ld-linux () { 182 | ! test -e "$1" || cp "$1" "$chroot_dir/$2/" 183 | } 184 | copy_ld-linux /lib/ld-linux.so.2 lib 185 | copy_ld-linux /lib64/ld-linux-x86-64.so.2 lib64 186 | copy_ld-linux /lib/ld-linux-armhf.so.3 lib 187 | 188 | # Copy binary and its libraries into the chroot. 189 | ssh_chroot_copy_binary () { 190 | # Find and copy the binary file 191 | cp `which $1` "$chroot_dir/bin/$(basename $1)" 192 | # Then search for its libraries 193 | while read lib_file 194 | do 195 | # Filter lib without path 196 | if echo "$lib_file" | grep --quiet "=> /" 197 | then 198 | # Keep only the path of this lib 199 | local lib_path=$(echo "$lib_file" | awk '{print $3}') 200 | cp $lib_path "$chroot_dir/lib/" 201 | fi 202 | done <<< "$(ldd `which $1`)" 203 | } 204 | 205 | # Copy bash in the chroot 206 | ssh_chroot_copy_binary bash 207 | # Then rsync 208 | ssh_chroot_copy_binary rsync 209 | 210 | # Create the directory for rsync 211 | mkdir -p $chroot_dir/backup 212 | 213 | # The parent directory shall belong to root 214 | chown $app: -R "$chroot_dir" 215 | chown root: "$chroot_dir" 216 | chmod 755 -R "$chroot_dir" 217 | # Set the permissions for the ssh key 218 | chmod 644 "$chroot_dir/.ssh/authorized_keys" 219 | 220 | # Update the ssh config 221 | if ! grep "# Automatically added by $app" /etc/ssh/sshd_config 222 | then 223 | echo " 224 | Match User $app # Automatically added by $app 225 | ChrootDirectory /home/%u # Automatically added by $app 226 | AllowTcpForwarding no # Automatically added by $app 227 | X11Forwarding no # Automatically added by $app" >> /etc/ssh/sshd_config 228 | 229 | # Reload ssh service 230 | ynh_system_reload --action=reload --service_name=ssh 231 | fi 232 | 233 | #================================================= 234 | # CONFIGURE AUTO DEPLOYMENT 235 | #================================================= 236 | 237 | if [ "$upgrade_type" == "UPGRADE_APP" ] 238 | then 239 | ynh_script_progression --message="Configuring auto deployment..." 240 | auto_check_config_file="$final_path/deploy_process/auto_check.conf" 241 | ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="$auto_check_config_file" 242 | 243 | # Optional parameters from config-panel feature 244 | if [ -n "$contact_mail" ]; then 245 | ynh_replace_string --match_string="^contact_mail=.*" --replace_string="contact_mail=$contact_mail" --target_file="$auto_check_config_file" 246 | fi 247 | if [ -n "$auto_deploy" ]; then 248 | ynh_replace_string --match_string="^auto_deploy=.*" --replace_string="auto_deploy=$auto_deploy" --target_file="$auto_check_config_file" 249 | fi 250 | if [ -n "$delay_before_incident" ]; then 251 | ynh_replace_string --match_string="^delay_before_incident=.*" --replace_string="delay_before_incident=$delay_before_incident" --target_file="$auto_check_config_file" 252 | fi 253 | 254 | # Configure the cron file 255 | ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="$final_path/deploy_process/auto_deploy_fallback.cron" 256 | fi 257 | fi 258 | 259 | #================================================= 260 | # UPDATE LINKS FOR THE ADMIN USER 261 | #================================================= 262 | 263 | if [ "$install_type" == "main" ]; then 264 | ln -sf "$final_path/send_process/app_list" "$datadir/app_list" 265 | ln -sf "$final_path/send_process/config.conf" "$datadir/config.conf" 266 | ln -sf "$final_path/update_from_fallback_process/update_from_fallback.sh" "$datadir/update_from_fallback" 267 | else 268 | ln -sf "$final_path/deploy_process/deploy_fallback.sh" "$datadir/deploy_fallback" 269 | ln -sf "$final_path/deploy_process/close_fallback.sh" "$datadir/close_fallback" 270 | fi 271 | 272 | #================================================= 273 | # CONFIGURE HOOKS 274 | #================================================= 275 | 276 | ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../hooks/post_app_install" 277 | ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../hooks/post_app_remove" 278 | 279 | #================================================= 280 | # SECURE FILES AND DIRECTORIES 281 | #================================================= 282 | 283 | # Set permissions to app files 284 | chown -R root: $final_path 285 | 286 | #================================================= 287 | # GENERIC FINALIZATION 288 | #================================================= 289 | # SETUP LOGROTATE 290 | #================================================= 291 | 292 | if [ "$install_type" == "main" ] 293 | then 294 | ynh_script_progression --message="Upgrading logrotate configuration..." --weight=2 295 | 296 | # Use logrotate to manage application logfile(s) 297 | ynh_use_logrotate --non-append 298 | fi 299 | 300 | #================================================= 301 | # SEND A README FOR THE ADMIN 302 | #================================================= 303 | 304 | # Get main domain and buid the url of the admin panel of the app. 305 | admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" 306 | 307 | # Build the changelog 308 | ynh_app_changelog || true 309 | 310 | if [ "$install_type" == "main" ] 311 | then 312 | Informations="By default, no apps will be backuped for your fallback server. To select which apps you want to backup, please have a look at the app_list file in $datadir/app_list. 313 | 314 | Please take note of your public ssh key. This will be usefull during the installation on your fallback server : 315 | $pub_key 316 | 317 | Fallback is going to backup and send its backup every night. 318 | If you want to change the frequency, have a look to the file /etc/cron.d/$app. 319 | 320 | You can also find a config file at /home/yunohost.app/fallback/config.conf" 321 | else 322 | domain=$(yunohost domain list | grep -m1 "-" | awk '{print $2}') 323 | if [ -n "$domain" ] 324 | then 325 | domain="$domain or " 326 | else 327 | domain="" 328 | fi 329 | Informations="This server is now your fallback, you should keep this server only for this purpose. 330 | 331 | Credentials for the ssh connexion from the other part of this app: 332 | - ssh_host: $domain$(hostname) 333 | - ssh_user: $app 334 | - ssh_port: $(grep "^Port " /etc/ssh/sshd_config | awk '{print $2}')" 335 | 336 | if [ $auto_detect_failure -eq 1 ] 337 | then 338 | Informations="$Informations 339 | 340 | Failure auto detection is activated on this fallback. In case of failure of your main server. 341 | To modify the configuration related to this option, please have a look at $final_path/deploy_process/auto_check.conf" 342 | fi 343 | fi 344 | 345 | echo "$Informations 346 | 347 | For more information about how to use this app, please read the __URL_TAG1__readme__URL_TAG2__https://github.com/YunoHost-Apps/fallback_ynh/blob/master/README.md#how-it-works__URL_TAG3__. 348 | 349 | You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__. 350 | You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__. 351 | 352 | If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/fallback_ynh__URL_TAG3__. 353 | 354 | --- 355 | 356 | Changelog since your last upgrade: 357 | $(cat changelog)" > mail_to_send 358 | 359 | ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=upgrade 360 | 361 | #================================================= 362 | # END OF SCRIPT 363 | #================================================= 364 | 365 | ynh_script_progression --message="Upgrade of $app completed" --last 366 | --------------------------------------------------------------------------------