Commit abbc06c70c476280fd304b432c6f4d42caaecabf

Authored by Göran Krampe
2 parents 85eedc50 ed979253

Merge branch 'issue1' into 'master'

Issue1

Fixed #1

See merge request !1
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,7 +20,7 @@ import md5, os, osproc, parseopt2, strutils, parsecfg, streams, lapp, subexes
20 # ~/blimpstore/.blimp.conf 20 # ~/blimpstore/.blimp.conf
21 21
22 var 22 var
23 - blimpStore, uploadCommandFormat, downloadCommandFormat, deleteCommandFormat: string 23 + blimpStore, uploadCommandFormat, downloadCommandFormat, deleteCommandFormat, rsyncPassword: string
24 remoteBlimpStore: string = nil 24 remoteBlimpStore: string = nil
25 verbose: bool 25 verbose: bool
26 26
@@ -28,14 +28,15 @@ let @@ -28,14 +28,15 @@ let
28 defaultConfig = """ 28 defaultConfig = """
29 [rsync] 29 [rsync]
30 # Set this to your remote rsync daemon area 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 # The following three formats should not need editing 34 # The following three formats should not need editing
34 # $1 is filename, $2 is remote and $3 is the local blimpstore 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 # This deletes a single file from destination, that is already deleted in source 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 # Load blimp.conf file, overkill for now but... 42 # Load blimp.conf file, overkill for now but...
@@ -61,6 +62,8 @@ proc parseConfFile(filename: string) = @@ -61,6 +62,8 @@ proc parseConfFile(filename: string) =
61 downloadCommandFormat = e.value 62 downloadCommandFormat = e.value
62 of "delete": 63 of "delete":
63 deleteCommandFormat = e.value 64 deleteCommandFormat = e.value
  65 + of "password":
  66 + rsyncPassword = e.value
64 else: 67 else:
65 quit("Unknown configuration: " & e.key) 68 quit("Unknown configuration: " & e.key)
66 of cfgOption: 69 of cfgOption:
@@ -74,12 +77,19 @@ proc run(cmd: string): auto = @@ -74,12 +77,19 @@ proc run(cmd: string): auto =
74 if verbose: echo(cmd) 77 if verbose: echo(cmd)
75 execCmd(cmd) 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 # Upload a file to the remote master blimpStore 87 # Upload a file to the remote master blimpStore
78 proc uploadFile(blimpFilename: string) = 88 proc uploadFile(blimpFilename: string) =
79 if remoteBlimpStore.isNil: 89 if remoteBlimpStore.isNil:
80 echo("Remote blimpstore not set in configuration file, skipping uploading content:\n\t" & blimpFilename) 90 echo("Remote blimpstore not set in configuration file, skipping uploading content:\n\t" & blimpFilename)
81 return 91 return
82 - let errorCode = run(format(uploadCommandFormat, blimpFilename, remoteBlimpStore, blimpStore)) 92 + let errorCode = rsyncRun(format(uploadCommandFormat, blimpFilename, remoteBlimpStore, blimpStore))
83 if errorCode != 0: 93 if errorCode != 0:
84 quit("Something went wrong uploading " & blimpFilename & " to " & remoteBlimpStore, 2) 94 quit("Something went wrong uploading " & blimpFilename & " to " & remoteBlimpStore, 2)
85 95
@@ -87,7 +97,7 @@ proc uploadFile(blimpFilename: string) = @@ -87,7 +97,7 @@ proc uploadFile(blimpFilename: string) =
87 proc downloadFile(blimpFilename: string) = 97 proc downloadFile(blimpFilename: string) =
88 if remoteBlimpStore.isNil: 98 if remoteBlimpStore.isNil:
89 quit("Remote blimpstore not set in configuration file, can not download content:\n\t" & blimpFilename) 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 if errorCode != 0: 101 if errorCode != 0:
92 quit("Something went wrong downloading " & blimpFilename & " from " & remoteBlimpStore, 3) 102 quit("Something went wrong downloading " & blimpFilename & " from " & remoteBlimpStore, 3)
93 103
@@ -95,7 +105,7 @@ proc downloadFile(blimpFilename: string) = @@ -95,7 +105,7 @@ proc downloadFile(blimpFilename: string) =
95 proc remoteDeleteFile(blimpFilename: string) = 105 proc remoteDeleteFile(blimpFilename: string) =
96 if remoteBlimpStore.isNil: 106 if remoteBlimpStore.isNil:
97 return 107 return
98 - let errorCode = run(format(deleteCommandFormat, blimpFilename, remoteBlimpStore, blimpStore)) 108 + let errorCode = rsyncRun(format(deleteCommandFormat, blimpFilename, remoteBlimpStore, blimpStore))
99 if errorCode != 0: 109 if errorCode != 0:
100 quit("Something went wrong deleting " & blimpFilename & " from " & remoteBlimpStore, 3) 110 quit("Something went wrong deleting " & blimpFilename & " from " & remoteBlimpStore, 3)
101 111