qasim 0.1.11.dev.2014102811

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +31 -0
  3. data/Gemfile +7 -0
  4. data/LICENSE-GPL-3 +674 -0
  5. data/Makefile +180 -0
  6. data/README.md +81 -0
  7. data/Rakefile +1 -0
  8. data/TODO.md +28 -0
  9. data/bin/qasim-cli +89 -0
  10. data/bin/qasim-gui +300 -0
  11. data/conf/config +2 -0
  12. data/conf/default.map +32 -0
  13. data/conf/qasim.desktop +13 -0
  14. data/data/icons/qasim.128.png +0 -0
  15. data/data/icons/qasim.16.png +0 -0
  16. data/data/icons/qasim.256.png +0 -0
  17. data/data/icons/qasim.32.png +0 -0
  18. data/data/icons/qasim.64.png +0 -0
  19. data/data/icons/qasim.png +0 -0
  20. data/data/icons/qasim.svg +192 -0
  21. data/data/text/authors.html +7 -0
  22. data/data/text/gpl-3.0-standalone.html +694 -0
  23. data/data/text/thanks.html +0 -0
  24. data/debian/changelog +73 -0
  25. data/debian/compat +1 -0
  26. data/debian/control +13 -0
  27. data/debian/copyright +38 -0
  28. data/debian/dirs +3 -0
  29. data/debian/docs +0 -0
  30. data/debian/rules +80 -0
  31. data/debian/source/format +1 -0
  32. data/demo.map +29 -0
  33. data/examples/config +2 -0
  34. data/examples/default.map +32 -0
  35. data/lib/qasim.rb +11 -0
  36. data/lib/qasim/config.rb +56 -0
  37. data/lib/qasim/configold.rb +123 -0
  38. data/lib/qasim/constants.rb +11 -0
  39. data/lib/qasim/map.rb +225 -0
  40. data/lib/qasim/qasim.qrc +8 -0
  41. data/lib/qasim/ui.rb +7 -0
  42. data/lib/qasim/ui/about.rb +58 -0
  43. data/lib/qasim/ui/about.ui +192 -0
  44. data/lib/qasim/ui/listmaps.ui +59 -0
  45. data/lib/qasim/ui/preferences.rb +12 -0
  46. data/lib/qasim/ui/preferences.ui +90 -0
  47. data/lib/qasim/version.rb +5 -0
  48. data/man/qasim-cli.1 +98 -0
  49. data/man/qasim-gui.1 +98 -0
  50. data/man/sshfs-mapper.1 +98 -0
  51. data/mapparser.y +155 -0
  52. data/qasim.gemspec +34 -0
  53. data/sshfs-mapper.completion +24 -0
  54. data/sshfs-mapper.sh +253 -0
  55. metadata +147 -0
