- The added line is THIS COLOR.
- The deleted line is THIS COLOR.
jukeboxのメインスクリプト
#!/bin/sh
Note 12/272(OLD2 2) Junk Box
[ RESPONSE 176/191 ]
Title : UNIXって、なぁーに?
SIN4103 [kaw] 93/03/03 02:19:53 サイズ: 2313 バイト
Subtitle: installing 386BSD
#######################
#
# Simple MP3 Jukebox
# KAWAMATA, Yoshihiro
# kaw@on.rim.or.jp
#
#######################
月の末にAT互換機を購入しまして、386BSD をインストールしましたので、
そのことについて書きたいと思います。
#=====
# utility functions / routines
#=====
注文したハードが到着した日には、最初に員数・構成のチェックを行いました。
これはOK。で、AT互換機は、輸送途中に部のコネクタがはずれたりのトラ
ブルが多いとの話を見聞きしてましたので、電源をれるまえに内部を覗いてみ
ました。すると案の定5インチのドライブのコネクタがはずれていて、フラット・
ケーブルが中でブラブラしていました。
# terminate process
#
terminate () {
[ $# -ne 0 ] && echo "$@"
rm -rf ctrl/playing
[ -r ctrl/finish ] && . ctrl/finish
}
他にはハードはOKのようでしたので、電源をれて3時間程ヒートランさせ
ました。次に BIOS 関係をセットアップするのですが、すでに販売店でセットア
ップされているので、設定値をメモした上で部時計の設定とディスクの表面検
査のみを行いました。
# trap for ^C
#
trap 'terminate "Aborted by user" ; exit' 2
386BSD のインストールは週の日曜 (2/28) に LED 氏の指導の元行いました。
氏から頂いたのは、386BSD のシステム1式と Patch Kit 2.0, XFree86 および
Linux のシステム1式です。結局バックアップから起動まで、丸一日かかりまし
た。
# check flags,
# fetch a file,
# play it
#
# Usage: play_one_action { local_file | URL }
#
play_one_action () {
[ $# -eq 0 ] && return
最初パッチをあてないで使用していたのですが、やはり色と不都合があった
のでパッチをあてたところ、ほとんど問題なく運用できるようになりました(ま
だそれほど使っていませんが‥)。パッチで解決できない固有の不都合としては、
# halt, reboot or exit
#
if [ -f ctrl/halt ]; then
terminate "Halting..."
rm -f ctrl/halt
/sbin/shutdown -hp now
sleep 86400
・TURBO スイッチをオンにしてブートすると、ハードディスクを認識せず、
ブートできない。
elif [ -f ctrl/reboot ]; then
terminate "Rebooting..."
rm -f ctrl/reboot
/sbin/shutdown -r now
sleep 86400
・キーボードが106タイプなので、386BSD が想定している101タイ
プのものとキー列が異なり、キーの刻印と実際に入力される文字が違
っている(() {} [] " ' ` + | \ * @ ... 等の特殊文字)。
elif [ -f ctrl/restart ]; then
terminate "Restarting script..."
rm -f ctrl/restart
exec $progfile
最初のものは、ディスクのドライバのソース中、タイムアウトの設定値を変更
してカーネルを再生成することで、解決しました。2番目のものも、やはりドラ
イバのソースでキーのコードを設定している部分を発見したので、ここを変更す
ることにより、解決できると思います(違っている部のキーを修正するのは結
構面倒ですが‥)。
elif [ -f ctrl/exit ]; then
terminate "Exiting..."
rm -f ctrl/exit
exit
fi
現在はこんなところです。いずれディスクのパーティションを切り直してちゃ
んと運用できるようにするつもりですので、それまでの間はシステムダウンを気
にせずリハーサルのつもりで色いじってみようと思います。そういうことがで
きるのは、最初のうちですので。
# clean non-MP3 file and empty directories under spool
#
if [ -f ctrl/clean ]; then
echo "Clearning dirs..."
rm -f ctrl/clean
find $src $dest oneshot oneshot_finished -type f \! \( -iname '*.mp3' -o -iname
'*.url' \) -print0 | xargs -0 rm -f
for d in $src $dest oneshot oneshot_finished; do
(cd $d && find . -type d -print | sort -r | xargs rmdir >/dev/null 2>&1)
done
fi
ディストリビューションを提供して下さった LED さん、また当日インストー
ル作業に立ち会って下さった Timer Troubler さん、どうもありがとうございま
した。これからもよろしくお願いします。
# pause playing
#
if [ -f ctrl/pause ]; then
echo "Pausing..."
while [ -f ctrl/pause ]; do
sleep 15
done
fi
[SIN4103 / kaw]
#comment
Note 12/272(OLD2 2) Junk Box
[ RESPONSE 177/191 ]
Title : UNIXって、なぁーに?
SIN4103 [kaw] 93/03/13 14:33:08 サイズ: 1292 バイト
Subtitle: Linuxをインストールしてみました
# play MP3 file
#
# ... invoke MP3 player with high priority
#
case "$1" in
http://*.mp3|ftp://*.mp3)
#
# Cats are buffers against network stall.
# Please adjust its numbers, if necessary.
#
echo "$1" > ctrl/playing/contents
ftp -o - "$1" |cat|cat|cat| nice -n -15 /usr/local/bin/mpg123 $opts -
;;
*.[Mm][Pp]3)
if [ -f "$1" ]; then
echo "$1" > ctrl/playing/contents
nice -n -15 /usr/local/bin/mpg123 $opts "$1"
else
echo "Cannot find $1"
fi
;;
esac
}
LED 氏より 386BSD と一緒に頂いた Linux をインストールしてみました。雑
誌などの紹介記事にもよく書かれていることですが、386BSD に比べるとかなり
小さなシステムです。ディストリビューションは 3.5" 1.44MB の FD が17枚
で、386BSD の 1/3 位です。運用に要なディスクの容量も 100MB もあればお
つりがきます(386BSD はフルインストールすると 200M でもちょっと苦しいか
な、という感じです)。
インストールは 386BSD に比べ、格段に楽でした。あらかじめチェックしてお
かなければいけないのは、fdisk と mkfs のやりかたくらいで、後はほぼメッセー
ジに従って操作してゆけば完了します。
# move played file to another directory.
# directory hierarchy preserved.
#
# Usage: movefile srcpath desttop
#
movefile () {
[ $# -lt 2 ] && return
[ -f $1 ] || return
destdir=$2/${1#*/}
destdir=${destdir%[^/]*}
if [ -d $destdir ]; then
mv $1 $destdir
else
su mp3play -c "mkdir -p $destdir" && mv $1 $destdir
fi
}
インストール後に、何パッケージが小さいかがわかりました。ソースがあま
りないんですね。でも、Emacs があるのは偉い!と思いました。あと、Linux は
MINIX がベースになっているだけあって、カーネルのディレクトリ(これはカー
ネルを再生成できるようにソースがあります)に mm (memory manager) と fs (
file system) がちゃんとありました。
UNIX システムの色んなところを徹底的にいじってみたいという人には 386BSD
が、DOS/V や MS-Windows と存させて楽しみたいという人には Linux が合っ
ているように感じました。386BSD は 98 に移植されていますが、Linux はそう
ではありません。でも、Linux のほうが 98 に向いているのでは、とも思いまし
た。
#=====
# Running code from here
#=====
[SIN4103 / kaw]
#comment
Note 12/272(OLD2 2) Junk Box
[ RESPONSE 178/191 ]
Title : UNIXって、なぁーに?
SIN4103 [kaw] 93/03/13 14:34:59 サイズ: 2510 バイト
Subtitle: 386BSDのインストール
# Base and current directory is where script placed.
#
progfile=$0
cd `dirname $progfile` || exit 1
で、Linux でちょっと遊んだあと、再度 386BSD をインストールしました。イ
ンストールを何回かやってみて、効率のよいインストールの方法がわかってきま
した。以下にその概要を。
# check if another player running
#
if mkdir ctrl/playing; then
date > ctrl/playing/started
chmod 0755 ctrl/playing
else
echo "Another player running"
exit 1
fi
1) dist.fs で立ち上げて、install コマンドでハードディスクに書込む。
2) ハードディスクで立ち上げて、root でログインする。/tmp に mread
で bin01 を読み込み、/tmp/extract で展開する。
3) shutdown -r now でリブートし root でログインする
4) mread で src01 を読み込み cpio で展開する。
5) 同様に etc01 の読み込み・展開を行う。
6) Patch kit を読み込み、ソースにパッチをあてる。
7) /usr/src/lib を make, make install する。
8) /usr/src/{bin,libexec,sbin,usr.bin,usr.sbin} を make, make
install する。
# remove stale files
#
rm -f ctrl/exit ctrl/reboot ctrl/halt
で、ポイントは、
# user initialization
#
[ -r ctrl/init ] && . ctrl/init
・インストール直後にパッチを当てる。
色いじった後でパッチをあてようとすると、当然のことながらうまくパ
ッチがあたらなくなる可能性があります。Patch kit 0.2 の中には、/usr/
src/sys.386bsd/i386/conf/Makefile.i386 にあてるパッチも含まれていま
すので、修正後はカーネルの再生成もうまくいきます。
余談ですが、Patch kit 0.2 の README には「要がなければ、#00500,
#00602, #00603 のパッチはあてるな」と書いてあったので、部にパッチ
をあててから上の3つを deinstall しようとしたら #00603 は deinstall
できませんでした。何なんでしょう?
#=====
# main loop ... play MP3 and its control
#=====
while :; do
# parameters to MP3 player
#
unset opts
[ -f ctrl/mpg123opts ] && opts=`cat ctrl/mpg123opts`
・ライブラリの再構築を他のコンパイルよりもにやる。
ライブラリよりもに他のソース(コマンド、カーネル等)をコンパイル
してしまうと、パッチをあてる以前の古いライブラリが使われてしまいます。
# We have two spool directories for infinite loop
# ... spool0 and spool1.
#
# set direction of file movement
# between two spools
# when every MP3 file played
#
if [ -f ctrl/reverse ]; then
src=spool1
dest=spool0
else
src=spool0
dest=spool1
fi
・そのままでは make できないものがいくつかある。
以下のものは、そのままでは make できませんでしたので、Makefile の
SUBDIR からははずしておいたほうがよいと思われます。
# playlist is symlink to spool for playing.
#
rm -f playlist
ln -s $src playlist
/usr/src/lib/libg++
/usr/src/usr.bin/awk
/usr/src/usr.bin/elvis
/usr/src/usr.bin/gdb
/usr/src/usr.bin/grotty
/usr/src/usr.bin/ktrace
/usr/src/usr.bin/tn3270
# for every MP3 files
# control and/or playing
#
# xNOPLAY is a sentinel to run inner loop
#
for playfile in xNOPLAY `find $src -type f \( -iname '*.mp3' -o -iname '*.u
rl' \) | sort`; do
このあとの作業としては、
# retrieve resource location
#
case "$playfile" in
*.[Uu][Rr][Ll])
mp3reslist=`cat $playfile`
;;
*.[Mm][Pp]3|xNOPLAY)
mp3reslist=$playfile
;;
esac
・カーネルの再生成
・一般ユーザの登録
・コントリビューション・ソフトのインストール
・DES Encryption の組込み
・その他、非標準ソフトのインストール
# for every MP3 resource ...
#
for mp3res in $mp3reslist; do
等がありますがこれらは任意の順番でやってもOKですし、最初の2つ以外は特
に要を感じなければ省略してもよいと思います。
# perform one shot playlist
#
while :; do
for oneshot in xNOPLAY `find oneshot -type f \( -iname '*.mp3' -o -iname '*.u
rl' \) | sort`; do
# retrieve resource location
#
case "$oneshot" in
*.[Uu][Rr][Ll])
oneshot_mp3res=`cat $oneshot`
;;
*.[Mm][Pp]3|xNOPLAY)
oneshot_mp3res=$oneshot
;;
esac
で、現在の私の課題ですが、ps コマンドで ps aux として結果を見るとすべ
てのプロセスで TT の覧が ?? になってしまうので、この原因を究明中でありま
す。
for os_mp3 in $oneshot_mp3res; do
# check if resource file removed
#
if [ -f $oneshot ]; then
play_one_action $os_mp3
fi
# rescan all contents
#
if [ -f ctrl/rescan ]; then
echo "Rescanning playlist..."
break 5
fi
done
movefile $oneshot oneshot_finished
done
[ X"$oneshot" = XxNOPLAY ] && break
done
play_one_action $mp3res
# restart at current spool
#
if [ -f ctrl/rescan ]; then
echo "Rescanning playlist..."
break 2
fi
done
# move played file to the other spool
#
movefile $playfile $dest
done
# pause when no MP3 files in spools
#
if [ X"$playfile$oneshot" = XxNOPLAYxNOPLAY ]; then
noplay=Z$noplay
echo "No file to play : $noplay"
if [ $noplay = ZZ ]; then
echo "Now sleeping for 60 secs..."
sleep 60
noplay=""
fi
else
noplay=""
fi
# role change of spools
# (not changing when rescan)
#
if [ -f ctrl/rescan ]; then
rm -f ctrl/rescan
else
if [ -f ctrl/reverse ]; then
rm -f ctrl/reverse
else
touch ctrl/reverse
fi
fi
done
----
kqueue / kevent というものを初めて使ってみた;
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
main () {
/*
* Open current working directory
*/
DIR *d;
int dfd;
int err;
if (!(d = opendir("."))) {
perror("opendir");
exit(1);
}
/*
* create and register kernel event queue
*/
int kq;
struct kevent kev;
if ((kq = kqueue()) == -1) {
perror("kqueue");
closedir(d);
exit(1);
}
EV_SET(&kev, dirfd(d), EVFILT_VNODE, EV_ADD|EV_CLEAR, NOTE_WRITE, 0, NULL);
if (kevent(kq, &kev, 1, NULL, 0, NULL) < 0) {
perror("kevent on register");
closedir(d);
exit(1);
}
int retval;
/*
* then go monitoring
*/
if (0 < kevent(kq, NULL, 0, &kev, 1, NULL)) {
printf("dir changed.\n");
} else {
perror("kevent on nofity");
closedir(d);
exit(1);
}
/*
* normal exit
*/
closedir(d);
exit(0);
}
[SIN4103 / kaw]
#comment