loginwindow アプリの LoginHook を利用し, ログイン時に環境を初期化するようにする.
設定は defaults コマンド(後述)で行う.
% sudo defaults write com.apple.loginwindow LoginHook /etc/login.sh % vi /etc/login.sh
この login.sh にいろいろな処理を書いていく.
/Library/.initialized が無ければ,
$1 にユーザ名が入るのでこんな感じ? login.sh
#!/bin/sh #TEMPDIR='/System/Library/User Template/Japanese.lproj/Library' TEMPDIR='/Users/skel' LIBDIR=${TEMPDIR}/Library ADMIN_USER=admin ID_LINE=`/usr/bin/id -P $1` GROUP=`echo "${ID_LINE}"| /usr/bin/cut -f 4 -d":"` #GROUP=`id -g -nr` HOME=`echo "${ID_LINE}"| /usr/bin/cut -f 9 -d":"` if [ "$1" = "root" -o "$1" = "${ADMIN_USER}" ] then exit 0 fi su $1 -c "test -d ${HOME}" if [ $? -ne 0 ] then echo "${HOME} is not found." exit 0 fi # Global Setting Section PRINTER=`/etc/selpr.pl` if [ -f ${TEMPDIR}/.lpoptions.${PRINTER} ] then su $1 -c "cp ${TEMPDIR}/.lpoptions.${PRINTER} ${HOME}/.lpoptions" fi su $1 -c "test -f ${HOME}/.CFUserTextEncoding" if [ $? -ne 0 ] then su $1 -c "cp ${TEMPDIR}/.CFUserTextEncoding ${HOME}/.CFUserTextEncoding" fi su $1 -c /usr/local/bin/RemoveOfficeCache.sh # # Make Directry Section # for DIR in Library Documents Movies Pictures do su $1 -c "test -d ${HOME}/${DIR}" if [ $? -ne 0 ] then su $1 -c "/bin/mkdir ${HOME}/${DIR}" su $1 -c "/usr/bin/touch ${HOME}/${DIR}/.localized" fi done # Preference Initialize Section su $1 -c "test -f ${HOME}/Library/.initialized" if [ $? -eq 0 ] then exit 0 fi su $1 -c "touch ${HOME}/Library/.initialized" su $1 -c "/usr/bin/ditto -rsrcFork "${LIBDIR}" ${HOME}/Library" /usr/sbin/chown -R $1:${GROUP} ${HOME}/Library exit 0
また,$HOME を自動作成する場合は, 以下のようなスクリプトを用いる.login2.sh
#!/bin/sh ADMIN_USER=admin ID_LINE=`/usr/bin/id -P $1` #GROUP=`echo "${ID_LINE}"| /usr/bin/cut -f 4 -d":"` HOME=`echo "${ID_LINE}"| /usr/bin/cut -f 9 -d":"` if [ "$1" = "root" -o "$1" = "${ADMIN_USER}" ] then exit 0 fi if [ ! -d "${HOME}" ] then # echo "${HOME} is not found." /usr/sbin/createhomedir -c -u $1 exit 0 fi
例)
sudo defaults write com.apple.loginwindow LogoutHook /Library/Management/crtrsrc.sh sudo defaults write com.apple.dock orientation left
よくわからないが,sudo で root としての設定を行うと システムデフォルトになるのか?
Syntax)
defaults [currentHost | -host hostname] read [domain [key]] defaults [currentHost | -host hostname] read-type domain key defaults [currentHost | -host hostname] write domain { 'plist' | domain key 'value' } defaults [currentHost | -host hostname] rename domain old_key new_key defaults [currentHost | -host hostname] delete [domain [key]] defaults [currentHost | -host hostname] { domains | find word | help }