bmc-tools 0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/bin-other/autobackup +70 -0
  3. data/bin-other/autobackup.inc +157 -0
  4. data/bin-other/bob/ExtractPagesFromPDF +0 -0
  5. data/bin-other/bob/backupsync +46 -0
  6. data/bin-other/bob/cachesync +58 -0
  7. data/bin-other/bob/deb +55 -0
  8. data/bin-other/bob/debmirror +2551 -0
  9. data/bin-other/bob/debmirror.marlin +2551 -0
  10. data/bin-other/bob/exif_rotate.sh +34 -0
  11. data/bin-other/bob/exif_rotate_dates.sh +35 -0
  12. data/bin-other/bob/git-big-objects +85 -0
  13. data/bin-other/bob/git-commit-details +22 -0
  14. data/bin-other/bob/git-commit-sizes +16 -0
  15. data/bin-other/bob/git-show-biggest.sh +33 -0
  16. data/bin-other/bob/git_remove_history.sh +24 -0
  17. data/bin-other/bob/git_staged_status.sh +29 -0
  18. data/bin-other/bob/identify_extra_raws +137 -0
  19. data/bin-other/bob/wallpaper_restore.sh +1 -0
  20. data/bin-other/bob/watch_olsr.sh +1 -0
  21. data/bin-other/bob/watch_rbpm_node_status +1 -0
  22. data/bin-other/bob/watermark_bmphoto_large.sh +32 -0
  23. data/bin-other/bob/watermark_bmphoto_small.sh +32 -0
  24. data/bin-other/bubbles/deb +42 -0
  25. data/bin-other/bubbles/firewall.sh +134 -0
  26. data/bin-other/bubbles/kernel-mirror.sh +15 -0
  27. data/bin-other/deb +42 -0
  28. data/bin-other/exif_dates.sh +35 -0
  29. data/bin-other/git-large-files +62 -0
  30. data/bin-other/git_add_upto.sh +54 -0
  31. data/bin-other/git_find_big.sh +33 -0
  32. data/bin-other/git_staged_status.sh +29 -0
  33. data/bin-other/image_resize +43 -0
  34. data/bin-other/kernel-mirror.sh +15 -0
  35. data/bin-other/marlin/deb +42 -0
  36. data/bin-other/marlin/firewall.sh +134 -0
  37. data/bin-other/mysql2svn.sh +36 -0
  38. data/bin-other/syno-cleanup.sh +31 -0
  39. data/bin/dockerize +35 -23
  40. data/bin/image_exif +30 -0
  41. data/bin/image_process +156 -0
  42. data/bin/image_process_wname +138 -0
  43. data/bin/tgv_to_pdf +206 -0
  44. data/bmc-tools.gemspec +1 -1
  45. data/lib/cli.rb +8 -0
  46. data/lib/constants.rb +1 -0
  47. data/lib/docker.rb +15 -0
  48. data/lib/git.rb +21 -0
  49. data/lib/runner.rb +19 -0
  50. metadata +52 -2
