トップ 追記

Masa's blog

検索キーワード:

2017年10月20日 Using named pipe with PowerShell [長年日記]

_ `echo' Server

$shutdown = $false
while (-not $shutdown){
        $pipe = New-Object System.IO.Pipes.NamedPipeServerStream "NamedPipeForEcho",InOut
        $pipe.WaitForConnection()
        $buf = New-Object byte[] 1024
        $loop = $true
        while($loop) {
                try {
                        $len = $pipe.Read($buf, 0, $buf.Length)
                        $cmd = [System.Text.Encoding]::Unicode.GetString($buf, 0, $len)
                        if($cmd -match '^exit|^quit|^shutdown') {
                                $loop = $false
                                if($cmd -match '^shutdown') {
                                        $shutdown = $true
                                }
                        } else {
                                $wb = [System.Text.Encoding]::Unicode.GetBytes($cmd)
                                $pipe.Write($wb, 0, $wb.Length)
                        }
                }catch{
                        $loop = $false
                }
        }
        $pipe.Close()
}

_ Client

$pipe = New-Object System.IO.Pipes.NamedPipeClientStream ".", "NamedPipeForEcho",InOut
$pipe.Connect()
$buf = New-Object byte[] 1024

$wb = [System.Text.Encoding]::Unicode.GetBytes("Hello, world.")
$pipe.Write($wb, 0, $wb.Length)
$len = $pipe.Read($buf, 0, $buf.Length)
[System.Text.Encoding]::Unicode.GetString($buf, 0, $len)

$wb = [System.Text.Encoding]::Unicode.GetBytes("exit")
$pipe.Write($wb, 0, $wb.Length)
#$wb = [System.Text.Encoding]::Unicode.GetBytes("shutdown")
#$pipe.Write($wb, 0, $wb.Length)

2017年10月08日 llvm-3.9 or later was required to build firefox-56 on Slackware-14.2 [長年日記]

_ I had to do version up llvm-3.8 to llvm-3.9.1 to build firefox-56.0.1

_ llvm.Slackbuild

_ Build

# sh llvm.SlackBuild

_ Install

# installpkg /tmp/llvm-3.9.1-x86_64-2.txz

And then I got success to build firefox-56 ;)


2017年09月24日 How to read QRCode by using zbar-0.10 on Slackware-14.2 [長年日記]

_ Build of zbar-0.10 on Slackware-14.2

  • ln -s /usr/include/libv4l1-videodev.h /usr/include/linux/videodev.h
  • tar xvf zbar-0.10.tar.bz2
  • cd zbar-0.10
  • ./configure && make && make install
  • rm /usr/include/linux/videodev.h

_ qrcode.sh

#! /bin/sh
LD_PRELOAD=/usr/lib64/libv4l/v4l1compat.so zbarcam /dev/video0 |\
while :
do
	read i
	if [ "X$i" = "X" ]
	then
		break
	else
		isUrl=`echo $i | egrep 'https*://'`
		if [ "X${isUrl}" != "X" ]
		then
			url=`echo $i | sed -e 's/^.*http/http/'`
			echo detected URL is ${url}
			/usr/local/firefox/firefox/firefox ${url}
		else
			echo Ignore $i
		fi
	fi
done

2017年09月21日 Script to merge movies left-right or top-bottom [長年日記]

_ mergemovies.sh

Script to merge two movies into left-right or top-bottom.

#! /bin/sh
#
if [ "X$1" = "X-h" -o "X$1" = "X--help" ]
then
	echo "Usage: $0 -l left_movie -r right_movie -o output_movie [options]"
	echo "       $0 -t top_movie -b bottom_movie -o output_movie [options]"
	echo "Merge movies into output_movie."
        echo ""
	echo "-l LEFT_MOVIE          movie file for left side"
	echo "-r RIGHT_MOVIE         movie file for right side"
	echo "-t TOP_MOVIE           movie file for top side"
	echo "-b BOTTOM_MOVIE        movie file for bottom side"
	echo "-o OUTPUT_MOVIE        movie file for output"
	echo "-a AUDIO_INPUT         lr   for left and right (default)"
	echo "                       l    for left"
	echo "                       r    for right"
	echo "                       tb   for top and bottom (default)"
	echo "                       t    for top"
	echo "                       b    for bottom"
	echo "                       none for no audio"
	echo "-bv VIDEO_BITRATE      bitrate for video (e.g. 2000k)"
	echo "-ba AUDIO_BITRATE      bitrate for audio (e.g. 192k)"
	echo "-vl VOLUME             amplitude for left volume (e.g. 1.2)"
	echo "                       -vr for right"
	echo "                       -vt for top"
	echo "                       -vb for bottom"
	echo "-fr FRAME_RATE         frame rate (e.g. 29.97)"
	echo "-sz SIZE               size for output (e.g. 1920x1080)"
	echo "-stl STARTTIME         start time for left movie (e.g. HH:MM:SS[.mmm])"
	echo "                       -str for right"
	echo "                       -stt for top"
	echo "                       -stb for bottom"
	echo "-etl ENDTIME           endtime for left movie (e.g. HH:MM:SS[.mmm])"
	echo "                       -etr for right"
	echo "                       -ett for top"
	echo "                       -etb for bottom"
	echo "-ell ELAPSTIME         elapstime for left movie (e.g. HH:MM:SS[.mmm])"
	echo "                       -elr for right"
	echo "                       -elt for top"
	echo "                       -elb for bottom"
        exit 0
fi

function preconvert(){
	input=$1; shift
	output=$1; shift
	pw=$1; shift
	ph=$1; shift
	vbitrate=$1; shift
	abitrate=$1; shift
	starttime=$1; shift
	endtime_with_opt=$1; shift
	volume=$1; shift
	framerate=$1

	iwh=`ffmpeg -i ${input} 2>&1 | egrep 'Stream.*Video' | sed -e 's/^.* \([0-9][0-9]*x[0-9][0-9]*\)[^0-9].*$/\1/g'`
	iw=`echo ${iwh} | cut -dx -f1`
	ih=`echo ${iwh} | cut -dx -f2`

	cond=`echo ${iw}*${ph}/${ih}/${pw} | bc`

	if [ ${cond} -gt 0 ]
	then
		sw=${pw}
		sh=`echo ${pw}*${ih}/${iw} | bc`
		padw=0
		padh=`echo "(${ph} - ${sh})/2" | bc`
	else
		sh=${ph}
		sw=`echo ${ph}*${iw}/${ih} | bc`
		padh=0
		padw=`echo "(${pw} - ${sw})/2" | bc`
	fi

	ffmpeg -i ${input} -ss ${starttime} ${endtime_with_opt} -vcodec h264 -b:v ${vbitrate} -r ${framerate} -strict -2 -acodec aac -b:a ${abitrate} -vol ${volume} -filter_complex "[0:v]scale=${sw}:${sh},pad=${pw}:${ph}:${padw}:${padh}" -y ${output}
}

left_movie=""
right_movie=""
top_movie=""
bottom_movie=""
output_movie=""
audio_input=""
video_bitrate="2000k"
audio_bitrate="192k"
left_volume="256"
right_volume="256"
top_volume="256"
bottom_volume="256"
frame_rate="3000/1001"
size="640x360"
left_starttime="00:00:00"
left_endelapstime="-t 24:00:00"
right_starttime="00:00:00"
right_endelapstime="-t 24:00:00"
top_starttime="00:00:00"
top_endelapstime="-t 24:00:00"
bottom_starttime="00:00:00"
bottom_endelapstime="-t 24:00:00"

while [ $# -ne 0 ]
do
	case $1 in
	-l)
		shift
		left_movie="$1"
		;;
	-r)
		shift
		right_movie="$1"
		;;
	-t)
		shift
		top_movie="$1"
		;;
	-b)
		shift
		bottom_movie="$1"
		;;
	-o)
		shift
		output_movie="$1"
		;;
	-a)
		shift
		audio_input="$1"
		;;
	-bv)
		shift
		video_bitrate="$1"
		;;
	-ba)
		shift
		audio_bitrate="$1"
		;;
	-vl)
		shift
		vol=`echo 256 \* $1 | bc | sed -e 's/\..*$//'`
		left_volume="${vol}"
		;;
	-vr)
		shift
		vol=`echo 256 \* $1 | bc | sed -e 's/\..*$//'`
		right_volume="${vol}"
		;;
	-vt)
		shift
		vol=`echo 256 \* $1 | bc | sed -e 's/\..*$//'`
		top_volume="${vol}"
		;;
	-vb)
		shift
		vol=`echo 256 \* $1 | bc | sed -e 's/\..*$//'`
		bottom_volume="${vol}"
		;;
	-fr)
		shift
		frame_rate="$1"
		;;
	-sz)
		shift
		size="$1"
		;;
	-stl)
		shift
		left_starttime="$1"
		;;
	-etl)
		shift
		left_endelapstime="-to $1"
		;;
	-ell)
		shift
		left_endelapstime="-t $1"
		;;
	-str)
		shift
		right_starttime="$1"
		;;
	-etr)
		shift
		right_endelapstime="-to $1"
		;;
	-elr)
		shift
		right_endelapstime="-t $1"
		;;
	-stt)
		shift
		top_starttime="$1"
		;;
	-ett)
		shift
		top_endelapstime="-to $1"
		;;
	-elt)
		shift
		top_endelapstime="-t $1"
		;;
	-stb)
		shift
		bottom_starttime="$1"
		;;
	-etb)
		shift
		bottom_endelapstime="-to $1"
		;;
	-elb)
		shift
		bottom_endelapstime="-t $1"
		;;
	esac
	shift
done

if [ "X${audio_input}" = "X" ]
then
	if [ "X${left_movie}" = "X" ]
	then
		audio_input="tb"
	else
		audio_input="lr"
	fi
fi

pw=`echo ${size} | cut -dx -f1`
ph=`echo ${size} | cut -dx -f2`

if [ "X${left_movie}" = "X" ]
then
	half_ph=`echo ${ph}/2 | bc`
	preconvert ${top_movie} /tmp/mergemovie.$$.1.tmp.mp4 ${pw} ${half_ph} ${video_bitrate} ${audio_bitrate} ${top_starttime} "${top_endelapstime}" ${top_volume} ${frame_rate}
	preconvert ${bottom_movie} /tmp/mergemovie.$$.2.tmp.mp4 ${pw} ${half_ph} ${video_bitrate} ${audio_bitrate} ${bottom_starttime} "${bottom_endelapstime}" ${bottom_volume} ${frame_rate}
else
	half_pw=`echo ${pw}/2 | bc`
	preconvert ${left_movie} /tmp/mergemovie.$$.1.tmp.mp4 ${half_pw} ${ph} ${video_bitrate} ${audio_bitrate} ${left_starttime} "${left_endelapstime}" ${left_volume} ${frame_rate}
	preconvert ${right_movie} /tmp/mergemovie.$$.2.tmp.mp4 ${half_pw} ${ph} ${video_bitrate} ${audio_bitrate} ${right_starttime} "${right_endelapstime}" ${right_volume} ${frame_rate}
fi

ffmpeg -i /tmp/mergemovie.$$.1.tmp.mp4 -strict -2 -acodec copy -vn -y /tmp/mergemovie.$$.3.tmp.wav.mp4
ffmpeg -i /tmp/mergemovie.$$.2.tmp.mp4 -strict -2 -acodec copy -vn -y /tmp/mergemovie.$$.4.tmp.wav.mp4

case ${audio_input} in
lr|tb)
	ffmpeg -i /tmp/mergemovie.$$.3.tmp.wav.mp4 -i /tmp/mergemovie.$$.4.tmp.wav.mp4 -strict -2 -acodec aac -b:a ${audio_bitrate} -filter_complex amix=inputs=2 -y /tmp/mergemovie.$$.5.tmp.wav.mp4
	;;
l|t)
	mv /tmp/mergemovie.$$.3.tmp.wav.mp4 /tmp/mergemovie.$$.5.tmp.wav.mp4
	;;
r|b)
	mv /tmp/mergemovie.$$.4.tmp.wav.mp4 /tmp/mergemovie.$$.5.tmp.wav.mp4
	;;
esac

ffmpeg -i /tmp/mergemovie.$$.1.tmp.mp4 -vcodec copy -strict -2 -an -y /tmp/mergemovie.$$.6.tmp.mp4
ffmpeg -i /tmp/mergemovie.$$.2.tmp.mp4 -vcodec copy -strict -2 -an -y /tmp/mergemovie.$$.7.tmp.mp4
if [ "X${left_movie}" = "X" ]
then
	ffmpeg -i /tmp/mergemovie.$$.6.tmp.mp4 -i /tmp/mergemovie.$$.7.tmp.mp4 -strict -2 -vcodec h264 -b:v ${video_bitrate} -filter_complex "[0:v]pad=iw:ih*2[v1];[v1][1:v]overlay=0:H/2" -y /tmp/mergemovie.$$.8.tmp.mp4
else
	ffmpeg -i /tmp/mergemovie.$$.6.tmp.mp4 -i /tmp/mergemovie.$$.7.tmp.mp4 -strict -2 -vcodec h264 -b:v ${video_bitrate} -filter_complex "[0:v]pad=iw*2:ih[v1];[v1][1:v]overlay=W/2:0" -y /tmp/mergemovie.$$.8.tmp.mp4
fi

if [ "X${audio_input}" = "Xnone" ]
then
	mv /tmp/mergemovie.$$.8.tmp.mp4 ${output_movie}
else
	ffmpeg -i /tmp/mergemovie.$$.8.tmp.mp4 -i /tmp/mergemovie.$$.5.tmp.wav.mp4 -strict -2 -vcodec copy -acodec copy -y ${output_movie}
fi

rm -f /tmp/mergemovie.$$.*.tmp.mp4 /tmp/mergemovie.$$.*.tmp.wav.mp4

2017年09月17日 Script which uses overlay with ffmpeg [長年日記]

_ overlaymovie.sh

Script which uses overlay with ffmpeg.

#! /bin/sh
#
if [ "X$1" = "X-h" -o "X$1" = "X--help" ]
then
	echo "Usage: $0 -m main_movie -s sub_movie -o output_movie [options]"
	echo "put sub_movie on main_movie into output_movie."
        echo ""
	echo "-m MAIN_MOVIE          movie file for background"
	echo "-s SUB_MOVIE           movie file for overlay"
	echo "-o OUTPUT_MOVIE        movie file for output"
	echo "-a AUDIO_INPUT         ms   for main and sub (default)"
	echo "                       m    for main"
	echo "                       s    for sub"
	echo "                       none for no audio"
	echo "-bv VIDEO_BITRATE      bitrate for video (e.g. 2000k)"
	echo "-ba AUDIO_BITRATE      bitrate for audio (e.g. 192k)"
	echo "-vm MAIN_VOLUME        amplitude for main volume (e.g. 1.2)"
	echo "-vs SUB_VOLUME         amplitude for sub volume (e.g. 1.2)"
	echo "-r FRAME_RATE          frame rate (e.g. 29.97)"
	echo "-szm MAIN_SIZE         size for main movie (e.g. 1920x1080)"
	echo "-szs SUB_SIZE          size for sub movie (e.g. 960x540)"
	echo "-stm MAIN_STARTTIME    start time for main movie (e.g. HH:MM:SS[.mmm])"
	echo "-etm MAIN_ENDTIME      endtime for main movie (e.g. HH:MM:SS[.mmm])"
	echo "-elm MAIN_ELAPSTIME    elapstime for main movie (e.g. HH:MM:SS[.mmm])"
	echo "-sts SUB_STARTTIME     start time for sub movie (e.g. HH:MM:SS[.mmm])"
	echo "-ets SUB_ENDTIME       endtime for sub movie (e.g. HH:MM:SS[.mmm])"
	echo "-els SUB_ELAPSTIME     elapstime for sub movie (e.g. HH:MM:SS[.mmm])"
	echo "-p SUB_POSITION        position for sub movie"
        echo "                       t, n   for top"
        echo "                       b, s   for bottom"
        echo "                       r, e   for right"
        echo "                       l, w   for left"
        echo "                       tr, ne for top-right"
        echo "                       tl, nw for top-left"
	echo "                       br, se for bottom-right (default)"
        echo "                       bl, sw for bottom-left"
        echo "                       c      for center"
        exit 0
fi

main_movie=""
sub_movie=""
output_movie=""
audio_input="ms"
video_bitrate="2000k"
audio_bitrate="192k"
main_volume=""
sub_volume=""
frame_rate="3000/1001"
main_size="1920x1080"
sub_size="960x540"
main_starttime="00:00:00"
main_endtime=""
main_elapstime=""
sub_starttime="00:00:00"
sub_endtime=""
sub_elapstime=""
sub_position="br"

while [ $# -ne 0 ]
do
	case $1 in
	-m)
		shift
		main_movie="$1"
		;;
	-s)
		shift
		sub_movie="$1"
		;;
	-o)
		shift
		output_movie="$1"
		;;
	-a)
		shift
		audio_input="$1"
		;;
	-bv)
		shift
		video_bitrate="$1"
		;;
	-ba)
		shift
		audio_bitrate="$1"
		;;
	-vm)
		shift
		vol=`echo 256 \* $1 | bc | sed -e 's/\..*$//'`
		main_volume="-vol ${vol}"
		;;
	-vs)
		shift
		vol=`echo 256 \* $1 | bc | sed -e 's/\..*$//'`
		sub_volume="-vol ${vol}"
		;;
	-r)
		shift
		frame_rate="$1"
		;;
	-szm)
		shift
		main_size="$1"
		;;
	-szs)
		shift
		sub_size="$1"
		;;
	-stm)
		shift
		main_starttime="$1"
		;;
	-etm)
		shift
		main_endtime="-to $1"
		;;
	-elm)
		shift
		main_elapstime="-t $1"
		;;
	-sts)
		shift
		sub_starttime="$1"
		;;
	-ets)
		shift
		sub_endtime="-to $1"
		;;
	-els)
		shift
		sub_elapstime="-t $1"
		;;
	-p)
		shift
		sub_position="$1"
		;;
	esac
	shift
done

main_width=`echo ${main_size} | cut -dx -f1`
main_height=`echo ${main_size} | cut -dx -f2`

sub_width=`echo ${sub_size} | cut -dx -f1`
sub_height=`echo ${sub_size} | cut -dx -f2`

case ${sub_position} in
t|n)
	sub_x=`echo "(${main_width} - ${sub_width}) / 2" | bc`
	sub_y=0
	;;
tr|ne)
	sub_x=`echo "${main_width} - ${sub_width}" | bc`
	sub_y=0
	;;
r|e)
	sub_x=`echo "${main_width} - ${sub_width}" | bc`
	sub_y=`echo "(${main_height} - ${sub_height}) / 2" | bc`
	;;
br|se)
	sub_x=`echo "${main_width} - ${sub_width}" | bc`
	sub_y=`echo "${main_height} - ${sub_height}" | bc`
	;;
b|s)
	sub_x=`echo "(${main_width} - ${sub_width}) / 2" | bc`
	sub_y=`echo "${main_height} - ${sub_height}" | bc`
	;;
bl|sw)
	sub_x=0
	sub_y=`echo "${main_height} - ${sub_height}" | bc`
	;;
l|w)
	sub_x=0
	sub_y=`echo "(${main_height} - ${sub_height}) / 2" | bc`
	;;
tl|nw)
	sub_x=0
	sub_y=0
	;;
c)
	sub_x=`echo "(${main_width} - ${sub_width}) / 2" | bc`
	sub_y=`echo "(${main_height} - ${sub_height}) / 2" | bc`
	;;
*)
	sub_x=`echo "(${main_width} - ${sub_width}) / 2" | bc`
	sub_y=`echo "(${main_height} - ${sub_height}) / 2" | bc`
	;;
esac

ffmpeg -i ${main_movie} -strict -2 -ss ${main_starttime} ${main_endtime} ${main_elapstime} ${main_volume} -vn -y /tmp/overlaymovie.$$.1.tmp.wav.mp4
ffmpeg -i ${sub_movie} -strict -2 -ss ${sub_starttime} ${sub_endtime} ${sub_elapstime} ${sub_volume} -vn -y /tmp/overlaymovie.$$.2.tmp.wav.mp4
case ${audio_input} in
ms)
	ffmpeg -i /tmp/overlaymovie.$$.1.tmp.wav.mp4 -i /tmp/overlaymovie.$$.2.tmp.wav.mp4 -strict -2 -acodec aac -b:a ${audio_bitrate} -filter_complex amix=inputs=2 -y /tmp/overlaymovie.$$.3.tmp.wav.mp4
	;;
m)
	ffmpeg -i /tmp/overlaymovie.$$.1.tmp.wav.mp4 -strict -2 -acodec aac -b:a ${audio_bitrate} -y /tmp/overlaymovie.$$.3.tmp.wav.mp4
	;;
s)
	ffmpeg -i /tmp/overlaymovie.$$.2.tmp.wav.mp4 -strict -2 -acodec aac -b:a ${audio_bitrate} -y /tmp/overlaymovie.$$.3.tmp.wav.mp4
	;;
esac

ffmpeg -i ${main_movie} -strict -2 -ss ${main_starttime} ${main_endtime} ${main_elapstime} -s ${main_size} -an -y /tmp/overlaymovie.$$.4.tmp.mp4
ffmpeg -i ${sub_movie} -strict -2 -ss ${sub_starttime} ${sub_endtime} ${sub_elapstime} -s ${sub_size} -an -y /tmp/overlaymovie.$$.5.tmp.mp4
ffmpeg -i /tmp/overlaymovie.$$.4.tmp.mp4 -i /tmp/overlaymovie.$$.5.tmp.mp4 -strict -2 -vcodec h264 -b:v ${video_bitrate} -r ${frame_rate} -filter_complex "[0:v][1:v]overlay=${sub_x}:${sub_y}" -y /tmp/overlaymovie.$$.6.tmp.mp4

if [ "X${audio_input}" = "Xnone" ]
then
	ffmpeg -i /tmp/overlaymovie.$$.6.tmp.mp4 -strict -2 -vcodec copy -y ${output_movie}
else
	ffmpeg -i /tmp/overlaymovie.$$.6.tmp.mp4 -i /tmp/overlaymovie.$$.3.tmp.wav.mp4 -strict -2 -vcodec copy -acodec copy -y ${output_movie}
fi

rm -f /tmp/overlaymovie.*.*.tmp.*

2017年06月27日 mscore-1.3 on Slackware-14.2 [長年日記]

_ mscore-1.3 on Slackware-14.2

Build

$ tar xvf mscore-1.3.tar.bz2
$ cd mscore-1.3
$ patch ../mscore-1.3.diff | patch -p0
*** ./mscore/mscore/CMakeLists.txt.ORG	2017-06-27 00:14:09.333969024 +0900
--- ./mscore/mscore/CMakeLists.txt	2017-06-27 00:14:41.637968660 +0900
***************
*** 274,279 ****
--- 274,280 ----
        qtsingleapp
        fluid
        z
+       pthread
        )

     if (HAS_AUDIOFILE)
$ make release
$ sudo make install

Setting

Edit -> Setting -> I/O -> check `JACK AUDIO SERVER'


