simple-chmod 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/simple-chmod'
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ print "\n***** Simple-Chmod *****\n\nSyntax for changing permissions is 'none' or 'read write xcute' and leave out by choice.\n\nEnter filename or directory: "
4
+
5
+ require_relative 'simple-chmod/filechecker'
6
+ require_relative 'simple-chmod/perms'
7
+
8
+ STDOUT.flush
9
+ file = gets.chomp
10
+
11
+ check = Filechecker.new(file)
12
+ checker = check.result
13
+
14
+ if checker == true
15
+ print "Filecheck OK.\nWhat permissions do you want to grant to the OWNER of this file?\n"
16
+ STDOUT.flush
17
+ ownerperms = gets.chomp
18
+ chowperms = ChangePerms.new(ownerperms,'u',file)
19
+ chowperms.result
20
+
21
+ print "What permissions do you want to grant to the GROUP of this file?\n"
22
+ STDOUT.flush
23
+ groupperms = gets.chomp
24
+ chgrpperms = ChangePerms.new(groupperms,'g',file)
25
+ chgrpperms.result
26
+
27
+ print "What permissions do you want to grant to the OTHERS?\n"
28
+ STDOUT.flush
29
+ otherperms = gets.chomp
30
+ othrperms = ChangePerms.new(otherperms,'o',file)
31
+ othrperms.result
32
+
33
+ else checker == false
34
+ print "The file doesn't exist.\n"
35
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ class Filechecker
4
+
5
+ def initialize(file)
6
+ @file = file
7
+ end
8
+
9
+ def result
10
+ File.exist?(@file)
11
+ end
12
+
13
+ end
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ class ChangePerms
4
+
5
+ def initialize(perms,type,file)
6
+ @perms = perms
7
+ @type = type
8
+ @file = file
9
+ end
10
+
11
+ def result
12
+ if @perms == 'none'
13
+ shell_script_output = `chmod #{@type}-rwx #{@file}`
14
+ print "Changed permissions.\n"
15
+ elsif @perms == 'read write' || @perms == 'read xcute' || @perms == 'write read' || @perms == 'write xcute' || @perms == 'xcute read' || @perms == 'xcute write' || @perms == 'read' || @perms == 'write' || @perms == 'xcute' ||@perms == 'read write xcute'
16
+ replaceperms = @perms.gsub("read", "r").gsub("write", "w").gsub("xcute", "x")
17
+ finalperms = replaceperms.delete("\s")
18
+ shell_script_output = `chmod #{@type}-rwx #{@file}`
19
+ shell_script_output = `chmod #{@type}+#{finalperms} #{@file}`
20
+ print "Changed permissions.\n"
21
+ else
22
+ print "No valid file permissions.\n"
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-chmod
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,17 +9,21 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-31 00:00:00.000000000 Z
12
+ date: 2014-08-03 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: This simple script is an alternative to the Unix & Linux-terminal chmod
15
- command to change file permissions.
14
+ description: Simple-Chmod is a simple script that allows you to edit file permissions
15
+ through the cli (command line interface).
16
16
  email: firestarter87@users.sf.net
17
- executables: []
17
+ executables:
18
+ - simple-chmod
18
19
  extensions: []
19
20
  extra_rdoc_files: []
20
21
  files:
21
- - simple-chmod.rb
22
- homepage: https://rubygems.org/profiles/firestarter87
22
+ - lib/simple-chmod.rb
23
+ - lib/simple-chmod/filechecker.rb
24
+ - lib/simple-chmod/perms.rb
25
+ - bin/simple-chmod
26
+ homepage: https://rubygems.org/gems/simple-chmod
23
27
  licenses:
24
28
  - GNU GPL v2
25
29
  post_install_message:
@@ -43,5 +47,6 @@ rubyforge_project:
43
47
  rubygems_version: 1.8.23
44
48
  signing_key:
45
49
  specification_version: 3
46
- summary: Simple UNIX/Linux-terminal script to change permissions of a file.
50
+ summary: Simple script to change permissions of a file trough the cli (command line
51
+ interface).
47
52
  test_files: []
