summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: b39dcb80adec9c736cf577e29d5fbe6f49f074fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#Contributor: Leon <leon.tty1@gmail.com>

pkgname=b1freearchiver
pkgdesc="Most friendly and simple free file archiver"
pkgver=1.5.86.4849
pkgrel=2
arch=('i686' 'x86_64')
depends=(qtwebkit)
optdepends=(python: dolphin service menu support)
url="http://www.b1.org"
license=('custom')
options=(strip)
install=$pkgname.install

case "$CARCH" in
	'i686')
		_arch1=32
		_arch2=i386
		md5sums=('0f3c5f0010f9cf67974c1f81f5f1413b')
		;;
	'x86_64')
		_arch1=64
		_arch2=amd64
		md5sums=('e8fd7a8306b23aa9db6cfbfe55bd2954')
		;;
esac    

source=("http://b1.org/download-start/0/os=deb${_arch1}/b1freearchiver_current_stable_${_arch2}.deb")


package() {
	cd "$srcdir"
	tar zxpf data.tar.gz -C "$pkgdir"
	mv "$pkgdir"/usr/bin/b1-kde/* "$pkgdir/usr/lib/$pkgname/"
	rmdir "$pkgdir"/usr/bin/b1-kde
	chmod a+x "$pkgdir"/usr/lib/$pkgname/*

	# These python scripts are total mess, I rewrote them.
	patch "$pkgdir"/usr/lib/b1freearchiver/AddToArchive <<'_EOF_'
--- AddToArchive    2014-02-15 00:23:46.000000000 +0800
+++ AddToArchive    2016-05-08 23:18:23.265395809 +0800
@@ -3,26 +3,30 @@
 import sys
 import os
 import os.path
+import subprocess as subp
+import tempfile
 
 if __name__ == "__main__":
   if len(sys.argv) < 2:
-    print "Error: invalid arguments."
+    sys.stderr.write("Error: invalid arguments."+os.linesep)
     sys.exit(1)
   
-  os.system("rm -f /tmp/b1.lst")
+  with tempfile.NamedTemporaryFile('w+') as w:
+    for f in sys.argv[1: len(sys.argv)]:
+      w.write(f)
+      w.write(os.linesep)
+      w.flush()
   
-  f = file("/tmp/b1.lst",'a')
-  for str in sys.argv[1: len(sys.argv)]:
-    f.write(str)
-    f.write("\n")
-  f.close()
-  
-  real_dir = os.path.dirname(str)
-  command_line = "b1manager a "
-  command_line += "\"*" + os.path.basename(real_dir) + ".zip\" "
-  command_line += "\"@/tmp/b1.lst\""
-  
-  print command_line
-  os.chdir(real_dir)
-  os.system(command_line);
-  sys.exit(0)
+    real_dir = os.path.dirname(os.path.abspath(sys.argv[-1]))
+    if len(sys.argv) == 2:
+        outname = os.path.splitext(sys.argv[1])[0]
+    else:
+        outname = real_dir
+    command_line = ['b1manager','a',
+              '*{}.zip'.format(os.path.basename(outname)),
+              '@{}'.format(w.name)]
+      
+    #print(command_line)
+    os.chdir(real_dir)
+    ret = subp.call(command_line)
+  sys.exit(ret)
_EOF_

	patch "$pkgdir"/usr/lib/b1freearchiver/ExtractTo <<'_EOF_'
--- ExtractTo   2014-02-15 00:23:46.000000000 +0800
+++ ExtractTo   2016-05-08 23:29:22.584108648 +0800
@@ -3,20 +3,18 @@
 import sys
 import os
 import os.path
+import subprocess as subp
 
 def extaract_file(filename):
-  command_line = "b1manager x "
-  command_line += "\"" + filename + "\" "
-  command_line += "\"*" + os.path.dirname(filename) + "\""
-  print command_line
-  os.system(command_line)
+  command_line = ["b1manager", "x", filename,
+          "*{}".format(os.path.dirname(os.path.abspath(filename)))]
+  subp.call(command_line)
   
 if __name__ == "__main__":
   if len(sys.argv) < 2:
-    print "Error: invalid arguments."
+    sys.stderr.write("Error: invalid arguments.")
+    sys.stderr.write(os.linesep)
     sys.exit(1)
 
-  for str in sys.argv[1: len(sys.argv)]:
-    extaract_file(str)
-    
-  sys.exit(0)
+  for f in sys.argv[1: len(sys.argv)]:
+    extaract_file(f)
_EOF_

	patch "$pkgdir"/usr/lib/b1freearchiver/ExtractHere <<'_EOF_'
--- ExtractHere 2014-02-15 00:23:46.000000000 +0800
+++ ExtractHere 2016-05-08 23:30:55.405958018 +0800
@@ -3,20 +3,17 @@
 import sys
 import os
 import os.path
+import subprocess as subp
 
 def extaract_file(filename):
-  command_line = "b1manager x "
-  command_line += "\"" + filename + "\" "
-  command_line += "\"" + os.path.dirname(filename) + "\""
-  print command_line
-  os.system(command_line)
+  command_line = ["b1manager","x",filename,os.path.dirname(os.path.abspath(filename))]
+  subp.call(command_line)
   
 if __name__ == "__main__":
   if len(sys.argv) < 2:
-    print "Error: invalid arguments."
+    sys.stderr.write("Error: invalid arguments.")
+    sys.stderr.write(os.linesep)
     sys.exit(1)
 
-  for str in sys.argv[1: len(sys.argv)]:
-    extaract_file(str)
-    
-  sys.exit(0)
+  for f in sys.argv[1: len(sys.argv)]:
+    extaract_file(f)
_EOF_

	sed -i 's:Exec=/usr/bin/b1/:Exec=/usr/lib/'$pkgname'/:' \
	  "$pkgdir"/usr/share/kde4/services/*.desktop
	find "$pkgdir" -type d -print0 | xargs -0 chmod 755
}