Commit ed979253eb3f910775f14320983a08f4704b9ec3
1 parent
85eedc50
Fixed #1, rsync password moved to conf file
Showing
1 changed file
with
18 additions
and
8 deletions
blimp.nim
... | ... | @@ -20,7 +20,7 @@ import md5, os, osproc, parseopt2, strutils, parsecfg, streams, lapp, subexes |
20 | 20 | # ~/blimpstore/.blimp.conf |
21 | 21 | |
22 | 22 | var |
23 | - blimpStore, uploadCommandFormat, downloadCommandFormat, deleteCommandFormat: string | |
23 | + blimpStore, uploadCommandFormat, downloadCommandFormat, deleteCommandFormat, rsyncPassword: string | |
24 | 24 | remoteBlimpStore: string = nil |
25 | 25 | verbose: bool |
26 | 26 | |
... | ... | @@ -28,14 +28,15 @@ let |
28 | 28 | defaultConfig = """ |
29 | 29 | [rsync] |
30 | 30 | # Set this to your remote rsync daemon area |
31 | -remote = "blimp@some-rsync-server.com::blimpstore" | |
31 | +remote = "blimpuser@some-rsync-server.com::blimpstore" | |
32 | +password = some-good-rsync-password-for-blimpuser | |
32 | 33 | |
33 | 34 | # The following three formats should not need editing |
34 | 35 | # $1 is filename, $2 is remote and $3 is the local blimpstore |
35 | -upload = "rsync --password-file ~/blimp.pass -avzP $3/$1 $2/" | |
36 | -download = "rsync --password-file ~/blimp.pass -avzP $2/$1 $3/" | |
36 | +upload = "rsync --password-file $3/.blimp.pass -avzP $3/$1 $2/" | |
37 | +download = "rsync --password-file $3/.blimp.pass -avzP $2/$1 $3/" | |
37 | 38 | # This deletes a single file from destination, that is already deleted in source |
38 | -delete = "rsync --password-file ~/blimp.pass -dv --delete --existing --ignore-existing --include '$1' --exclude '*' $3/ $2" | |
39 | +delete = "rsync --password-file $3/.blimp.pass -dv --delete --existing --ignore-existing --include '$1' --exclude '*' $3/ $2" | |
39 | 40 | """ |
40 | 41 | |
41 | 42 | # Load blimp.conf file, overkill for now but... |
... | ... | @@ -61,6 +62,8 @@ proc parseConfFile(filename: string) = |
61 | 62 | downloadCommandFormat = e.value |
62 | 63 | of "delete": |
63 | 64 | deleteCommandFormat = e.value |
65 | + of "password": | |
66 | + rsyncPassword = e.value | |
64 | 67 | else: |
65 | 68 | quit("Unknown configuration: " & e.key) |
66 | 69 | of cfgOption: |
... | ... | @@ -74,12 +77,19 @@ proc run(cmd: string): auto = |
74 | 77 | if verbose: echo(cmd) |
75 | 78 | execCmd(cmd) |
76 | 79 | |
80 | +# Every rsync command, make sure we have a password file | |
81 | +proc rsyncRun(cmd: string): auto = | |
82 | + writeFile(blimpStore / ".blimp.pass", rsyncPassword) | |
83 | + if execCmd("chmod 600 " & blimpStore / ".blimp.pass") != 0: | |
84 | + quit("Failed to chmod 600 " & blimpStore / ".blimp.pass") | |
85 | + run(cmd) | |
86 | + | |
77 | 87 | # Upload a file to the remote master blimpStore |
78 | 88 | proc uploadFile(blimpFilename: string) = |
79 | 89 | if remoteBlimpStore.isNil: |
80 | 90 | echo("Remote blimpstore not set in configuration file, skipping uploading content:\n\t" & blimpFilename) |
81 | 91 | return |
82 | - let errorCode = run(format(uploadCommandFormat, blimpFilename, remoteBlimpStore, blimpStore)) | |
92 | + let errorCode = rsyncRun(format(uploadCommandFormat, blimpFilename, remoteBlimpStore, blimpStore)) | |
83 | 93 | if errorCode != 0: |
84 | 94 | quit("Something went wrong uploading " & blimpFilename & " to " & remoteBlimpStore, 2) |
85 | 95 | |
... | ... | @@ -87,7 +97,7 @@ proc uploadFile(blimpFilename: string) = |
87 | 97 | proc downloadFile(blimpFilename: string) = |
88 | 98 | if remoteBlimpStore.isNil: |
89 | 99 | quit("Remote blimpstore not set in configuration file, can not download content:\n\t" & blimpFilename) |
90 | - let errorCode = run(format(downloadCommandFormat, blimpFilename, remoteBlimpStore, blimpStore)) | |
100 | + let errorCode = rsyncRun(format(downloadCommandFormat, blimpFilename, remoteBlimpStore, blimpStore)) | |
91 | 101 | if errorCode != 0: |
92 | 102 | quit("Something went wrong downloading " & blimpFilename & " from " & remoteBlimpStore, 3) |
93 | 103 | |
... | ... | @@ -95,7 +105,7 @@ proc downloadFile(blimpFilename: string) = |
95 | 105 | proc remoteDeleteFile(blimpFilename: string) = |
96 | 106 | if remoteBlimpStore.isNil: |
97 | 107 | return |
98 | - let errorCode = run(format(deleteCommandFormat, blimpFilename, remoteBlimpStore, blimpStore)) | |
108 | + let errorCode = rsyncRun(format(deleteCommandFormat, blimpFilename, remoteBlimpStore, blimpStore)) | |
99 | 109 | if errorCode != 0: |
100 | 110 | quit("Something went wrong deleting " & blimpFilename & " from " & remoteBlimpStore, 3) |
101 | 111 | ... | ... |