2017年06月20日 How to make WLI-UC-GNM working stably with Slackware-14.2 [長年日記]

_ How to make WLI-UC-GNM working stably with Slackware-14.2

$ lsusb

Bus 004 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 004: ID 056e:0084 Elecom Co., Ltd
Bus 003 Device 003: ID 0411:01a2 BUFFALO INC. (formerly MelCo., Inc.) WLI-UC-GNM Wireless LAN Adapter [Ralink RT8070]    # <- This is WLI-UC-GNM
Bus 003 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

/etc/rc.d/rc.wireless.conf

DC:FB:02:*)
    ESSID="_YOUR_ESSID_"
    MODE="Managed"
    KEY="_YOUR_PASSWORD_"
    IWCONFIG="power off"       # <- This is important!
    ;;

/etc/modprobe.d/rt2800usb.conf

options rt2800usb nohwcrypt=1

2017年06月04日 Version up php-5.5.11 to php-7.1.5 [長年日記]

_ Version up php-5.5.11 to php-7.1.5

Build

$ tar xvf php-7.1.5.tar.bz2
$ cd php-7.1.5
$ cat ../php-7.1.5.diff | patch -p0
*** ./configure.ORG     2017-06-04 10:50:30.000000000 +0900
--- ./configure 2017-06-04 10:55:11.000000000 +0900
***************
*** 79826,79832 ****
  ac_fn_c_check_decl "$LINENO" "isnan" "ac_cv_have_decl_isnan" "#include <math.h>
 "
  if test "x$ac_cv_have_decl_isnan" = xyes; then :
