Set configuration file ownership
authorEliseo Ocampos <roskoff@gmail.com>
Thu, 10 Mar 2016 16:24:31 +0000 (13:24 -0300)
committerEliseo Ocampos <roskoff@gmail.com>
Thu, 10 Mar 2016 16:24:31 +0000 (13:24 -0300)
Set the proper file ownership if installed with sudo. This avoids
constants error messages when trying to change/delete configuration
values (chmod: changing permissions of ...: Operation not permitted)

Signed-off-by: Eliseo Ocampos <roskoff@gmail.com>
setup.py

index 10f509425497b7aafdb1c549a2dad9e2a3b64178..fe065349969f009c0a73000846f4cf713e473718 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,12 @@
 from setuptools import setup, find_packages
 import os
 import os.path
 from setuptools import setup, find_packages
 import os
 import os.path
+import sys
+
+if sys.version[0] == "2":
+    from pipes import quote
+else:
+    from shlex import quote
 
 # Bumped version
 version = '1.3.3'
 
 # Bumped version
 version = '1.3.3'
@@ -16,11 +22,16 @@ install_requires = [
     "PySocks"
 ]
 
     "PySocks"
 ]
 
+# Default user (considers non virtualenv method)
+user = os.environ.get('SUDO_USER', os.environ['USER'])
+
 # Copy default config if not exists
 default = os.path.expanduser("~") + os.sep + '.rainbow_config.json'
 if not os.path.isfile(default):
     cmd = 'cp rainbowstream/colorset/config ' + default
     os.system(cmd)
 # Copy default config if not exists
 default = os.path.expanduser("~") + os.sep + '.rainbow_config.json'
 if not os.path.isfile(default):
     cmd = 'cp rainbowstream/colorset/config ' + default
     os.system(cmd)
+    cmd = 'chown ' + quote(user) + ' ' + default
+    os.system(cmd)
     cmd = 'chmod 777 ' + default
     os.system(cmd)
 
     cmd = 'chmod 777 ' + default
     os.system(cmd)