Tengo un error asociado con este agente launchd. Hay un agente listado en la lista launchctl, y llama a mi script bash, llamado rc.wakeup, cada vez que el mac se despierta del modo de espera. Sólo hay una copia de este script bash. El código en el script de bash no se repite. A pesar de esto, el script bash se está ejecutando dos veces en su totalidad. ¿Por qué?
He creado un script bash de instalación y un script bash de desinstalación. Los he estado ejecutando en serie para intentar que ambos scripts funcionen, por lo que cualquiera puede usar este programa. Creo que la instalación / desinstalación incorrecta de estos archivos ha causado el problema, aunque no tengo idea de por qué lo haría.
Aquí está el plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>de.bernhard-baehr.sleepwatcher</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/sbin/sleepwatcher</string>
<string>-V</string>
<string>-s /etc/rc.sleep</string>
<string>-w /etc/rc.wakeup</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
Aquí está el script de instalación que utilizo para instalar el programa:
#!/bin/bash
sudo mkdir -p /usr/local/sbin /usr/local/share/man/man8
sudo cp ~/Desktop/mysecureview/sleepwatcher_2.2/sleepwatcher /usr/local/sbin
sudo cp ~/Desktop/mysecureview/sleepwatcher_2.2/sleepwatcher.8 /usr/local/share/man/man8
mkdir ~/mysecureview
mkdir ~/mysecureview/log
mkdir ~/mysecureview/pics
cp ~/Desktop/mysecureview/imagesnap-master/imagesnap ~/mysecureview/imagesnap
mkdir ~/Library/LaunchAgents
cp ~/Desktop/mysecureview/sleepwatcher_2.2/config/de.bernhard-baehr.sleepwatcher-20compatibility.plist ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility.plist
launchctl load ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility.plist
sudo cp ~/Desktop/mysecureview/sleepwatcher_2.2/config/rc.wakeup /etc/rc.wakeup
sudo cp ~/Desktop/mysecureview/sleepwatcher_2.2/config/rc.wakeup /etc/rc.sleep
cp ~/Desktop/mysecureview/num.txt ~/mysecureview/num.txt
cp ~/Desktop/mysecureview/logs.txt ~/mysecureview/logs.txt
cp ~/Desktop/mysecureview/compile.bash ~/mysecureview/compile.bash
cp ~/Desktop/mysecureview/uninstall ~/mysecureview/uninstall
mkdir ~/mysecureview/logs.txt
echo "========================"
echo "~Installation Succesful~"
echo "========================"
Aquí está el script de desinstalación:
#!/bin/bash
launchctl unload ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility.plist;
rm ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility.plist
sudo rm /etc/rc.wakeup
sudo rm /etc/rc.sleep
sudo killall sleepwatcher
sudo rm -rf /Library/StartupItems/SleepWatcher
launchctl unload de.bernhard-baehr.sleepwatcher
launchctl remove de.bernhard-baehr.sleepwatcher
rm ~/mysecureview/num.txt
rm ~/mysecureview/compile.bash
rm ~/mysecureview/imagesnap
rm ~/mysecureview/logs.txt
for i in {1..100}
do
p=".txt"
x="$i$p"
rm ~/mysecureview/log/$x
done
rmdir ~/mysecureview/log
echo "====================="
echo "~Uninstall Successful"
echo "====================="
Aquí está el script real que se está ejecutando cuando se apaga la computadora:
for user in 'echo 'show State:/Users/ConsoleUser' | scutil | awk '/kCGSSessionUserNameKey/ { print $3 }''; do
home='eval echo ~$user'
if [ -x "$home/.wakeup" ]; then
logger -t $0 "executing .wakeup of user $user"
su - $user -c "$home/.wakeup"
fi
done
#The following is the MySecureView script used to capture the picture and its information.
cd ~/mysecureview
# take a picture.
./imagesnap
#get the log index. Create a variable for and iterate the index.
numPics=$(cat ~/mysecureview/num.txt)
numPics=$[numPics+1]
jpg=".jpg"
index="$numPics$jpg"
#We only allow 100 log entries to exist at a time.
if [ $numPics == 100 ]; then
numPics=1
fi
#temp storage for the newest picture.
cp ~/mysecureview/snapshot.jpg ~/mysecureview/pics/$index
rm ~/mysecureview/snapshot.jpg
rm ~/mysecureview/date.txt
# temporary storage for the most recent log entry.
date=$(date)
entry="$numPics $date"
logNum="$numPics.txt"
echo "$entry" > ~/mysecureview/log/$logNum
#store the index for next use.
echo "$numPics" > ~/mysecureview/num.txt
#compile each and every log entry .txt file into the logs.txt file.
bash compile.bash