]>
Commit | Line | Data |
---|---|---|
7a32b172 | 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'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 | ||
27 | ##### CONFIG ################# | |
28 | #The port used by php's local server | |
29 | php_local_port=7431 | |
30 | ||
31 | #Name of the SSH server and path where Shaarli is installed | |
32 | #TODO: pass these as command-line arguments | |
33 | remotehost="my.ssh.server" | |
34 | remote_shaarli_dir="/var/www/shaarli" | |
35 | ||
36 | ||
37 | ###### FUNCTIONS ############# | |
38 | _main() { | |
39 | _CBSyncShaarli | |
40 | _CBServeShaarli | |
41 | } | |
42 | ||
43 | _CBSyncShaarli() { | |
44 | remote_temp_dir=$(ssh $remotehost mktemp -d) | |
45 | remote_ssh_user=$(ssh $remotehost whoami) | |
46 | ssh -t "$remotehost" sudo cp -r "$remote_shaarli_dir" "$remote_temp_dir" | |
47 | ssh -t "$remotehost" sudo chown -R "$remote_ssh_user":"$remote_ssh_user" "$remote_temp_dir" | |
48 | scp -rq "$remotehost":"$remote_temp_dir" local-shaarli | |
49 | ssh "$remotehost" rm -r "$remote_temp_dir" | |
50 | } | |
51 | ||
52 | _CBServeShaarli() { | |
53 | #TODO: allow serving a previously downloaded Shaarli | |
54 | #TODO: ask before overwriting local copy, if it exists | |
55 | cd local-shaarli/ | |
56 | php -S localhost:${php_local_port} | |
57 | echo "Please go to http://localhost:${php_local_port}" | |
58 | } | |
59 | ||
60 | ||
61 | ##### MAIN ################# | |
62 | ||
63 | _main</code></pre> | |
64 | <p>This outputs:</p> | |
65 | <pre><code>$ ./local-shaarli.sh | |
66 | PHP 5.6.0RC4 Development Server started at Mon Sep 1 21:56:19 2014 | |
67 | Listening on http://localhost:7431 | |
68 | Document root is /home/user/local-shaarli/shaarli | |
69 | Press Ctrl-C to quit. | |
70 | ||
71 | [Mon Sep 1 21:56:27 2014] ::1:57868 [200]: / | |
72 | [Mon Sep 1 21:56:27 2014] ::1:57869 [200]: /index.html | |
73 | [Mon Sep 1 21:56:37 2014] ::1:57881 [200]: /...</code></pre> | |
74 | </body> | |
75 | </html> |