!   ac_have_decl=1
  else
    ac_have_decl=0
  fi
--- 79826,79832 ----
  ac_fn_c_check_decl "$LINENO" "isnan" "ac_cv_have_decl_isnan" "#include <math.h>
 "
  if test "x$ac_cv_have_decl_isnan" = xyes; then :
!   ac_have_decl=0
  else
    ac_have_decl=0
  fi
***************
*** 79837,79843 ****
  ac_fn_c_check_decl "$LINENO" "isinf" "ac_cv_have_decl_isinf" "#include <math.h>
 "
  if test "x$ac_cv_have_decl_isinf" = xyes; then :
!   ac_have_decl=1
  else
    ac_have_decl=0
  fi
--- 79837,79843 ----
  ac_fn_c_check_decl "$LINENO" "isinf" "ac_cv_have_decl_isinf" "#include <math.h>
 "
  if test "x$ac_cv_have_decl_isinf" = xyes; then :
!   ac_have_decl=0
  else
    ac_have_decl=0
  fi
***************
*** 95505,95511 ****
  ac_fn_c_check_decl "$LINENO" "isfinite" "ac_cv_have_decl_isfinite" "#include <math.h>
 "
  if test "x$ac_cv_have_decl_isfinite" = xyes; then :
!   ac_have_decl=1
  else
    ac_have_decl=0
  fi
