whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject [whimsy] 01/02: Take ownership of the n directory.
Date Sun, 08 Dec 2019 13:16:20 GMT
This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git

commit 63193a4dae6396a9614782129b7f6fecd06590c6
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Sun Dec 8 08:13:16 2019 -0500

    Take ownership of the n directory.
    
    See: https://github.com/tj/n/blob/master/README.md#installation
---
 config/setupmymac | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/config/setupmymac b/config/setupmymac
index b1626bc..8c82e46 100755
--- a/config/setupmymac
+++ b/config/setupmymac
@@ -171,6 +171,9 @@ uid = Etc.getpwnam(user).uid
 gid = Etc.getpwnam(user).gid
 group = Etc.getgrgid(gid).name
 
+sudo_user = ENV['SUDO_USER'] ?
+  Etc.getpwnam(ENV['SUDO_USER']) : Etc.getpwuid(Process.uid)
+
 ### Install Homebrew
 
 if not $root and (option!=:docker or not Dir.exist? '/Applications/Docker.app')
@@ -189,11 +192,21 @@ if not $root and option != :docker
   elsif force[:node]
     brew 'upgrade', 'n' 
   end
+end
+
+unless Dir.exist? '/usr/local/n'
+  sudo { run 'mkdir', '/usr/local/n' }
+end
 
+unless File.stat('/usr/local/n').uid == uid
+  sudo {run 'chown', '-R', "#{sudo_user.uid}:#{sudo_user.gid}", '/usr/local/n'}
+end
+
+if not $root and option != :docker
   if `which node`.empty?
-    sudo { run 'n lts' }
+    run 'n lts'
   elsif force[:node] and "v#{`n ls-remote stable`}" != `node --version`
-    sudo { run 'n lts' }
+    run 'n lts'
   end
 
   # Prompt for xcode installation
@@ -215,12 +228,10 @@ end
 mac_version = `sw_vers`[/ProductVersion:\s+(.*)/, 1]
 unless Dir.exist? '/srv'
   sudo do
-    sudo_user = ENV['SUDO_USER']
-    sudo_group = Etc.getpwnam(sudo_user).gid
     if (mac_version.split('.').map(&:to_i) <=> [10, 15, 0]) >= 0
       # Catalina or later
       run 'mkdir', '/var/whimsy' unless Dir.exist? '/var/whimsy'
-      run 'chown', "#{sudo_user}:#{sudo_group}", '/var/whimsy'
+      run 'chown', "#{sudo_useruid}:#{sudo_user.gid}", '/var/whimsy'
       run 'touch', '/etc/synthetic.conf'
       SYNTHETIC = '/etc/synthetic.conf'
       unless File.read(SYNTHETIC).include? "/var/whimsy"


Mime
View raw message