Skip to content

Commit f94a8bc

Browse files
committed
merge the latest master.
2 parents 426fa44 + defeac8 commit f94a8bc

File tree

2 files changed

+106
-50
lines changed

2 files changed

+106
-50
lines changed

README.md

Lines changed: 86 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,61 +7,66 @@ For more background, see the initial [discussion](https://github.com/hackmdio/co
77
*There is an alternative, TypeScript-based CodiMD CLI for `hackmdio/codimd` maintained by the HackMD team here: https://github.com/hackmdio/codimd-cli.*
88
*(it may or may not be compatible with the `hedgedoc/hedgedoc` server)*
99

10-
## Install
10+
## Installation
1111

12-
Dependencies:
13-
- A HedgeDoc server running somewhere
14-
- `curl` (install via `apt install curl` or `brew install curl` on Mac)
15-
- `wget` (install via `apt install wget` or `brew install wget` on Mac)
16-
- `jq` (install via `apt install jq` or `brew install jq` on Mac)
12+
### Dependencies
1713

18-
```bash
19-
git clone https://github.com/hedgedoc/cli
20-
cd cli/bin
21-
# optionally symlink the hedgedoc script somewhere into your $PATH
22-
ln -s $PWD/hedgedoc /usr/local/bin/hedgedoc
23-
24-
# set HEDGEDOC_SERVER environment variable to your server's URL
25-
# it defaults to http://127.0.0.1:3000
26-
export HEDGEDOC_SERVER='https://hedgedoc.example.com'
27-
28-
# Test by creating a new note
29-
hedgedoc login --email
30-
hedgedoc import test.md
31-
```
14+
- A HedgeDoc server running somewhere
15+
- `curl` (install via `apt install curl` or `brew install curl` on Mac)
16+
- `wget` (install via `apt install wget` or `brew install wget` on Mac)
17+
- `jq` (install via `apt install jq` or `brew install jq` on Mac)
3218

33-
## Documentation
19+
### Instructions
3420

35-
### Create/import a new note
36-
```bash
37-
$ hedgedoc import <input_path> [note_id] # takes a local path to a text file, and an optional note id for the new note
38-
qhmNmwmxSmK1H2oJmkKBQQ # returns <note_id> on success
39-
```
40-
You can open the new note on the server by going to `$HEDGEDOC_SERVER/<note_id>`.
21+
Clone the repository.
4122

42-
### Publish an existing note
23+
$ git clone https://github.com/hedgedoc/cli
4324

44-
```bash
45-
$ hedgedoc publish qhmNmwmxSmK1H2oJmkKBQQ # takes a <note_id>
46-
S1ok9no3f # returns public note id
47-
```
48-
You can open the published note on the server by going to `$HEDGEDOC_SERVER/s/<public_note_id>`.
25+
Enter the folder with the script.
4926

50-
### Export an existing note
27+
$ cd cli/bin
5128

52-
```bash
53-
$ hedgedoc export --pdf qhmNmwmxSmK1H2oJmkKBQQ # takes a <note_id>, outputs to <note_id>.pdf by default
54-
$ hedgedoc export --md qhmNmwmxSmK1H2oJmkKBQQ my_note.md # or you can specify an output path explicitly
55-
$ hedgedoc export --html qhmNmwmxSmK1H2oJmkKBQQ
56-
$ hedgedoc export --slides qhmNmwmxSmK1H2oJmkKBQQ my_slides.zip
57-
```
29+
Optionally symlink the hedgedoc script somewhere into your $PATH to make it globally accessible. Otherwise you will have to provide the path to the script manually. This command might need admin rights (sudo)!
30+
31+
$ ln -s $PWD/hedgedoc /usr/local/bin/hedgedoc
32+
33+
Check if the new command exists. You should see the documentation
34+
35+
$ hedgedoc
36+
37+
Set `HEDGEDOC_SERVER` environment variable to your server's URL. It defaults to `http://127.0.0.1:3000` Do this once on the command line or persist it in `.profile` and/or `.bashrc`.
38+
39+
$ export HEDGEDOC_SERVER='https://hedgedoc.example.com'
40+
41+
If you added the variable to `.profile` or `.bashrc`, re-open the terminal to read the new variable.
42+
43+
Test your configuration by creating a new note with FREELY access and no login required. You will receive the generated `<note_id>` for the document like `3jXcabSfSNesbH6KT72ieg`.
44+
45+
**Caution: You won't have the right to delete the new document if not authenticated!**
46+
47+
$ echo "# HedgeDoc!" > test.md
48+
$ hedgedoc import test.md
49+
50+
Check for the document in the browser by concatenating the
51+
address of your server and the `<note_id>`.
52+
53+
## Configuration and usage
54+
55+
### Variants of authentication
56+
57+
It's not necessary to authenticate against the server in order to make use of `hedgedoc-cli`. But without authentication you won't have access to the non-FREELY documents and everything that's accessible behind the login.
5858

59-
### Authenticate and get notes history
59+
#### Authenticate with cookie
60+
61+
Authentication with a cookie is so far the only way if you login with GitLab and the like. Use browser extensions like [Get cookies.txt](https://chrome.google.com/webstore/detail/get-cookiestxt/bgaddhkoddajcdgocldbbfleckgcbcid) to store the cookie in `key.conf`.
62+
63+
Possible you have many lines in `key.conf`. You only need the line with `connect.sid` followed by a long hash!
64+
65+
Optionally add the HEDGEDOC_COOKIES_FILE environment variable to specify where cookies will be stored. It defaults to `~/.config/hedgedoc/key.conf`
6066

6167
```bash
62-
# optionally add the HEDGEDOC_COOKIES_FILE environment variable to specify
63-
# where cookies will be stored. It defaults to ~/.config/hedgedoc-cli/key.conf
64-
$ export HEDGEDOC_COOKIES_FILE=~/.config/hedgedoc-cli/key.conf
68+
# You can put this in .profile and/or .bashrc, too.
69+
$ export HEDGEDOC_COOKIES_FILE=~/.config/hedgedoc/key.conf
6570
```
6671
#### Authenticate with email
6772

@@ -77,7 +82,11 @@ $ hedgedoc login --ldap username p4sW0rD # takes a username and a pas
7782
$ hedgedoc login --ldap # or pass them via stdin prompt instead
7883
```
7984

80-
#### Get auth status, history, and logout
85+
#### Check if authentication works
86+
87+
If your authentication method is set up correctly the following commands will work.
88+
89+
### Get auth status, history, and logout
8190

8291
```bash
8392
$ hedgedoc profile
@@ -105,6 +114,38 @@ You may need to log in again if:
105114
- the hedgedoc server was restarted (which force-expires all sessions as a side-effect)
106115
- the is`$HEDGEDOC_COOKIES_FILE` deleted, moved, or becomes unreadable by `hedgedoc-cli`
107116

117+
### Create/import a new note
118+
119+
```bash
120+
$ hedgedoc import <input_path> [note_id] # takes a local path to a text file, and an optional note id for the new note
121+
qhmNmwmxSmK1H2oJmkKBQQ # returns <note_id> on success
122+
```
123+
124+
You can open the new note on the server by going to `$HEDGEDOC_SERVER/<note_id>`.
125+
126+
The optional `note_id` is only available on servers with `allowFreeURL`
127+
enabled.
128+
Check the [documentation](https://docs.hedgedoc.org/configuration/#users-and-privileges)
129+
for more information.
130+
131+
### Publish an existing note
132+
133+
```bash
134+
$ hedgedoc publish qhmNmwmxSmK1H2oJmkKBQQ # takes a <note_id>
135+
S1ok9no3f # returns public note id
136+
```
137+
You can open the published note on the server by going to `$HEDGEDOC_SERVER/s/<public_note_id>`.
138+
139+
### Export an existing note
140+
141+
```bash
142+
$ hedgedoc export --pdf qhmNmwmxSmK1H2oJmkKBQQ # takes a <note_id>, outputs to <note_id>.pdf by default
143+
$ hedgedoc export --md qhmNmwmxSmK1H2oJmkKBQQ my_note.md # or you can specify an output path explicitly
144+
$ hedgedoc export --html qhmNmwmxSmK1H2oJmkKBQQ
145+
$ hedgedoc export --slides qhmNmwmxSmK1H2oJmkKBQQ my_slides.zip
146+
```
147+
148+
108149
## API Endpoints
109150

110151
These server endpoints are used by this project and can be unstable and undocumented, but may be of use if you're developing your own projects that need API access to HedgeDoc.

bin/hedgedoc

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Config:
8181
\$HEDGEDOC_CONFIG_DIR (defaults to $XDG_CONFIG_HOME/$SCRIPTNAME)
8282
\$HEDGEDOC_COOKIES_FILE (defaults to \$HEDGEDOC_CONFIG_DIR/key.conf)
8383
84-
Usage examples:
84+
Usage examples:
8585
8686
\$ export HEDGEDOC_SERVER='$HEDGEDOC_SERVER'
8787
\$ export HEDGEDOC_COOKIES_FILE=$HEDGEDOC_COOKIES_FILE
@@ -178,7 +178,7 @@ function import_note() {
178178
echo "Hint: You may need to run '$SCRIPTNAME login' to authenticate first." >&2
179179
return 2
180180
fi
181-
echo "$note_id"
181+
echo "$note_id"
182182
}
183183

184184
function export_note() {
@@ -234,7 +234,7 @@ function export_note() {
234234
output_path="${output_path:-$note_id.zip}"
235235
# hack: there is no way to get slide output as zipfile directly.
236236
# we dump it to folder of html files first then zip it.
237-
237+
238238
# check for any existing conflicting file/dir that wget downloads
239239
local temp_folder_name="$(
240240
echo "$HEDGEDOC_SERVER" \
@@ -287,6 +287,18 @@ function user_login_helper_gitlab() {
287287
bash ${HELPER_SCRIPT_DIR}/login-hedgedoc-via-gitlab.sh $username $password >& /dev/null
288288
}
289289

290+
291+
function backup_all_notes() {
292+
output_path="${1:-archive.zip}"
293+
294+
curl \
295+
--silent \
296+
--cookie "$HEDGEDOC_COOKIES_FILE" \
297+
--output "$output_path" \
298+
"${HEDGEDOC_SERVER}/me/export" \
299+
&& echo "$output_path"
300+
}
301+
290302
function user_login() {
291303
local method="${1#--}" username="${2:-}" password="${3:-}" username_arg=""
292304
case "$method" in
@@ -381,7 +393,7 @@ function user_profile() {
381393

382394
function user_history() {
383395
assert_is_authenticated
384-
396+
385397
curl \
386398
--silent \
387399
--cookie "$HEDGEDOC_COOKIES_FILE" \
@@ -422,6 +434,9 @@ function main() {
422434
export)
423435
export_note "${1:-}" "${2:-}" "${3:-}"
424436
;;
437+
backup)
438+
backup_all_notes "${1:-}"
439+
;;
425440
delete)
426441
delete_note "${1:-}"
427442
;;
@@ -448,7 +463,7 @@ function main() {
448463
# Do the usage function of no Command line arguments are given.
449464
if [[ $# -eq 0 ]]; then
450465
set -- "help"
451-
fi
466+
fi
452467

453468
# Allow importing funcs without running main by using `source ./bin/hedgedoc --import`
454469
if [[ "${1:-}" != "--import" ]]; then

0 commit comments

Comments
 (0)