]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - doc/Copy-an-existing-installation-over-SSH-and-serve-it-locally.md
Show page title when sharing via Firefox Social.
[github/shaarli/Shaarli.git] / doc / Copy-an-existing-installation-over-SSH-and-serve-it-locally.md
CommitLineData
992af0b9 1#Copy an existing installation over SSH and serve it locally
1acc87ee 2Example bash script:
3
992af0b9 4```bash
1acc87ee 5#!/bin/bash
6#Description: Copy a Shaarli installation over SSH/SCP, serve it locally with php-cli
7#Will create a local-shaarli/ directory when you run it, backup your Shaarli there, and serve it locally.
8#Will NOT download linked pages. It's just a directly usable backup/copy/mirror of your Shaarli
9#Requires: ssh, scp and a working SSH access to the server where your Shaarli is installed
10#Usage: ./local-shaarli.sh
11#Author: nodiscc (nodiscc@gmail.com)
12#License: MIT (http://opensource.org/licenses/MIT)
13set -o errexit
14set -o nounset
15
16##### CONFIG #################
17#The port used by php's local server
18php_local_port=7431
19
20#Name of the SSH server and path where Shaarli is installed
21#TODO: pass these as command-line arguments
22remotehost="my.ssh.server"
23remote_shaarli_dir="/var/www/shaarli"
24
25
26###### FUNCTIONS #############
27_main() {
28 _CBSyncShaarli
29 _CBServeShaarli
30}
31
32_CBSyncShaarli() {
33 remote_temp_dir=$(ssh $remotehost mktemp -d)
34 remote_ssh_user=$(ssh $remotehost whoami)
35 ssh -t "$remotehost" sudo cp -r "$remote_shaarli_dir" "$remote_temp_dir"
36 ssh -t "$remotehost" sudo chown -R "$remote_ssh_user":"$remote_ssh_user" "$remote_temp_dir"
37 scp -rq "$remotehost":"$remote_temp_dir" local-shaarli
38 ssh "$remotehost" rm -r "$remote_temp_dir"
39}
40
41_CBServeShaarli() {
42 #TODO: allow serving a previously downloaded Shaarli
43 #TODO: ask before overwriting local copy, if it exists
44 cd local-shaarli/
45 php -S localhost:${php_local_port}
46 echo "Please go to http://localhost:${php_local_port}"
47}
48
49
50##### MAIN #################
51
52_main
53```
54
55This outputs:
56
992af0b9 57```bash
1acc87ee 58$ ./local-shaarli.sh
59PHP 5.6.0RC4 Development Server started at Mon Sep 1 21:56:19 2014
60Listening on http://localhost:7431
61Document root is /home/user/local-shaarli/shaarli
62Press Ctrl-C to quit.
63
992af0b9
V
64[Mon Sep 1 21:56:27 2014] ::1:57868 [200]: /[](.html)
65[Mon Sep 1 21:56:27 2014] ::1:57869 [200]: /index.html[](.html)
66[Mon Sep 1 21:56:37 2014] ::1:57881 [200]: /...[](.html)
67```