data/mapparser.y ADDED
@@ -0,0 +1,155 @@
1
+
2
+ class MapParser
3
+ rule
4
+
5
+ commands
6
+ : commands command_blk SEMICOLON { puts "GOT A COMMAND" }
7
+ | /* none */ { puts "no command found" }
8
+
9
+ command_blk
10
+ : global_blk
11
+ | server_blk
12
+
13
+ server_blk
14
+ : SERVER STRING OBRACE server_opts EBRACE { puts "[server #{val[1]}]" }
15
+
16
+ global_blk
17
+ : GLOBAL OBRACE global_opts EBRACE
18
+
19
+ server_opts
20
+ : server_opts server_opt SEMICOLON
21
+ | /* none */
22
+
23
+ server_opt
24
+ : user_opt { puts "=> user opt" }
25
+ | port_opt { puts "=> port opt" }
26
+ | automount_opt { puts "=> automount opt" }
27
+ | compress_opt { puts "=> compress opt" }
28
+ | reconnect_opt { puts "=> reconnect opt" }
29
+ | server_map_blk { puts "=> server_map blk" }
30
+
31
+ server_map_blk
32
+ : MAP STRING OBRACE server_map_opts EBRACE
33
+
34
+ server_map_opts
35
+ : server_map_opts server_map_opt SEMICOLON
36
+ | /* none */
37
+
38
+ server_map_opt
39
+ : remote_opt
40
+ | local_opt
41
+ | user_opt
42
+ | port_opt
43
+ | compress_opt
44
+
45
+ user_opt
46
+ : USER STRING { puts "* user = #{val[1]}" }
47
+
48
+ port_opt
49
+ : PORT NUMBER { puts "* port = #{val[1]}" }
50
+
51
+ automount_opt
52
+ : AUTOMOUNT boolean { puts "* automount = #{@bool_result}" }
53
+
54
+ compress_opt
55
+ : COMPRESS boolean { puts "* compress = #{@bool_result}" }
56
+
57
+ reconnect_opt
58
+ : RECONNECT boolean { puts ( "* reconnect = #{@bool_result}" ) }
59
+
60
+ boolean
61
+ : BOOL_TRUE { @bool_result = true }
62
+ | BOOL_FALSE { @bool_result = false }
63
+
64
+ end
65
+
66
+ ---- header ----
67
+
68
+ # calc.rb : generated by racc
69
+ #
70
+ require 'strscan'
71
+ #require 'map.rb'
72
+
73
+ ---- inner ----
74
+
75
+ def parse( str )
76
+ puts "parse start..."
77
+ tokens = []
78
+
79
+ scanner = StringScanner.new( str )
80
+ puts ( "scanner?" + scanner.string )
81
+
82
+ until scanner.eos?
83
+ puts "scanning.. at #{scanner.pos}"
84
+ case
85
+ when m = scanner.scan( /\/\/.*$/ )
86
+ # comments
87
+ when m = scanner.scan( /(\s+|\n)/ )
88
+ # whitespace and newlines
89
+ when m = scanner.scan( /\{/ )
90
+ tokens.push [:OBRACE, m]
91
+ when m = scanner.scan( /\}/ )
92
+ tokens.push [:EBRACE, m]
93
+ when m = scanner.scan( /;/ )
94
+ tokens.push [:SEMICOLON, m]
95
+ when m = scanner.scan( /\d+/ )
96
+ tokens.push [:NUMBER, m]
97
+ when m = scanner.scan( /user/i )
98
+ tokens.push [:USER, m]
99
+ when m = scanner.scan( /automount/i )
100
+ tokens.push [:AUTOMOUNT, m]
101
+ when m = scanner.scan( /reconnect/i )
102
+ tokens.push [:RECONNECT, m]
103
+ when m = scanner.scan( /compress/i )
104
+ tokens.push [:COMPRESS, m]
105
+ when m = scanner.scan( /port/i )
106
+ tokens.push [:PORT, m]
107
+ when m = scanner.scan( /(true|1|yes)/i )
108
+ tokens.push [:BOOL_TRUE, m]
109
+ when m = scanner.scan( /(false|0|no)/i )
110
+ tokens.push [:BOOL_FALSE, m]
111
+ when m = scanner.scan( /".+?"/i )
112
+ tokens.push [:STRING, m]
113
+ when m = scanner.scan( /map/i )
114
+ tokens.push [:MAP, m]
115
+ when m = scanner.scan( /server/i )
116
+ tokens.push [:SERVER, m]
117
+ when m = scanner.scan( /./ )
118
+ tokens.push [:UNMATCHED, m]
119
+ puts "UNMATCHED #{m} after #{scanner.pre_match}"
120
+ end
121
+ end
122
+ puts "tokenization ok"
123
+ tokens.push [false, false]
124
+ @last_value = yyparse( tokens, :each )
125
+ puts "parse end... "
126
+ end
127
+
128
+ def on_error(error_token_id, error_value, value_stack)
129
+ msg = "parse error "
130
+ msg << "after #{value_stack.last} " if value_stack.length > 1
131
+ #msg << "after #{value_stack.last} " unless value_stack.empty?
132
+ msg << "on #{token_to_str(error_token_id)} #{error_value}"
133
+ raise ParseError, msg
134
+ end
135
+
136
+
137
+ ---- footer ----
138
+
139
+ puts "GOO"
140
+
141
+ bigstr = ""
142
+ STDIN.read.split(/\n/).each do |a|
143
+ puts "READING #{a}"
144
+ bigstr = bigstr + a
145
+ end
146
+
147
+ puts "PARSING NOW..."
148
+
149
+ parser = MapParser.new
150
+ begin
151
+ val = parser.parse( bigstr )
152
+ print '= ', val, "\n"
153
+ rescue ParseError
154
+ puts $!
155
+ end
data/qasim.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'qasim/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "qasim"
8
+ spec.version = if `git branch`.split($/).include?("* develop") then
9
+ Qasim::APP_VERSION + '.dev.' + Time.now.utc.strftime('%Y%m%d%H')
10
+ else
11
+ Qasim::APP_VERSION
12
+ end
13
+ spec.authors = ["Glenn Y. Rolland"]
14
+ spec.email = ["glenux@glenux.net"]
15
+ spec.summary = %q{Easy mount solution for SSH filesystems.}
16
+ spec.description = %q{Qasim is a front-end for sshfs, the filesystem
17
+ client based on fuse and ssh. It provides automating and global settings
18
+ control for sshfs mounts.}
19
+ spec.homepage = "http://glenux.github.io/qasim"
20
+ spec.license = "GPL-3"
21
+
22
+ spec.files = `git ls-files`.split($/)
23
+ .concat(Dir['*/**/*_ui.rb'])
24
+ .concat(Dir['*/**/*_qrc.rb'])
25
+
26
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.5"
31
+ spec.add_development_dependency "rake"
32
+
33
+ spec.add_runtime_dependency "qtbindings", "~> 4.8.6.0"
34
+ end
@@ -0,0 +1,24 @@
1
+ #!/bin/sh
2
+
3
+ _sshfsmapper_opts()
4
+ {
5
+ local cur prev sshfsmapper_opts sshfsmapper_maps
6
+
7
+ COMPREPLY=()
8
+ cur="${COMP_WORDS[COMP_CWORD]}"
9
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
10
+
11
+ sshfsmapper_opts='-s -h -i -l -u -a'
12
+ if [[ "$cur" == -* ]]; then
13
+ COMPREPLY=( $( compgen -W "$sshfsmapper_opts" -- $cur ) )
14
+ else
15
+ if [[ "$prev" == -s ]]; then
16
+ sshfsmapper_maps=$( sshfs-mapper -l 2> /dev/null )
17
+ COMPREPLY=( $( compgen -W "$sshfsmapper_maps" -- $cur ) )
18
+ else
19
+ COMPREPLY=( $( compgen -W "$sshfsmapper_opts" -- $cur ) )
20
+ fi
21
+ fi
22
+ }
23
+
24
+ complete -F _sshfsmapper_opts $default sshfs-mapper
data/sshfs-mapper.sh ADDED
@@ -0,0 +1,253 @@
1
+ #!/bin/sh
2
+ # vim: set ts=2 sw=2 :
3
+ set -u
4
+
5
+
6
+ ################################################################################
7
+ ##
8
+ ## Variables initializations
9
+ ##
10
+
11
+ set |grep -q '^XDG_CONFIG_HOME' || XDG_CONFIG_HOME="$HOME/.config"
12
+ SSHFS_DIR="$XDG_CONFIG_HOME/sshfs-mapper"
13
+ SSHFS_CONFIG="$SSHFS_DIR/config"
14
+ SSHFS_MOUNT=1
15
+ SSHFS_HOSTS_SELECTION=0
16
+
17
+
18
+ ################################################################################
19
+ ##
20
+ ## Functions definitions
21
+ ##
22
+
23
+ read_conf() {
24
+ local config=$1
25
+ local var=$2
26
+ local value="`eval echo \`cat $config |grep "^$2=" |sed "s/$2=//"\``"
27
+ echo "$value"
28
+ }
29
+
30
+ do_mount() {
31
+ local remotedir=$1
32
+ local localdir=$2
33
+ local remoteport=$3
34
+
35
+ set -x
36
+ sshfs \
37
+ -o allow_root \
38
+ -o idmap=user \
39
+ -o uid=`id -u` \
40
+ -o gid=`id -g` \
41
+ -o reconnect \
42
+ -o workaround=all \
43
+ -o cache_timeout=240 \
44
+ -o ServerAliveInterval 15 \
45
+ -o no_readahead \
46
+ -o Ciphers=arcfour \
47
+ -o Port=$remoteport \
48
+ $remotedir \
49
+ $localdir
50
+ set +x
51
+
52
+ #-o compression=yes
53
+ }
54
+
55
+ do_umount() {
56
+ local remotedir=$1
57
+ local localdir=$2
58
+ fusermount -u $localdir
59
+ }
60
+
61
+ do_usage() {
62
+ cat >&2 <<EOF
63
+ Usage: `basename $0` [options]
64
+ -h, --help Show this help and exit.
65
+ -i, --init Initialize user configuration.
66
+ -l, --list List available maps.
67
+ -a, --all Use all maps.
68
+ -s, --select <map> Only use specified map.
69
+ -u, --umount Umount user maps (mount if not specified).
70
+ -v, --verbose Be verbose.
71
+ EOF
72
+ exit 1
73
+ }
74
+
75
+ do_initialize()
76
+ {
77
+ echo "Initializing user maps..."
78
+ if [ -e "$SSHFS_DIR" ]; then
79
+ echo -e "\nERROR: Configuration directory already exists!" >&2
80
+ echo "To erase your setup, please manually remove directory \"$SSHFS_DIR\" first." >&2
81
+ exit 1
82
+ else
83
+ mkdir -p "$SSHFS_DIR"
84
+ cat > "$SSHFS_DIR/config" <<EOF
85
+ MOUNTPOINT=\$HOME/mnt
86
+ LINKTO=\$HOME
87
+ EOF
88
+
89
+ cat > "$SSHFS_DIR/default.map" <<EOF
90
+ REMOTE_USER=\$USER
91
+ REMOTE_HOST=example.com
92
+ REMOTE_PORT=22
93
+
94
+ MAP=RemoteDocs /home/\$USER/Documents
95
+ MAP=RemoteMusic /home/\$USER/Music
96
+ EOF
97
+ echo -e "\nManually edit configuration files in \"$SSHFS_DIR\""
98
+ echo "to adjust sshfs-mapper configuration to your settings."
99
+ echo -e "\nType \"man sshfs-mapper\" to get more help."
100
+
101
+ exit 0
102
+ fi
103
+ }
104
+
105
+
106
+ ################################################################################
107
+ ##
108
+ ## Parse options and mount/umount
109
+ ##
110
+
111
+ SSHFS_HOST_PATTERN=" "
112
+ SSHFS_HOST_LIMIT=0
113
+ SSHFS_HOST_LIST=0
114
+ SSHFS_HOST_AUTO=0
115
+ SSHFS_VERBOSE=0
116
+ OPTFOUND=0
117
+ while true
118
+ do
119
+ OPT=${1:-}
120
+ if [ -z $OPT ]; then break ; fi
121
+ shift
122
+ OPTARG=${1:-}
123
+ #echo "$OPT?"
124
+ case "$OPT" in
125
+ --verbose|-v) #be verbose
126
+ SSHFS_VERBOSE=1
127
+ ;;
128
+ --all|-a) # mount all
129
+ SSHFS_HOST_AUTO=1
130
+ OPTFOUND=1
131
+ ;;
132
+ --init|-i) # init (copy config files in user HOME)
133
+ do_initialize
134
+ OPTFOUND=1
135
+ ;;
136
+ --umount|-u) # umount
137
+ echo "Umounting..."
138
+ SSHFS_MOUNT=0
139
+ OPTFOUND=1
140
+ ;;
141
+ --select|-s) # only selected hosts
142
+ SSHFS_HOST_PATTERN="${SSHFS_HOST_PATTERN}${OPTARG} "
143
+ SSHFS_HOST_LIMIT=1
144
+ shift
145
+ OPTFOUND=1
146
+ ;;
147
+ --list|-l)
148
+ SSHFS_HOST_LIST=1
149
+ OPTFOUND=1
150
+ ;;
151
+ --help|-h)
152
+ do_usage
153
+ OPTFOUND=1
154
+ ;;
155
+ *)
156
+ do_usage
157
+ OPTFOUND=1
158
+ ;;
159
+ esac
160
+ done
161
+ if [ $OPTFOUND -eq 0 ]; then
162
+ do_usage
163
+ fi
164
+
165
+ if [ ! -e $SSHFS_DIR ]; then mkdir $SSHFS_DIR ; fi
166
+ if [ ! -e $SSHFS_DIR ]; then
167
+ echo -e "\nERROR: Unable to create $SSHFS_DIR" >&2
168
+ exit 1
169
+ fi
170
+
171
+ if [ ! -e "$SSHFS_CONFIG" ]; then
172
+ echo "MOUNTPOINT=\$HOME/mnt" >> "$SSHFS_CONFIG"
173
+ fi
174
+ if [ ! -e "$SSHFS_CONFIG" ]; then
175
+ echo -e "\nERROR: Unable to find config file." >&2
176
+ exit 1
177
+ fi
178
+
179
+ for map_file in $SSHFS_HOST_PATTERN; do
180
+ if [ ! -e "$SSHFS_DIR/$map_file.map" ]; then
181
+ echo -e "\nERROR: Unable to find map file '$map_file.map'." >&2
182
+ fi
183
+ done
184
+
185
+ mountpoint=$( read_conf "$SSHFS_CONFIG" MOUNTPOINT )
186
+ if [ "x$mountpoint" = "x" ]; then
187
+ echo -e "\nERROR: Mountpoint undefined." >&2
188
+ echo "Edit mountpoint definition in \"$SSHFS_CONFIG\"" >&2
189
+ exit 1;
190
+ fi
191
+
192
+ is_mounted() {
193
+ local map_name=$1
194
+
195
+ mount | grep -q " $mountpoint/$map_name "
196
+ return $?
197
+ }
198
+
199
+ for map_file in `find "$SSHFS_DIR" -follow -type f -name '*.map' `; do
200
+ if [ $SSHFS_HOST_LIST -eq 1 ]; then
201
+ basename `echo ${map_file} | sed 's/.map$//'`
202
+ continue
203
+ fi
204
+ if [ $SSHFS_HOST_LIMIT -eq 1 ]; then
205
+ if ! echo "$SSHFS_HOST_PATTERN" | grep -q " `basename \`echo ${map_file} |sed s'/.map$//' \`` " ; then
206
+ continue
207
+ fi
208
+ else
209
+ if [ $SSHFS_HOST_AUTO -eq 0 ]; then
210
+ continue
211
+ fi
212
+ fi
213
+ remote_host=$( read_conf $map_file REMOTE_HOST )
214
+ remote_user=$( read_conf $map_file REMOTE_USER )
215
+ remote_port=$( read_conf $map_file REMOTE_PORT )
216
+ map=$( read_conf $map_file MAP )
217
+ echo "Map: $remote_user@$remote_host"
218
+
219
+ nc -z $remote_host $remote_port > /dev/null 2>&1
220
+ if [ $? != 0 ]; then
221
+ echo " ERROR: can't find the server at $remote_host:$remote_port"
222
+ continue
223
+ fi
224
+
225
+ map_count=0
226
+ map_name=""
227
+ remote_dir=""
228
+ for map_item in $map; do
229
+ if [ $map_count = 0 ]; then map_name=$map_item ; fi
230
+ if [ $map_count = 1 ]; then remote_dir=$map_item ; fi
231
+ map_count=$(( ( $map_count + 1 ) % 2 ))
232
+ if [ $map_count = 0 ]; then
233
+ echo " $map_name => $remote_dir"
234
+ if ! is_mounted $map_name ; then
235
+ if [ $SSHFS_MOUNT = 1 ]; then
236
+ mkdir -p $mountpoint/$map_name
237
+ do_mount $remote_user@$remote_host:$remote_dir $mountpoint/$map_name $remote_port
238
+ rm -f $HOME/$map_name
239
+ ln -s $mountpoint/$map_name $HOME/$map_name
240
+ fi
241
+ else
242
+ if [ $SSHFS_MOUNT = 0 ]; then
243
+ do_umount $remote_user@$remote_host:$remote_dir $mountpoint/$map_name
244
+ rm -f $HOME/$map_name
245
+ fi
246
+ if [ $SSHFS_MOUNT = 1 ]; then
247
+ echo " (Already mounted on $mountpoint/$map_name)"
248
+ fi
249
+ fi
250
+ fi
251
+ done
252
+ done
253
+