You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by ru...@apache.org on 2019/12/02 00:46:22 UTC
[whimsy] branch master updated: emulate sudo;
don't pretend to start apache twice
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
The following commit(s) were added to refs/heads/master by this push:
new 870ecc3 emulate sudo; don't pretend to start apache twice
870ecc3 is described below
commit 870ecc379c4a6ed0c3e47eb76343128fe24a6962
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Sun Dec 1 19:46:02 2019 -0500
emulate sudo; don't pretend to start apache twice
---
config/setupmymac | 39 ++++++++++++++++++++++-----------------
1 file changed, 22 insertions(+), 17 deletions(-)
diff --git a/config/setupmymac b/config/setupmymac
index 0961bf9..adfe6b1 100755
--- a/config/setupmymac
+++ b/config/setupmymac
@@ -3,6 +3,9 @@ require 'tmpdir'
require 'optparse'
require 'etc'
+$root = (ARGV.delete '--sudo') || (Process.uid == 0)
+$apache_would_have_been_restarted = (ARGV.delete '--apache-restarted')
+
#########################################################################
#
# Sets up a macOS machine for whimsy development. Pass --help as an
@@ -48,7 +51,7 @@ end
# echo a command and run it
def run *args
- color "$ " + "#{'sudo ' if Process.uid == 0}" + Array(args).join(' ')
+ color "$ " + "#{'sudo ' if $root}" + Array(args).join(' ')
return if $dry_run
Kernel.system *args
end
@@ -65,11 +68,15 @@ end
# Switch to root
def sudo
- if Process.uid != 0
+ if $root
+ yield
+ elsif $dry_run
+ ARGS.push '--apache-restarted' if $apache_would_have_been_restarted
+ system RbConfig.ruby, COMMAND, *ARGS, '--sudo'
+ $apache_would_have_been_restarted = true
+ else
system "sudo", RbConfig.ruby, COMMAND, *ARGS
exit $?.exitstatus unless $?.success?
- else
- yield
end
end
@@ -144,9 +151,7 @@ group = Etc.getgrgid(gid).name
### Install Homebrew
-if Process.uid != 0 and
- (option != :docker or not Dir.exist? '/Applications/Docker.app')
-then
+if not $root and (option!=:docker or not Dir.exist? '/Applications/Docker.app')
if `which brew`.empty?
script = 'https://raw.githubusercontent.com/Homebrew/install/master/install'
color %($ ruby -e "$(curl -fsSL #{script})")
@@ -156,7 +161,7 @@ end
## Install Node.js
-if Process.uid != 0 and option != :docker
+if not $root and option != :docker
if `which node`.empty?
brew 'install', 'node'
elsif force[:node]
@@ -220,7 +225,7 @@ if not Dir.exist? '/srv/whimsy'
end
# update source
-if force[:source] and Process.uid != 0
+if force[:source] and not $root
Dir.chdir '/srv/whimsy' do
run 'git', 'pull'
end
@@ -276,7 +281,7 @@ if option == :docker
run 'open /Applications/Docker.app'
end
- if Process.uid != 0
+ if not $root
Dir.chdir '/srv/whimsy' do
run 'rake docker:update'
end
@@ -323,7 +328,7 @@ end
### Installl gems
-if Process.uid != 0
+if not $root
if force[:gems] or not File.exist?("#{WHIMSY}/Gemfile.lock")
# collect up all gems and install them so the sudo password is only
# asked for once
@@ -356,17 +361,17 @@ end
### Checkout/clone repositories
-if force[:svn] and Process.uid != 0
+if force[:svn] and not $root
run 'rake', 'svn:update'
end
-if force[:git] and Process.uid != 0
+if force[:git] and not $root
run 'rake', 'git:pull'
end
### Collate minutes
-if Process.uid != 0
+if not $root
if force[:minutes] or not Dir.exist? '/srv/whimsy/www/board/minutes'
run 'tools/collate_minutes.rb'
end
@@ -380,7 +385,7 @@ if File.exist? "#{WHIMSY}/Gemfile.lock"
if force[:ldap] or not ASF::LDAP.configured?
sudo do
color '$ ruby -I lib -r whimsy/asf -e "ASF::LDAP.configure"'
- ASF::LDAP.configure
+ ASF::LDAP.configure unless $dry_run
end
ARGS.push '--no-ldap'
end
@@ -469,7 +474,7 @@ end
### Make applications restart on change
-if Process.uid != 0 and option != :docker
+if not $root and option != :docker
plist = "#{Dir.home}/Library/LaunchAgents/toucher.plist"
contents = File.read("#{__dir__}/toucher.plist")
contents[/>(.*ruby.*)</, 1] = RbConfig.ruby
@@ -494,7 +499,7 @@ end
### Start Apache httpd
-if Process.uid == 0
+if $root and not $apache_would_have_been_restarted
if not `launchctl list`.include? 'org.apache.httpd'
run "launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist"
elsif restart_apache