@@ -1,155 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # All Simple-Chmod code is Copyright 2011 by Pascal Ryckmans <firestarter87@users.sf.net>.
4
- # This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2 of the License.
5
- # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6
- # You can find a copy of the GNU General Public License on <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
7
-
8
- #Simple-Chmod is a simple script to edit file permissions. If you (as a user) are the file owner you can just run this script with the command ‘simple-chmod’ if you want to change a file that’s not yours you should run the script as root or superuser.
9
- #In order to be able to just run the script trough the command ‘simple-chmod’ you have to follow this instructions.
10
- #These instructions are only tested on Linux but should work on all UNIX/Linux systems. Simply said, all systems that can run the normal chmod command.
11
- #First install the interpreter of the Ruby programming language. On most system it is installed by default.
12
- #Then install the Rubygems package, this package downloads and installs Ruby packages very fast and simple. On most systems the package can be found in the package manager.
13
- #Install the latest release of simple-chmod by typing following command in your terminal: # gem install simple-chmod
14
- #We recommend install trough rubygems. When rubygems is finished installing type the following command: # gem contents simple-chmod
15
- #This command echos all the files of the simple-chmod package. Next, open your favorite text-editor and open your .bashrc file. At the end of this file you should add the next line: 'alias simple-chmod="ruby PATH_TO_SIMPLE-CHMOD.RB_FILE"'
16
- #Next you reload your .bashrc file (source ~/.bashrc).
17
- #After this you should be able to run the simple-chmod command in you terminal and run the program. You may be obliged to grant the script the permission to be run as a program (executable).
18
-
19
- print "\n***** Simple-Chmod-v0.3 *****\n\nWith this program you can change permissions very simple. The syntax for changing permissions is easier then the chmod command in your terminal, permission options are 'none' or 'read write xcute' and leave out by your choice.\n\nOnly run this program as root.\n\nEnter filename or directory: "
20
-
21
- STDOUT.flush
22
- file = gets.chomp
23
-
24
- checker = File.exist?(file)
25
-
26
- if checker == true
27
- print "Filecheck OK.\nWhat permissions do you want to grant to the OWNER of this file?\n"
28
- STDOUT.flush
29
- ownerperms = gets.chomp
30
- if ownerperms == 'none'
31
- shell_script_output = `chmod u-rwx #{file}`
32
- print "Changed owner perms.\n"
33
- print "What permissions do you want to grant to the GROUP of this file?\n"
34
- STDOUT.flush
35
- groupperms = gets.chomp
36
- if groupperms == 'none'
37
- shell_script_output = `chmod g-rwx #{file}`
38
- print "Changed group perms.\n"
39
-
40
- print "What permissions do you want to grant to the OTHERS?\n"
41
- STDOUT.flush
42
- otherperms = gets.chomp
43
- if otherperms == 'none'
44
- shell_script_output = `chmod o-rwx #{file}`
45
- print "Changed other perms.\n"
46
-
47
- elsif otherperms == 'read write' || otherperms == 'read xcute' || otherperms == 'write read' || otherperms == 'write xcute' || otherperms == 'xcute read' || otherperms == 'xcute write' || otherperms == 'read' || otherperms == 'write' || otherperms == 'xcute' || otherperms == 'read write xcute'
48
- replaceotherperms = otherperms.gsub("read", "r").gsub("write", "w").gsub("xcute", "x")
49
- finalotherperms = replaceotherperms.delete("\s")
50
- shell_script_output = `chmod o-rwx #{file}`
51
- shell_script_output = `chmod o+#{finalotherperms} #{file}`
52
- print "Changed other perms.\n"
53
-
54
- else
55
- print "No valid file permissions.\n"
56
- end
57
-
58
-
59
- elsif groupperms == 'read write' || groupperms == 'read xcute' || groupperms == 'write read' || groupperms == 'write xcute' || groupperms == 'xcute read' || groupperms == 'xcute write' || groupperms == 'read' || groupperms == 'write' || groupperms == 'xcute' || groupperms == 'read write xcute'
60
- replacegroupperms = groupperms.gsub("read", "r").gsub("write", "w").gsub("xcute", "x")
61
- finalgroupperms = replacegroupperms.delete("\s")
62
- shell_script_output = `chmod g-rwx #{file}`
63
- shell_script_output = `chmod g+#{finalgroupperms} #{file}`
64
- print "Changed group perms.\n"
65
-
66
- print "What permissions do you want to grant to the OTHERS?\n"
67
- STDOUT.flush
68
- otherperms = gets.chomp
69
- if otherperms == 'none'
70
- shell_script_output = `chmod o-rwx #{file}`
71
- print "Changed other perms.\n"
72
-
73
- elsif otherperms == 'read write' || otherperms == 'read xcute' || otherperms == 'write read' || otherperms == 'write xcute' || otherperms == 'xcute read' || otherperms == 'xcute write' || otherperms == 'read' || otherperms == 'write' || otherperms == 'xcute' || otherperms == 'read write xcute'
74
- replaceotherperms = otherperms.gsub("read", "r").gsub("write", "w").gsub("xcute", "x")
75
- finalotherperms = replaceotherperms.delete("\s")
76
- shell_script_output = `chmod o-rwx #{file}`
77
- shell_script_output = `chmod o+#{finalotherperms} #{file}`
78
- print "Changed other perms.\n"
79
-
80
- else
81
- print "No valid file permissions.\n"
82
- end
83
-
84
- else
85
- print "No valid file permissions.\n"
86
- end
87
-
88
- elsif ownerperms == 'read write' || ownerperms == 'read xcute' || ownerperms == 'write read' || ownerperms == 'write xcute' || ownerperms == 'xcute read' || ownerperms == 'xcute write' || ownerperms == 'read' || ownerperms == 'write' || ownerperms == 'xcute' || ownerperms == 'read write xcute'
89
- replaceownerperms = ownerperms.gsub("read", "r").gsub("write", "w").gsub("xcute", "x")
90
- finalownerperms = replaceownerperms.delete("\s")
91
- shell_script_output = `chmod u-rwx #{file}`
92
- shell_script_output = `chmod u+#{finalownerperms} #{file}`
93
- print "Changed owner perms.\n"
94
- print "What permissions do you want to grant to the GROUP of this file?\n"
95
- STDOUT.flush
96
- groupperms = gets.chomp
97
- if groupperms == 'none'
98
- shell_script_output = `chmod g-rwx #{file}`
99
- print "Changed group perms.\n"
100
- print "What permissions do you want to grant to the OTHERS?\n"
101
- STDOUT.flush
102
- otherperms = gets.chomp
103
- if otherperms == 'none'
104
- shell_script_output = `chmod o-rwx #{file}`
105
- print "Changed other perms.\n"
106
-
107
- elsif otherperms == 'read write' || otherperms == 'read xcute' || otherperms == 'write read' || otherperms == 'write xcute' || otherperms == 'xcute read' || otherperms == 'xcute write' || otherperms == 'read' || otherperms == 'write' || otherperms == 'xcute' || otherperms == 'read write xcute'
108
- replaceotherperms = otherperms.gsub("read", "r").gsub("write", "w").gsub("xcute", "x")
109
- finalotherperms = replaceotherperms.delete("\s")
110
- shell_script_output = `chmod o-rwx #{file}`
111
- shell_script_output = `chmod o+#{finalotherperms} #{file}`
112
- print "Changed other perms.\n"
113
-
114
- else
115
- print "No valid file permissions.\n"
116
- end
117
-
118
-
119
- elsif groupperms == 'read write' || groupperms == 'read xcute' || groupperms == 'write read' || groupperms == 'write xcute' || groupperms == 'xcute read' || groupperms == 'xcute write' || groupperms == 'read' || groupperms == 'write' || groupperms == 'xcute' || groupperms == 'read write xcute'
120
- replacegroupperms = groupperms.gsub("read", "r").gsub("write", "w").gsub("xcute", "x")
121
- finalgroupperms = replacegroupperms.delete("\s")
122
- shell_script_output = `chmod g-rwx #{file}`
123
- shell_script_output = `chmod g+#{finalgroupperms} #{file}`
124
- print "Changed group perms.\n"
125
-
126
- print "What permissions do you want to grant to the OTHERS?\n"
127
- STDOUT.flush
128
- otherperms = gets.chomp
129
- if otherperms == 'none'
130
- shell_script_output = `chmod o-rwx #{file}`
131
- print "Changed other perms.\n"
132
-
133
- elsif otherperms == 'read write' || otherperms == 'read xcute' || otherperms == 'write read' || otherperms == 'write xcute' || otherperms == 'xcute read' || otherperms == 'xcute write' || otherperms == 'read' || otherperms == 'write' || otherperms == 'xcute' || otherperms == 'read write xcute'
134
- replaceotherperms = otherperms.gsub("read", "r").gsub("write", "w").gsub("xcute", "x")
135
- finalotherperms = replaceotherperms.delete("\s")
136
- shell_script_output = `chmod o-rwx #{file}`
137
- shell_script_output = `chmod o+#{finalotherperms} #{file}`
138
- print "Changed other perms.\n"
139
-
140
- else
141
- print "No valid file permissions.\n"
142
- end
143
-
144
- else
145
- print "No valid file permissions.\n"
146
- end
147
-
148
- else
149
- print "No valid file permissions.\n"
150
- end
151
-
152
- else checker == false
153
- print "The file doesn't exist.\n"
154
- end
155
-