--- 95505,95511 ----
  ac_fn_c_check_decl "$LINENO" "isfinite" "ac_cv_have_decl_isfinite" "#include <math.h>
 "
  if test "x$ac_cv_have_decl_isfinite" = xyes; then :
!   ac_have_decl=0
  else
    ac_have_decl=0
  fi
***************
*** 95516,95522 ****
  ac_fn_c_check_decl "$LINENO" "isnan" "ac_cv_have_decl_isnan" "#include <math.h>
 "
  if test "x$ac_cv_have_decl_isnan" = xyes; then :
!   ac_have_decl=1
  else
    ac_have_decl=0
  fi
--- 95516,95522 ----
  ac_fn_c_check_decl "$LINENO" "isnan" "ac_cv_have_decl_isnan" "#include <math.h>
 "
  if test "x$ac_cv_have_decl_isnan" = xyes; then :
!   ac_have_decl=0
  else
    ac_have_decl=0
  fi
***************
*** 95527,95533 ****
  ac_fn_c_check_decl "$LINENO" "isinf" "ac_cv_have_decl_isinf" "#include <math.h>
 "
  if test "x$ac_cv_have_decl_isinf" = xyes; then :
!   ac_have_decl=1
  else
    ac_have_decl=0
  fi
--- 95527,95533 ----
  ac_fn_c_check_decl "$LINENO" "isinf" "ac_cv_have_decl_isinf" "#include <math.h>
 "
  if test "x$ac_cv_have_decl_isinf" = xyes; then :
