How to reload .com.apple.iokit.graphics underscan without restarting? - macos

I'm looking into making a script that automatically turns off underscan when my Plex Home Theater.app is running.
So far I have found the file containing the setting at /var/db/.com.apple.iokit.graphics.
Then I tried changing the underscan value in the settings file with PlistBuddy:
# underscan 100%
sudo /usr/libexec/PlistBuddy /private/var/db/.com.apple.iokit.graphics -c 'Set "IOService\:/AppleACPIPlatformExpert/PCI0#0/AppleACPIPCI/IGPU#2/AppleIntelFramebuffer#2/display0/AppleDisplay-3dcb-e51:pscn" 8800'
# underscan off
sudo /usr/libexec/PlistBuddy /private/var/db/.com.apple.iokit.graphics -c 'Set "IOService\:/AppleACPIPlatformExpert/PCI0#0/AppleACPIPCI/IGPU#2/AppleIntelFramebuffer#2/display0/AppleDisplay-3dcb-e51:pscn" 10000'
But changing the file alone didn't apply the new underscan setting, so I tried restarting to see if the setting would take effect – it did.
So does anyone know how to change the underscan setting without restarting?
Thanks.

Related

timeout error message when running sudo visudo

I was trying to install yabai on my Big Sur mac, and ran into an issue when trying to do visudo. After some playing around, I found that I was running into issues even with just sudo visudo (i.e., the problem isn't with yabai):
❯ sudo visudo
Timeout waiting for detached instance to start: No such file or directory
visudo: /etc/sudoers.tmp unchanged
Nor does adding an editor flag work:
❯ sudo EDITOR="vim" visudo
Timeout waiting for detached instance to start: No such file or directory
visudo: /etc/sudoers.tmp unchanged
❯ sudo EDITOR="nano" visudo
Timeout waiting for detached instance to start: No such file or directory
visudo: /etc/sudoers.tmp unchanged
I'm using zsh.
Would any of you happen to know how to get around this?
Thanks very much in advance!
It looks like visudo is trying to run Sublime Text despite your use of an EDITOR environment variable. I suspect that this is because you have it set in the SUDO_EDITOR or VISUAL environment variables, both of which take precedence over EDITOR if they're set. Try sudo SUDO_EDITOR="vim" visudo or sudo SUDO_EDITOR="nano" visudo instead.
If that isn't it, the other possibility is that in your sudoers file, env_editor is disabled and so editor is forcing the use of Sublime Text.

LD_PRELOAD not working on Heroku + jemalloc + quotaguard

TL;DR: update your bin/qgtunnel.
I've recently noticed an increase in my web dyno's memory usage. After digging a bit, I could see that the LD_PRELOAD variable that should be set with heroku-buildpack-jemalloc was not set correctly. I used a tiny script (bin/show_preload) that helped me debug that and trace which program was overriding LD_PRELOAD.
#!/usr/bin/env bash
echo "buildpack=foo preload='$LD_PRELOAD' at=start-app cmd='$#'"
$#
I introduced that in our Procfile:
web: bin/show_preload bin/qgtunnel bin/show_preload bin/start-nginx bin/show_preload bin/start-pgbouncer bin/show_preload bundle exec puma -C config/puma.rb
And when lauching on heroku I can see that bin/qgtunnel overrides our LD_PRELOAD configuration.
I created a tiny helper for the time being which makes sure I keep original value as well as what is added by bin/qgtunnel:
#!/usr/bin/env bash
after_qgtunnel_script=$(mktemp)
echo <<-BASH > $after_qgtunnel_script
# Retrieve previous LD_PRELOAD value
export LD_PRELOAD="\$LD_PRELOAD $LD_PRELOAD"
# Clean after usage
rm $after_qgtunnel_script
# Start following commands
$#
BASH
chmod +x $after_qgtunnel_script
bin/qgtunnel $after_qgtunnel_script $#
If you ever need this script use it in place of bin/qgtunnel
After reaching out to Quotaguard, they patched the qgtunnel binary and there is no error anymore:
curl https://quotaguard.s3.amazonaws.com/qgtunnel-2.4.1.tar.gz | tar xz
git add bin/qgtunnel vendor/nss_wrapper/libnss_wrapper.so
git commit -m "Update qgtunnel to fix LD_PRELOAD"
NOTE: new versions may occur since that one, see the related documentation

Transmission on FreeNAS does not call script on completion

I have been trying to get this running for over a week and am at a loss. I am trying to call a script on completion by using the settings.json config like so:
"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/posttorrent.sh",
My script is in the root of the jail and is owned by transmission. I have also checked permissions on the file (which are 755) and have run chmod +x /posttorrent.sh.
I have even simplified the file to just output to a log file like so:
#!/bin/bash
echo "$TR_TORRENT_NAME is completed" >> /posttorrent.log
However, thus far, I still do not have a posttorrent.log file anywhere, no matter what file I download. I am not totally sure if I am on the right track as Transmission is set to log level 3 and yet I do not even see the calls to the script in /var/log/debug.log. I am sure I am missing something easy as others have been able to get this working, I am just out of options now as I think I have read and/or tried everything I could find in relation to this issue. Thanks!
The script is relying on /bin/bash being present inside of the jail.
You can either change the script to use /bin/sh, change /bin/bash
to /usr/bin/env bash, or link /path/to/port/bin/bash to
/usr/local/bin/bash (or wherever bash is located relative to the
jail directory, but if it exists it should be in /usr/local/bin).
ln -s /usr/local/bin/bash /path/to/jail/bin/bash
Also, the root directory (by default) is only writable by root, so
the transmission user would not have permission to create
the log file in the root directory. To properly allow creation of
the log file change the destination directory to one that the
transmission user has permission to write to. For example
/var/db/transmission/posttorrent.log, if using the FreeNAS plugin.
A directory can be created for the transmission user using the
install utility:
install -d -o transmission -g transmission /home/transmission
Alternatively the log file can be created manually using the
install utility, or the owner can be set with chown:
install -o transmission -g transmission -m 644 /dev/null /posttorrent.log
# or on an existing log file
chown transmission /posttorrent.log
chgrp transmission /posttorrent.log
# normally the mode bits will already be 644
chmod 644 /posttorrent.log
Transmission will also rewrite the configuration file when it
exits. So transmission-daemon has to be stopped before
editing the settings file. However, if using the Transmission plugin,
the settings are stored in a SQLite database
(/usr/pbi/transmission-amd64/transmissionUI/transmission.db)
and the settings file will be recreated from the database on
startup. sqlite3 can be used to manually edit the database, or the plugin's settings can be edited on the FreeNAS web UI.
sqlite3 /usr/pbi/transmission-amd64/transmissionUI/transmission.db <<EOF
UPDATE freenas_transmission SET enable=1;
UPDATE freenas_transmission SET script_post_torrent="/posttorrent.sh";

bash-completion (from Homebrew) not completing variables on OSX

I use bash completion all the time to save typing. However there is an oddity I am unable to figure out how to fix on OSX.
If I install bash-completion using Homebrew (brew install bash-completion) and set it up in .bashrc, the tab key will no longer complete environment variables. Without this installed, environment variable completion works as expected.
For example, I have shortcuts for all my SSH accounts for clients... instead of typing ssh myuser#somecrazydomain.com I can just type ssh $SSHCRAZY which is much easier to remember.
Expected behavior: In the built-in bash in OSX I can type ssh $SSHC and hit tab and it completes to the full command as expected. This is what I want.
Observed behavior: In bash using the homebrew bash-completion additions, hitting tab has no effect for environment variables.
Note: All other extensions added by the bash-completion project are desired (git command completion, etc). I don't want to uninstall it, I just want it to also work with environment variables.
Thanks in advance for any help!
You might consider using an SSH config file (~/.ssh/config) to set up your SSH shortcuts instead of using environment variables. You could put into that file:
Host crazy
HostName somecrazydomain.com
User myuser
Then you can just type ssh crazy.
I guess bash-completion must have defined completion rule for ssh. So try add the -o bashdefault option in your .bashrc. For example, if complete -p ssh output like this:
# complete -p ssh
complete -F _func ssh
#
then you can add this to your .bashrc (or .bash_profile):
complete -F _func -o bashdefault ssh
or
eval "$(complete -p ssh | sed 's/ssh$/-o bashdefault ssh/')"

modify file content

I'm installing a lighttpd server on a remote machine using a bash script. After installation, I need to configure the port for the server. The system says I don't have permission to modify the file /etc/lighttpd/lighttpd.conf even though I do
sudo echo "server.bind=2000" >> /etc/lighttpd/lighttpd.conf
How shall I modify this?
What you're doing is running echo as root, then trying to append its output to the config file as the normal user.
What you want is sudo sh -c 'echo "server.bind=2000" >> /etc/lighttpd/lighttpd.conf'
Try to change the file permission using chmod
$ sudo chmod a+x /etc/lighttpd/lighttpd.conf
If you don't have the right to change the file /etc/lighttpd/lighttpd.conf check the man page of lighthttpd. If you can start it with a different config file, then create a config file somewhere and start lighthttpd with it.
The problem is that the bit on the right of >> is not run under sudo. Either use sudo -i to bring up a root shell a superuser and run the command, or just use an editor as mentioned before.

Resources