Copy-a-Shaarli-installation-over-SSH-SCP,-serve-it-locally-with-php-cli.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="generator" content="pandoc">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
  7. <title></title>
  8. <style type="text/css">code{white-space: pre;}</style>
  9. <!--[if lt IE 9]>
  10. <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
  11. <![endif]-->
  12. <link rel="stylesheet" href="github-markdown.css">
  13. </head>
  14. <body>
  15. <p>Example bash script:</p>
  16. <pre><code>#!/bin/bash
  17. #Description: Copy a Shaarli installation over SSH/SCP, serve it locally with php-cli
  18. #Will create a local-shaarli/ directory when you run it, backup your Shaarli there, and serve it locally.
  19. #Will NOT download linked pages. It&#39;s just a directly usable backup/copy/mirror of your Shaarli
  20. #Requires: ssh, scp and a working SSH access to the server where your Shaarli is installed
  21. #Usage: ./local-shaarli.sh
  22. #Author: nodiscc (nodiscc@gmail.com)
  23. #License: MIT (http://opensource.org/licenses/MIT)
  24. set -o errexit
  25. set -o nounset
  26. ##### CONFIG #################
  27. #The port used by php&#39;s local server
  28. php_local_port=7431
  29. #Name of the SSH server and path where Shaarli is installed
  30. #TODO: pass these as command-line arguments
  31. remotehost=&quot;my.ssh.server&quot;
  32. remote_shaarli_dir=&quot;/var/www/shaarli&quot;
  33. ###### FUNCTIONS #############
  34. _main() {
  35. _CBSyncShaarli
  36. _CBServeShaarli
  37. }
  38. _CBSyncShaarli() {
  39. remote_temp_dir=$(ssh $remotehost mktemp -d)
  40. remote_ssh_user=$(ssh $remotehost whoami)
  41. ssh -t &quot;$remotehost&quot; sudo cp -r &quot;$remote_shaarli_dir&quot; &quot;$remote_temp_dir&quot;
  42. ssh -t &quot;$remotehost&quot; sudo chown -R &quot;$remote_ssh_user&quot;:&quot;$remote_ssh_user&quot; &quot;$remote_temp_dir&quot;
  43. scp -rq &quot;$remotehost&quot;:&quot;$remote_temp_dir&quot; local-shaarli
  44. ssh &quot;$remotehost&quot; rm -r &quot;$remote_temp_dir&quot;
  45. }
  46. _CBServeShaarli() {
  47. #TODO: allow serving a previously downloaded Shaarli
  48. #TODO: ask before overwriting local copy, if it exists
  49. cd local-shaarli/
  50. php -S localhost:${php_local_port}
  51. echo &quot;Please go to http://localhost:${php_local_port}&quot;
  52. }
  53. ##### MAIN #################
  54. _main</code></pre>
  55. <p>This outputs:</p>
  56. <pre><code>$ ./local-shaarli.sh
  57. PHP 5.6.0RC4 Development Server started at Mon Sep 1 21:56:19 2014
  58. Listening on http://localhost:7431
  59. Document root is /home/user/local-shaarli/shaarli
  60. Press Ctrl-C to quit.
  61. [Mon Sep 1 21:56:27 2014] ::1:57868 [200]: /
  62. [Mon Sep 1 21:56:27 2014] ::1:57869 [200]: /index.html
  63. [Mon Sep 1 21:56:37 2014] ::1:57881 [200]: /...</code></pre>
  64. </body>
  65. </html>