!   ac_have_decl=0
  else
    ac_have_decl=0
  fi
$ ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysqli=mysqlnd --with-gd --with-zlib --with-bz2 --with-openssl=/usr/local/ssl
$ make
$ su
# make install && ldconfig
# cp php.ini-development /usr/local/lib/php7.ini
# vim /usr/local/lib/php7.ini
# cd /usr/local/lib
# rm php.ini
# ln -s php7.ini php.ini

_ After install php-7, apache got segfault

I have to remove line for old php5.

/usr/local/apache2/conf/httpd.conf

#DEL_LoadModule php5_module        modules/libphp5.so
LoadModule php7_module        modules/libphp7.so

2017年05月27日 let's encrypt [長年日記]

_ let's encrypt

pre-requirement

  • mercurial-1.8.2.tar.gz
  • python-2.7.11.tar.gz
  • curl-7.53.1.tar.gz (must be enabled SNI)

getssl-2.10.zip

Create default config files.

# getssl -c myh.no-ip.org

~/.getssl/getssl.cfg

CA="https://acme-v01.api.letsencrypt.org"
ACCOUNT_EMAIL="m-ito@myh.no-ip.org"
ACCOUNT_KEY_LENGTH=4096
ACCOUNT_KEY="/root/.getssl/account.key"
PRIVATE_KEY_ALG="rsa"
RENEW_ALLOW="30"
SERVER_TYPE="https"
CHECK_REMOTE="true"