@@ -0,0 +1,30 @@
1
+ #!/bin/bash
2
+ total=$#
3
+ current=1
4
+ percent=0
5
+
6
+ echo
7
+ echo "EXIF AND DATES - received $total files to process";
8
+ echo
9
+
10
+ while [[ -n "$1" ]]; do
11
+ percent=`expr 100 \* $current / $total`
12
+ #echo "$percent" ;
13
+ sourcename="`basename \"$1\"`"
14
+
15
+ echo "* $sourcename ($percent%) "
16
+
17
+ if [[ -f "$1" ]]; then
18
+ jhead -autorot -ft "$1" > /dev/null
19
+ if [ "$?" -ne "0" ] ; then
20
+ echo " > FAILED"
21
+ fi
22
+ fi
23
+
24
+ shift
25
+ let current=current+1
26
+ done
27
+
28
+ echo
29
+ echo "All files have been processed.";
30
+ echo
@@ -0,0 +1,156 @@
1
+ #!/bin/bash
2
+
3
+ # Settings
4
+ watermark_dir="/Users/bruno/Dropbox/DATA/BMPHOTO/divers"
5
+ right_margin=0
6
+ bottom_margin=10
7
+ #set -x
8
+
9
+ # Initialize context
10
+ current=1
11
+ percent=0
12
+ framed=0
13
+ named=0
14
+ format="$1"
15
+ shift
16
+ total=$#
17
+ suffix="$format"
18
+
19
+ # Set parameters for each format
20
+ case $format in
21
+ "mini")
22
+ targetsize="400x400>"
23
+ watermark="$watermark_dir/watermark24f.png"
24
+ framed=1
25
+ named=1
26
+ ;;
27
+ "web")
28
+ targetsize="800x600>"
29
+ watermark="$watermark_dir/watermark26f.png"
30
+ framed=2
31
+ ;;
32
+ "web1k")
33
+ targetsize="1000x1000>"
34
+ watermark="$watermark_dir/watermark26f.png"
35
+ framed=1
36
+ ;;
37
+ "www")
38
+ targetsize="1200x1200>"
39
+ #watermark="$watermark_dir/watermark24.png"
40
+ ;;
41
+ "www650")
42
+ targetsize="x650>"
43
+ #watermark="$watermark_dir/watermark24.png"
44
+ ;;
45
+ "pano")
46
+ targetsize="x650>"
47
+ watermark="$watermark_dir/watermark58f.png"
48
+ ;;
49
+ "big")
50
+ targetsize="1800x1800>"
51
+ watermark="$watermark_dir/watermark58f.png"
52
+ framed=10
53
+ ;;
54
+ "bigf")
55
+ targetsize="1800x1800>"
56
+ watermark="$watermark_dir/watermark26f.png"
57
+ ;;
58
+ # "friendly")
59
+ # targetsize="1800x1800>"
60
+ # #suffix="bigf"
61
+ # framed=12
62
+ # watermark="$watermark_dir/watermark30.png"
63
+ # ;;
64
+ "print")
65
+ targetsize="10000x10000>"
66
+ #suffix="print"
67
+ framed=15
68
+ watermark="$watermark_dir/watermark86f.png"
69
+ ;;
70
+ *)
71
+ echo "usage: `basename $0` {mini|web|web1000|www|www650||big|bigf|pano|print} file1 file2 file3 ..."
72
+ exit 1
73
+ ;;
74
+ esac
75
+
76
+ # Check presence of watermak file
77
+ #if [[ ! -f "$watermark" ]]; then
78
+ # echo "quitting: missing watermark file: $watermark"
79
+ # exit 1
80
+ #fi
81
+
82
+ # Evaluate watermark offset according to frame value
83
+ if [ $framed -gt 0 ]; then
84
+ right_margin=`expr ${right_margin} + ${framed}`
85
+ bottom_margin=`expr ${bottom_margin} + ${framed}`
86
+ fi
87
+
88
+ # Welcome
89
+ echo
90
+ echo "###################################";
91
+ echo "# IMAGE PROCESSOR";
92
+ echo "###################################";
93
+ echo "# "
94
+ echo "# number of files: $total";
95
+ echo "# output format: $format";
96
+ echo "# output size: $targetsize";
97
+ echo "# file suffix: $suffix";
98
+ echo "# "
99
+ echo "# watermark: `basename \"$watermark\"`";
100
+ echo "# right margin: $right_margin";
101
+ echo "# bottom margin: $bottom_margin";
102
+ echo "# output frame: $framed";
103
+ echo "# "
104
+ echo
105
+
106
+ # Start processing
107
+ while [[ -n "$1" ]]; do
108
+ percent=`expr 100 \* $current / $total`
109
+ sedfilter="s/^\(.*\)\.\([^\.]*\)$/\1.${suffix}.\2/"
110
+ temp="$1.temp"
111
+ target=`echo "$1" | sed -e "$sedfilter"`
112
+
113
+ sourcename="`basename \"$1\"`"
114
+ targetname="`basename \"${target}\"`"
115
+
116
+ echo "* $sourcename => ${targetname} ($current/$total, $percent%)"
117
+
118
+ if [[ -f "$1" ]]; then
119
+ #jhead "$1" | grep 'Date/Time'
120
+
121
+ # Resize picture, add border, and calculate bottom and right offset according to frame value
122
+ if [ $framed -eq 0 ]; then
123
+ convert -resize "${targetsize}" "$1" "${temp}" > /dev/null || exit 1
124
+ else
125
+ convert -resize "${targetsize}" -frame "${framed}x${framed}+0+0" -mattecolor "#EEEEEE" "$1" "${temp}" > /dev/null || exit 1
126
+ fi
127
+
128
+ # Tag picture with watermark
129
+ if [ -n "$watermark" ]; then
130
+ composite -dissolve 40% -gravity SouthEast -geometry "+${right_margin}+${bottom_margin}" "$watermark" "$temp" "$temp" || exit 1
131
+ fi
132
+
133
+ # Burn filename into the picture
134
+ if [ $named -eq 1 ]; then
135
+ convert "$temp" -gravity SouthWest -background White -splice 0x18 -annotate +5+2 "$sourcename" "$temp"
136
+ fi
137
+
138
+ # Apply jhead to autorotate and fix a real file date
139
+ jhead -autorot -ft "$temp" > /dev/null
140
+
141
+ # Rename to final filename
142
+ mv "$temp" "$target" || exit 1
143
+ #jhead "${target}" | grep 'Date/Time'
144
+ #if [ "$?" -ne "0" ] ; then
145
+
146
+ #echo " > FAILED"
147
+ #fi
148
+ fi
149
+
150
+ shift
151
+ let current=current+1
152
+ done
153
+
154
+ echo
155
+ echo "All files have been processed.";
156
+ echo
@@ -0,0 +1,138 @@
1
+ #!/bin/bash
2
+
3
+ # Settings
4
+ watermark_dir="/Users/bruno/Documents/BMPDOCS/divers"
5
+ right_margin=0
6
+ bottom_margin=10
7
+
8
+ # Initialize context
9
+ current=1
10
+ percent=0
11
+ framed=0
12
+ format="$1"
13
+ shift
14
+ total=$#
15
+ suffix="$format"
16
+
17
+ # Set parameters for each format
18
+ case $format in
19
+ "mini")
20
+ targetsize="400x400>"
21
+ watermark="$watermark_dir/watermark24.png"
22
+ framed=1
23
+ ;;
24
+ "web")
25
+ targetsize="800x600>"
26
+ watermark="$watermark_dir/watermark24.png"
27
+ framed=2
28
+ ;;
29
+ "www")
30
+ targetsize="1200x1200>"
31
+ #watermark="$watermark_dir/watermark24.png"
32
+ framed=0
33
+ ;;
34
+ "wwwp")
35
+ targetsize="x650>"
36
+ #watermark="$watermark_dir/watermark24.png"
37
+ framed=0
38
+ ;;
39
+ "pano")
40
+ targetsize="x650>"
41
+ watermark="$watermark_dir/watermark57.png"
42
+ framed=0
43
+ ;;
44
+ "big")
45
+ targetsize="1800x1800>"
46
+ watermark="$watermark_dir/watermark57.png"
47
+ framed=12
48
+ ;;
49
+ "bigf")
50
+ targetsize="1800x1800>"
51
+ suffix="bigf"
52
+ framed=12
53
+ watermark="$watermark_dir/watermark30.png"
54
+ ;;
55
+ "print")
56
+ targetsize="10000x10000>"
57
+ suffix="print"
58
+ framed=15
59
+ watermark="$watermark_dir/watermark90.png"
60
+ ;;
61
+ *)
62
+ echo "usage: `basename $0` {mini|web|big|bigf|www|pano|print} file1 file2 file3 ..."
63
+ exit 1
64
+ ;;
65
+ esac
66
+
67
+ # Check presence of watermak file
68
+ #if [[ ! -f "$watermark" ]]; then
69
+ # echo "quitting: missing watermark file: $watermark"
70
+ # exit 1
71
+ #fi
72
+
73
+ # Evaluate watermark offset according to frame value
74
+ if [ $framed -gt 0 ]; then
75
+ right_margin=`expr ${right_margin} + ${framed}`
76
+ bottom_margin=`expr ${bottom_margin} + ${framed}`
77
+ fi
78
+
79
+ # Welcome
80
+ echo
81
+ echo "###################################";
82
+ echo "# IMAGE PROCESSOR";
83
+ echo "###################################";
84
+ echo "# "
85
+ echo "# number of files: $total";
86
+ echo "# output format: $format";
87
+ echo "# output size: $targetsize";
88
+ echo "# file suffix: $suffix";
89
+ echo "# "
90
+ echo "# watermark: `basename \"$watermark\"`";
91
+ echo "# right margin: $right_margin";
92
+ echo "# bottom margin: $bottom_margin";
93
+ echo "# output frame: $framed";
94
+ echo "# "
95
+ echo
96
+
97
+ # Start processing
98
+ while [[ -n "$1" ]]; do
99
+ percent=`expr 100 \* $current / $total`
100
+ sedfilter="s/^\(.*\)\.\([^\.]*\)$/\1.${suffix}.\2/"
101
+ temp="$1.temp"
102
+ target=`echo "$1" | sed -e "$sedfilter"`
103
+
104
+ sourcename="`basename \"$1\"`"
105
+ targetname="`basename \"${target}\"`"
106
+
107
+ echo "* $sourcename => ${targetname} ($current/$total, $percent%)"
108
+
109
+ if [[ -f "$1" ]]; then
110
+ # Resize picture, add border, and calculate bottom and right offset according to frame value
111
+ if [ $framed -eq 0 ]; then
112
+ convert -resize "${targetsize}" "$1" "${temp}" > /dev/null || exit 1
113
+ else
114
+ convert -resize "${targetsize}" -frame "${framed}x${framed}+0+0" -mattecolor "#EEEEEE" "$1" "${temp}" > /dev/null || exit 1
115
+ fi
116
+
117
+ # Tag picture with watermark
118
+ if [ -n "$watermark" ]; then
119
+ composite -dissolve 40% -gravity SouthEast -geometry "+${right_margin}+${bottom_margin}" "$watermark" "$temp" "$temp" || exit 1
120
+ fi
121
+
122
+ # Burn filename into the picture
123
+ convert "$temp" "$temp" -gravity SouthWest -background White -splice 0x18 -annotate +5+2 '$sourcename'
124
+
125
+ # Rename to final filename
126
+ mv "$temp" "$target" || exit 1
127
+ #if [ "$?" -ne "0" ] ; then
128
+ #echo " > FAILED"
129
+ #fi
130
+ fi
131
+
132
+ shift
133
+ let current=current+1
134
+ done
135
+
136
+ echo
137
+ echo "All files have been processed.";
138
+ echo
@@ -0,0 +1,206 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'mail'
4
+ require 'pdfkit'
5
+ require "i18n"
6
+ require 'nokogiri'
7
+ require 'json'
8
+
9
+ MAX_DAYS_DIFF = 10
10
+ I18n.enforce_available_locales = false
11
+
12
+
13
+ PDFKit.configure do |config|
14
+ #config.wkhtmltopdf = '/path/to/wkhtmltopdf'
15
+ config.default_options = {
16
+ :page_size => 'A4',
17
+ :print_media_type => true,
18
+ :encoding=>"UTF-8",
19
+ }
20
+ # Use only if your external hostname is unavailable on the server.
21
+ config.verbose = false
22
+ end
23
+
24
+ def adjust_date_within date, daynumber, max
25
+ puts "find_next_within date:#{date.strftime('%Y%m%d')}, daynumber:#{daynumber}, max:#{max}"
26
+ date.upto(date + max.to_i) do |cur|
27
+ next unless cur.day == daynumber.to_i
28
+ puts "find_next_within matched: #{cur.strftime('%Y%m%d')}"
29
+ return cur
30
+ end
31
+ return date
32
+ end
33
+
34
+ def normalize(str)
35
+ n = str.chars.downcase.strip.to_s
36
+ n.gsub!(/[à áâãäåÄÄ?]/u, 'a')
37
+ n.gsub!(/æ/u, 'ae')
38
+ n.gsub!(/[ÄÄ?]/u, 'd')
39
+ n.gsub!(/[çÄ?ÄÄ?Ä?]/u, 'c')
40
+ n.gsub!(/[èéêëÄ?Ä?Ä?Ä?Ä?]/u, 'e')
41
+ n.gsub!(/Æ?/u, 'f')
42
+ n.gsub!(/[ÄÄ?Ä¡Ä£]/u, 'g')
43
+ n.gsub!(/[ĥħ]/, 'h')
44
+ n.gsub!(/[ììíîïīĩĭ]/u, 'i')
45
+ n.gsub!(/[įıijĵ]/u, 'j')
46
+ n.gsub!(/[ķĸ]/u, 'k')
47
+ n.gsub!(/[Å?ľĺļÅ?]/u, 'l')
48
+ n.gsub!(/[ñÅ?Å?Å?Å?Å?]/u, 'n')
49
+ n.gsub!(/[òóôõöøÅÅ?ÅÅ]/u, 'o')
50
+ n.gsub!(/Å?/u, 'oe')
51
+ n.gsub!(/Ä?/u, 'q')
52
+ n.gsub!(/[Å?Å?Å?]/u, 'r')
53
+ n.gsub!(/[Å?Å¡Å?ÅÈ?]/u, 's')
54
+ n.gsub!(/[ťţŧÈ?]/u, 't')
55
+ n.gsub!(/[ùúûüūůűŭũų]/u,'u')
56
+ n.gsub!(/ŵ/u, 'w')
57
+ n.gsub!(/[ýÿŷ]/u, 'y')
58
+ n.gsub!(/[žżź]/u, 'z')
59
+ n.gsub!(/\s+/, ' ')
60
+ n.gsub!(/[^\sa-z0-9_-]/, '')
61
+ n
62
+ end
63
+
64
+ def filename_from_ld ldjson
65
+ parts = []
66
+
67
+ # TGV Prefix
68
+ parts << 'TGV'
69
+
70
+ # puts "gare_dest: #{ldjson[:reservationFor][:arrivalStation][:name]}"
71
+ gare_dest = at ldjson, "reservationFor", "arrivalStation", "name"
72
+ # ][:arrivalStation][:name]
73
+ puts "gare_dest: #{gare_dest}"
74
+ parts << gare_dest.downcase.capitalize
75
+
76
+ # Ajout de la date en prefixe
77
+ #final = adjust_date_within mail.date, jour.to_i, MAX_DAYS_DIFF
78
+
79
+ # Fallback name
80
+ #parts << oid if parts.empty?
81
+
82
+ # Composition
83
+ #parts.unshift final.strftime('%Y%m%d')
84
+ return I18n.transliterate parts.join(' ')
85
+ end
86
+
87
+ # def filename mail, html
88
+ # parts = []
89
+
90
+ # # Date du mail
91
+
92
+ # # Hash du corps
93
+ # oid = mail.object_id
94
+ # subject = mail.subject
95
+
96
+ # # Confirmation SNCF
97
+ # if mail.subject.include? 'Confirmation pour votre voyage'
98
+ # # TGV Prefix
99
+ # parts << 'TGV'
100
+
101
+ # # Destinations et journee
102
+ # if m = /voyage([^-]+)\-([^,]+),/i.match(subject)
103
+ # parts << m[2].strip.capitalize
104
+ # end
105
+
106
+ # # Numero de dossier
107
+ # if m = /dossier : ([A-Z0-9]+)/i.match(html)
108
+ # parts << m[1].strip
109
+ # end
110
+
111
+ # # Nom du jour
112
+ # if m = /aller le ([0-9]+) ([^\.]+)/i.match(subject)
113
+ # jour = m[1].strip
114
+ # mois = m[2].strip
115
+ # # parts << "- #{jour} #{mois[0..2]}"
116
+ # parts << "- #{jour} #{mois}"
117
+ # end
118
+ # end
119
+
120
+ # # Ajout de la date en prefixe
121
+ # final = adjust_date_within mail.date, jour.to_i, MAX_DAYS_DIFF
122
+
123
+ # # Composition
124
+ # #parts << oid
125
+ # parts.unshift final.strftime('%Y%m%d')
126
+ # return I18n.transliterate parts.join(' ')
127
+ # end
128
+
129
+
130
+ def process message
131
+ # Parse the message
132
+ mail = Mail.read_from_string message
133
+ abort "ABORTING: FAILED TO PARSE EMAIL" if mail.nil? || mail.html_part.nil?
134
+ #html = mail.html_part.body.to_s
135
+ html = mail.html_part.body.decoded
136
+
137
+ # Extract HTML part
138
+ puts " subject: #{mail.subject}"
139
+ puts " from: #{mail.from}"
140
+ #html = mail.html_part.body.to_s
141
+
142
+ puts " declared encoding: #{html.encoding}"
143
+ #html.force_encoding(Encoding::ISO_8859_1)
144
+ html.force_encoding(Encoding::UTF_8)
145
+ # html.encode!(Encoding::UTF_8)
146
+ puts " new encoding: #{html.encoding}"
147
+ # html = mail.html_part.body.to_s.encode(Encoding::ISO_8859_1, Encoding::UTF_8)
148
+ # html = mail.html_part.body.to_s.encode(Encoding::UTF_8)
149
+ # html = mail.html_part.body.to_s.encode("ISO-8859-1", "utf-8")
150
+ puts " html: #{(html.size/1024).round} kB"
151
+
152
+ # Extract LD JSON
153
+ ldjson = extract_ld_json(html)
154
+ puts " ld-json: #{ldjson.keys.inspect}"
155
+ puts " ld-json: #{ldjson.to_yaml}"
156
+
157
+ # Build filename and PDF output
158
+ if ldjson.is_a? Hash
159
+ # Infos du HTML
160
+ basename = filename_from_ld ldjson
161
+ else
162
+ # Hash du corps
163
+ basename = mail.object_id
164
+ end
165
+
166
+ #basename = filename mail, html
167
+ puts " basename: #{basename}"
168
+ #pdf = WickedPdf.new.pdf_from_string(html)
169
+
170
+ kit = PDFKit.new html
171
+
172
+ # Write both components
173
+ #File.write "#{basename}.html", html
174
+ kit.to_file "#{basename}.pdf"
175
+ #puts " output: #{pdf_file} (#{(pdf.size/1024).round} kB)"
176
+ end
177
+
178
+
179
+ def extract_ld_json(html)
180
+ doc = Nokogiri::HTML(html)
181
+
182
+ # Find a LD+JSON block
183
+ script = doc.at('script[type="application/ld+json"]')
184
+ return nil unless script
185
+
186
+ # Parse it
187
+ return JSON.parse script.text
188
+ end
189
+
190
+ def at data, *path
191
+ path.reduce(data) { |m, key| m && m[key.to_s] }
192
+ end
193
+
194
+
195
+ # For each file found, process if
196
+ Dir.glob('*.eml').each do |file|
197
+ puts "======================================================"
198
+ puts file
199
+ contents = IO.read file
200
+ process contents
201
+
202
+ #File.delete file
203
+ puts "removed file"
204
+ puts
205
+ end
206
+