~/.getssl/myh.no-ip.org/getssl.cfg

CA="https://acme-v01.api.letsencrypt.org"
SANS=""
ACL=('/usr/local/apache2/htdocs/.well-known/acme-challenge')

Create certificate etc.

# getssl myh.no-ip.org

Update certificate.

# getssl -u -a -q && cp `find /root/.getssl/myh.no-ip.org/archive/ -type d|tail -1`/* /root/.getssl/myh.no-ip.org/

2017年04月30日 firefox-53 with cairo-gtk3 and lprng [長年日記]

_ firefox-53 with cairo-gtk3 and lprng

I tried to build firefox-53, but it failed. because firefox-53 already doesn't support cailo-gtk2 ! Of course, I have succeeded to build firefox-53 with cairo-gtk3.

But I faced to another issue about printing by firefox. gtk2 supports printing by lpr, but gtk3 doesn't support it. And I have been LPRng's user in long time :P

CUPS is one of solutions for this issue, but I don't like it. So I resolved this issue by another way ;)

notify_change.c

#include <errno.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/inotify.h>
#include <unistd.h>

/* Read all available inotify events from the file descriptor 'fd'.
   wd is the table of watch descriptors for the directories in argv.
   argc is the length of wd and argv.
   argv is the list of watched directories.
   Entry 0 of wd and argv is unused. */

static void handle_events(int fd, int *wd, int argc, char *argv[])
{
    /* Some systems cannot read integer variables if they are not
       properly aligned. On other systems, incorrect alignment may
       decrease performance. Hence, the buffer used for reading from
       the inotify file descriptor should have the same alignment as
       struct inotify_event. */

    char buf[4096]
        __attribute__ ((aligned(__alignof__(struct inotify_event))));
    const struct inotify_event *event;
    int i;
    ssize_t len;
    char *ptr;

    /* Loop while events can be read from inotify file descriptor. */

    for (;;) {

        /* Read some events. */

        len = read(fd, buf, sizeof buf);
        if (len == -1 && errno != EAGAIN) {
            perror("read");
            exit(EXIT_FAILURE);
        }

        /* If the nonblocking read() found no events to read, then
           it returns -1 with errno set to EAGAIN. In that case,
           we exit the loop. */

        if (len <= 0)
            break;

        for (ptr = buf; ptr < buf + len;
             ptr += sizeof(struct inotify_event) + event->len) {

            event = (const struct inotify_event *) ptr;

            /* Print event type */

            if (event->mask & IN_OPEN)
                printf("IN_OPEN: ");
            if (event->mask & IN_CLOSE_NOWRITE)
                printf("IN_CLOSE_NOWRITE: ");
            if (event->mask & IN_CLOSE_WRITE)
                printf("IN_CLOSE_WRITE: ");

            /* Print the name of the watched directory */

            for (i = 1; i < argc; ++i) {
                if (wd[i] == event->wd) {
                    printf("%s/", argv[i]);
                    break;
                }
            }

            /* Print the name of the file */

            if (event->len)
                printf("%s", event->name);

            /* Print type of filesystem object */

            if (event->mask & IN_ISDIR)
                printf(" [directory]\n");
            else
                printf(" [file]\n");

            fflush(stdout);
        }
    }
}

int main(int argc, char *argv[])
{
    char buf;
    int fd, i;
    int *wd;

    if (argc < 2) {
        printf("Usage: %s PATH [PATH ...]\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    /* Create the file descriptor for accessing the inotify API */

    fd = inotify_init();
    if (fd == -1) {
        perror("inotify_init");
        exit(EXIT_FAILURE);
    }

    /* Allocate memory for watch descriptors */

    wd = calloc(argc, sizeof(int));
    if (wd == NULL) {
        perror("calloc");
        exit(EXIT_FAILURE);
    }

    /* Mark directories for events
       - file was opened
       - file was closed */

    for (i = 1; i < argc; i++) {
        wd[i] = inotify_add_watch(fd, argv[i], IN_OPEN | IN_CLOSE);
        if (wd[i] == -1) {
            fprintf(stderr, "Cannot watch '%s'\n", argv[i]);
            perror("inotify_add_watch");
            exit(EXIT_FAILURE);
        }
    }

    while (1) {
        handle_events(fd, wd, argc, argv);
    }

    close(fd);
    free(wd);
    exit(EXIT_SUCCESS);
}

printspool.sh

#! /bin/sh
trap "rm -fr ~/printspool/LOCK.DIR; exit 0" INT TERM
mkdir ~/printspool/LOCK.DIR || exit 1
echo -n $$ >~/printspool/LOCK.DIR/pid
notify_change ~/printspool |\
while :
do
        read line
        if [ "X`echo $line | egrep 'IN_CLOSE_WRITE.*\[file\]'`" = "X" ]
        then
                :
        else
                file=`echo $line | cut -d ' ' -f 2`
                lpr $file && rm $file
        fi
done
rm -fr ~/printspool/LOCK.DIR

How to use

  • Run printspool.sh in background.
  • When you want to print from firefox, output file(postscript or pdf) into ~/printspool/ from print menu in firefox.
  • lpr will be invoked automatically to print file and after that, file will be removed.