Linuxで年賀状の宛名を印刷する
Linux Mint 19 32bitで年賀状の宛名を印刷する
昨日拍子抜けしつつLinux Mintでプリンタを認識してくれたので、続いては宛名を印刷するためのアプリケーションを用意しなければなりません。
正直これはかなりハードルが高いと想像しておりました。もし実現できなかったらもう家族に平謝りして安価な中古Windowsマシンでも購入しなければと最悪パターンも想定していたくらいで。 半ば諦めつつGoogle先生と相談していたところ以下のエントリにたどり着きまして。
そうだよね〜日本郵便のはがきデザインキットでも試してみるしかないか?でもAdobe Airは32bitのLinuxサポート切れみたいだし最悪Wineで何か使うか??と落胆していたところ同エントリにあるgatenaが目に入りました。
結論から申し上げるとgatenaは私の中の「神アプリ」です。
gatenaはおそらくGNU atenaの略。Google先生にお尋ねしても、それってもしかして「はてな」(gatenaではなくてhatena)の間違いじゃない?とサジェストしてくれます。いやgatenaなんですよ私が知りたいのは。
作者は htrbさん。本当に素晴らしい。
動作要件はRuby (version 1.9)とRuby-GTK2。Linux Mint 19でデフォルトインストールされているRubyは2.5みたいだけど、なんとかすればコンパイル通って動くんじゃないコレ?と思い立ったので簡単な導入方法を記載します。なお最初から動くとは思っていなかったので詳細なログを残しておりませんでしたので記載漏れ等がありましたらごめんなさい。
gatenaビルド手順
以下長文となっておりますので真剣に読み込む気になった方はご注意ください。また、下記手順はこちらの動作環境で確認できた限りの手順であり、下記手順を元にした操作で何らかの不具合等が発生した場合は私で責任は取れませんのでくれぐれもご注意ください。
ダウンロード
下記URLのSourceForgeから[gatena-0.1.0.tar.gz]をダウンロード。debパッケージ形式の[gatena_0.1.0_all.deb]も提供されているようですが、2011年時点のパッケージのようなので念のためソースコードからコンパイルしてみます。
tar.gzを解凍
下記コマンドで適切なディレクトリに保存した[gatena-0.1.0.tar.gz]を解凍
# tar xvzf gatena-0.1.0.tar.gz
ディレクトリ[gatena-0.1.0]が作成されるのでcdして素直にconfigureスクリプトを実行してみる。
# cd gatena-0.1.0 # ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking for xdg-icon-resource... yes checking for ruby1.9... no checking for ruby1.9.1... no checking for ruby... yes configure: error: "Cannot find Ruby."
Ruby1.9がインストールされていないよ?と指摘されてしまう。そりゃそうだ。
configureスクリプトを修正してみる
じゃあちょっと姑息かもしれないけど、Ruby2.5でもMakefileが作成されるようにconfigureスクリプトを修正してみる。でも直接configureスクリプトを修正するのは達成感は高いかもしれないけど今の私には現実的ではないのでconfigure.inファイルを修正しautoconfコマンドてconfigureスクリプトを作成してみることにする。
まずはautoconfをインストール
# apt install autoconf
続いてautoconf.in configure.inファイルを下記のように修正。diffの結果は後述。修正はviでもgeditでもxedでもどうぞ。ちなみに私は学生時代にviの基本操作を身に着けておいて本当に良かったとIT業界に身を置いてみて思っています。
dnl Process this file with autoconf to produce a configure script. AC_INIT(gatena, 0.1.0, ###00000@nifty.com, gatena) AC_CONFIG_SRCDIR(src/main.rb) AM_INIT_AUTOMAKE GSL_REQUIRED_VERSION=0.2.5 GTK_REQUIRED_VERSION=2.12.0 GLIB_REQUIRED_VERSION=$GTK_REQUIRED_VERSION AC_PROG_INSTALL # check ruby AC_CHECK_PROG(XDG_ICON_RESOURCE, xdg-icon-resource, yes, no) # check ruby AC_CHECK_PROG(RUBY1_9, ruby2.5, yes, no) AC_CHECK_PROG(RUBY1_9_1, ruby2.5.1, yes, no) AC_CHECK_PROG(RUBY, ruby, yes, no) if test "$RUBY" = "yes" then case 'ruby --version' in "ruby 2.5"*) RUBY_BIN=ruby ;; esac fi if test "x$RUBY_BIN" = "x" then if test "$RUBY1_9_1" = "yes" then RUBY_BIN=ruby1.9.1 elif test "$RUBY1_9" = "yes" then RUBY_BIN=ruby2.5 fi fi if test "x$RUBY_BIN" = "x" then AC_MSG_ERROR("Cannot find Ruby.") fi RUBY_FULL_PATH=`which $RUBY_BIN` AC_SUBST(RUBY_BIN) AC_SUBST(RUBY_FULL_PATH) # check Ruby-GTK2 echo -n "checking for Ruby-GTK2... " if $RUBY_BIN -e 'begin require "gtk2"; rescue Gtk::InitError; 0; end' then echo yes else AC_MSG_ERROR(Cannot find ruby-gnome2.) fi AC_CONFIG_FILES([Makefile data/Makefile src/Makefile po/Makefile desktop/Makefile zip/Makefile debian/Makefile]) AC_OUTPUT
修正前後のファイルのdiffは下記の通り。
18,19c18,19 < AC_CHECK_PROG(RUBY1_9, ruby1.9, yes, no) < AC_CHECK_PROG(RUBY1_9_1, ruby1.9.1, yes, no) --- > AC_CHECK_PROG(RUBY1_9, ruby2.5, yes, no) > AC_CHECK_PROG(RUBY1_9_1, ruby2.5.1, yes, no) 24c24 < "ruby 1.9"*) --- > "ruby 2.5"*) 37c37 < RUBY_BIN=ruby1.9 --- > RUBY_BIN=ruby2.5
ではautoconfを実行
# autoconf aclocal.m4:16: warning: this file was generated for autoconf 2.68. You have another version of autoconf. It may work, but is not guaranteed to. If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically `autoreconf'.
configureファイルの日付が更新されていることを確認して、再度configureスクリプトを実行。
# ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking for xdg-icon-resource... yes checking for ruby2.5... yes checking for ruby2.5.1... no checking for ruby... yes checking for Ruby-GTK2... Traceback (most recent call last): 1: from -e:1:in `<main>' -e:1:in `rescue in <main>': uninitialized constant Gtk (NameError) configure: error: Cannot find ruby-gnome2.
今度はRuby-GTK2がインストールされていないよ?と指摘された模様。なるほど。
Ruby-GTK2のインストール
ではgemでRuby-GTK2をインストールしてみる。
# gem install gtk2 Building native extensions. This could take a while... ERROR: Error installing gtk2: ERROR: Failed to build gem native extension. current directory: /var/lib/gems/2.5.0/gems/atk-3.2.9/dependency-check /usr/bin/ruby2.5 -rrubygems /usr/share/rubygems-integration/all/gems/rake-12.3.1/exe/rake RUBYARCHDIR=/var/lib/gems/2.5.0/extensions/x86-linux/2.5.0/atk-3.2.9 RUBYLIBDIR=/var/lib/gems/2.5.0/extensions/x86-linux/2.5.0/atk-3.2.9 /usr/bin/ruby2.5: No such file or directory -- /usr/share/rubygems-integration/all/gems/rake-12.3.1/exe/rake (LoadError) rake failed, exit code 1 Gem files will remain installed in /var/lib/gems/2.5.0/gems/atk-3.2.9 for inspection. Results logged to /var/lib/gems/2.5.0/extensions/x86-linux/2.5.0/atk-3.2.9/gem_make.out
gtk2をインストールできない。gem_make.outログの内容からgoogle先生に相談してみたところ、今度はrakeがインストールされてないよ?と指摘された模様。rakeが何なのかは深堀りせずに、素直にrakeをインストールしてみる。
# gem install rake Fetching: rake-12.3.1.gem (100%) Successfully installed rake-12.3.1 Parsing documentation for rake-12.3.1 Installing ri documentation for rake-12.3.1 Done installing documentation for rake after 2 seconds 1 gem installed
rakeがインストールされたので、改めてgem install gtk2
# gem install gtk2 Building native extensions. This could take a while... Successfully installed atk-3.2.9 Fetching: cairo-gobject-3.2.9.gem (100%) Building native extensions. This could take a while... ERROR: Error installing gtk2: ERROR: Failed to build gem native extension. current directory: /var/lib/gems/2.5.0/gems/cairo-gobject-3.2.9/ext/cairo-gobject /usr/bin/ruby2.5 -r ./siteconf20181011-4954-1fnhoef.rb extconf.rb checking for --enable-debug-build option... no checking for -Wall option to compiler... yes checking for -Waggregate-return option to compiler... yes checking for -Wcast-align option to compiler... yes checking for -Wextra option to compiler... yes checking for -Wformat=2 option to compiler... yes checking for -Winit-self option to compiler... yes checking for -Wlarger-than-65500 option to compiler... yes checking for -Wmissing-declarations option to compiler... yes checking for -Wmissing-format-attribute option to compiler... yes checking for -Wmissing-include-dirs option to compiler... yes checking for -Wmissing-noreturn option to compiler... yes checking for -Wmissing-prototypes option to compiler... yes checking for -Wnested-externs option to compiler... yes checking for -Wold-style-definition option to compiler... yes checking for -Wpacked option to compiler... yes checking for -Wp,-D_FORTIFY_SOURCE=2 option to compiler... yes checking for -Wpointer-arith option to compiler... yes checking for -Wswitch-default option to compiler... yes checking for -Wswitch-enum option to compiler... yes checking for -Wundef option to compiler... yes checking for -Wout-of-line-declaration option to compiler... no checking for -Wunsafe-loop-optimizations option to compiler... yes checking for -Wwrite-strings option to compiler... yes checking for cairo... no *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/usr/bin/$(RUBY_BASE_NAME)2.5 --enable-debug-build --disable-debug-build --with-pkg-config --without-pkg-config --with-override-variables --without-override-variables To see why this extension failed to compile, please check the mkmf.log which can be found here: /var/lib/gems/2.5.0/extensions/x86-linux/2.5.0/cairo-gobject-3.2.9/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /var/lib/gems/2.5.0/gems/cairo-gobject-3.2.9 for inspection. Results logged to /var/lib/gems/2.5.0/extensions/x86-linux/2.5.0/cairo-gobject-3.2.9/gem_make.out
少し進んだけどまたエラー。gem_make.outログの内容からgoogle先生にまた相談してみたところ、今度はcairoがインストールされていないと指摘された模様。当然cairoが何なのか深堀りせずに素直にcairoをインストールしてみる。
# gem install cairo Fetching: cairo-1.15.14.gem (100%) Building native extensions. This could take a while... Successfully installed cairo-1.15.14 Parsing documentation for cairo-1.15.14 Installing ri documentation for cairo-1.15.14 Done installing documentation for cairo after 5 seconds 1 gem installed
cairoがインストールされたので、改めてgem install gtk2
# gem install gtk2 Building native extensions. This could take a while... Successfully installed cairo-gobject-3.2.9 Fetching: gobject-introspection-3.2.9.gem (100%) Building native extensions. This could take a while... Successfully installed gobject-introspection-3.2.9 Fetching: pango-3.2.9.gem (100%) Building native extensions. This could take a while... Successfully installed pango-3.2.9 Fetching: gio2-3.2.9.gem (100%) Building native extensions. This could take a while... Successfully installed gio2-3.2.9 Fetching: gdk_pixbuf2-3.2.9.gem (100%) Building native extensions. This could take a while... Successfully installed gdk_pixbuf2-3.2.9 Fetching: gtk2-3.2.9.gem (100%) Building native extensions. This could take a while... Successfully installed gtk2-3.2.9 Parsing documentation for cairo-gobject-3.2.9 Installing ri documentation for cairo-gobject-3.2.9 Parsing documentation for gobject-introspection-3.2.9 Installing ri documentation for gobject-introspection-3.2.9 Parsing documentation for pango-3.2.9 Installing ri documentation for pango-3.2.9 Parsing documentation for gio2-3.2.9 Installing ri documentation for gio2-3.2.9 Parsing documentation for gdk_pixbuf2-3.2.9 Installing ri documentation for gdk_pixbuf2-3.2.9 Parsing documentation for gtk2-3.2.9 Installing ri documentation for gtk2-3.2.9 Done installing documentation for cairo-gobject, gobject-introspection, pango, gio2, gdk_pixbuf2, gtk2 after 9 seconds 6 gems installed
どうやらRuby-GTK2がインストールされた模様。ふー。
再びconfigure
これでconfigureスクリプトが通ればMakefileが作成されるはず。
# ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking for xdg-icon-resource... yes checking for ruby2.5... yes checking for ruby2.5.1... no checking for ruby... yes checking for Ruby-GTK2... yes configure: creating ./config.status config.status: creating Makefile config.status: creating data/Makefile config.status: creating src/Makefile config.status: creating po/Makefile config.status: creating desktop/Makefile config.status: creating zip/Makefile config.status: creating debian/Makefile
おおMakefileが作成された!ではmakeしてみよう!
# make CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/bash /root/gatena-0.1.0/missing --run aclocal-1.11 /root/gatena-0.1.0/missing: 行 52: aclocal-1.11: コマンドが見つかりません WARNING: `aclocal-1.11' is missing on your system. You should only need it if you modified `acinclude.m4' or `configure.in'. You might want to install the `Automake' and `Perl' packages. Grab them from any GNU archive site. cd . && /bin/bash /root/gatena-0.1.0/missing --run automake-1.11 --gnu /root/gatena-0.1.0/missing: 行 52: automake-1.11: コマンドが見つかりません WARNING: `automake-1.11' is missing on your system. You should only need it if you modified `Makefile.am', `acinclude.m4' or `configure.in'. You might want to install the `Automake' and `Perl' packages. Grab them from any GNU archive site. CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/bash /root/gatena-0.1.0/missing --run autoconf aclocal.m4:16: warning: this file was generated for autoconf 2.68. You have another version of autoconf. It may work, but is not guaranteed to. If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically `autoreconf'. /bin/bash ./config.status --recheck running CONFIG_SHELL=/bin/bash /bin/bash ./configure --no-create --no-recursion checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking for xdg-icon-resource... yes checking for ruby2.5... yes checking for ruby2.5.1... no checking for ruby... yes checking for Ruby-GTK2... yes configure: creating ./config.status /bin/bash ./config.status config.status: creating Makefile config.status: creating data/Makefile config.status: creating src/Makefile config.status: creating po/Makefile config.status: creating desktop/Makefile config.status: creating zip/Makefile config.status: creating debian/Makefile Making all in data make[1]: ディレクトリ '/root/gatena-0.1.0/data' に入ります ruby2.5 pathconv.rb /usr/local/share/gatena layout 0000.in ruby2.5 pathconv.rb /usr/local/share/gatena layout 0001.in make[1]: ディレクトリ '/root/gatena-0.1.0/data' から出ます Making all in src make[1]: ディレクトリ '/root/gatena-0.1.0/src' に入ります ruby2.5 make_gatena /usr/bin/ruby2.5 /usr/local/share/gatena 0.1.0 main.rb > gatena chmod 755 gatena make[1]: ディレクトリ '/root/gatena-0.1.0/src' から出ます Making all in zip make[1]: ディレクトリ '/root/gatena-0.1.0/zip' に入ります ruby2.5 make_zip_data.rb *.csv zip.bin x-ken-all.csv (1/1) 100% make[1]: ディレクトリ '/root/gatena-0.1.0/zip' から出ます Making all in po make[1]: ディレクトリ '/root/gatena-0.1.0/po' に入ります make[1]: 'all' に対して行うべき事はありません. make[1]: ディレクトリ '/root/gatena-0.1.0/po' から出ます Making all in desktop make[1]: ディレクトリ '/root/gatena-0.1.0/desktop' に入ります sed -e 's!@pixmapdir@!/usr/local/share/pixmaps!;' < gatena.desktop.in > gatena.desktop make[1]: ディレクトリ '/root/gatena-0.1.0/desktop' から出ます Making all in debian make[1]: ディレクトリ '/root/gatena-0.1.0/debian' に入ります make[1]: 'all' に対して行うべき事はありません. make[1]: ディレクトリ '/root/gatena-0.1.0/debian' から出ます make[1]: ディレクトリ '/root/gatena-0.1.0' に入ります make[1]: 'all-am' に対して行うべき事はありません. make[1]: ディレクトリ '/root/gatena-0.1.0' から出ます
ん?無事makeされたのかな?ではmake installしてみる。
# make install Making install in data make[1]: ディレクトリ '/root/gatena-0.1.0/data' に入ります make[2]: ディレクトリ '/root/gatena-0.1.0/data' に入ります make[2]: 'install-exec-am' に対して行うべき事はありません. test -z "/usr/local/share/gatena" || /bin/mkdir -p "/usr/local/share/gatena" /usr/bin/install -c -m 644 0000.layout 0001.layout 0002.layout 0003.layout 0004.layout 0005.layout aaaaaaaa.book book_index.txt from_book.dat nenga.png otosidama.png icon.png gatena.xml '/usr/local/share/gatena' make[2]: ディレクトリ '/root/gatena-0.1.0/data' から出ます make[1]: ディレクトリ '/root/gatena-0.1.0/data' から出ます Making install in src make[1]: ディレクトリ '/root/gatena-0.1.0/src' に入ります make[2]: ディレクトリ '/root/gatena-0.1.0/src' に入ります test -z "/usr/local/bin" || /bin/mkdir -p "/usr/local/bin" /usr/bin/install -c gatena '/usr/local/bin' make[2]: 'install-data-am' に対して行うべき事はありません. make[2]: ディレクトリ '/root/gatena-0.1.0/src' から出ます make[1]: ディレクトリ '/root/gatena-0.1.0/src' から出ます Making install in zip make[1]: ディレクトリ '/root/gatena-0.1.0/zip' に入ります make[2]: ディレクトリ '/root/gatena-0.1.0/zip' に入ります make[2]: 'install-exec-am' に対して行うべき事はありません. test -z "/usr/local/share/gatena" || /bin/mkdir -p "/usr/local/share/gatena" /usr/bin/install -c -m 644 zip.bin '/usr/local/share/gatena' make[2]: ディレクトリ '/root/gatena-0.1.0/zip' から出ます make[1]: ディレクトリ '/root/gatena-0.1.0/zip' から出ます Making install in po make[1]: ディレクトリ '/root/gatena-0.1.0/po' に入ります for file in ja.mo ; do \ LANG=`basename $file .mo`; \ dir=/usr/local/share/locale/$LANG/LC_MESSAGES; \ cp $file gatena.mo; \ install -d $dir; \ install -m 0644 gatena.mo $dir; \ rm gatena.mo; \ done; make[1]: ディレクトリ '/root/gatena-0.1.0/po' から出ます Making install in desktop make[1]: ディレクトリ '/root/gatena-0.1.0/desktop' に入ります make[2]: ディレクトリ '/root/gatena-0.1.0/desktop' に入ります make[2]: 'install-exec-am' に対して行うべき事はありません. test -z "/usr/local/share/applications" || /bin/mkdir -p "/usr/local/share/applications" /usr/bin/install -c -m 644 gatena.desktop '/usr/local/share/applications' test -z "/usr/local/share/pixmaps" || /bin/mkdir -p "/usr/local/share/pixmaps" /usr/bin/install -c -m 644 application-x-gatena.png '/usr/local/share/pixmaps' make[2]: ディレクトリ '/root/gatena-0.1.0/desktop' から出ます make[1]: ディレクトリ '/root/gatena-0.1.0/desktop' から出ます Making install in debian make[1]: ディレクトリ '/root/gatena-0.1.0/debian' に入ります make[2]: ディレクトリ '/root/gatena-0.1.0/debian' に入ります make[2]: 'install-exec-am' に対して行うべき事はありません. make[2]: 'install-data-am' に対して行うべき事はありません. make[2]: ディレクトリ '/root/gatena-0.1.0/debian' から出ます make[1]: ディレクトリ '/root/gatena-0.1.0/debian' から出ます make[1]: ディレクトリ '/root/gatena-0.1.0' に入ります make[2]: ディレクトリ '/root/gatena-0.1.0' に入ります make[2]: 'install-exec-am' に対して行うべき事はありません. make[2]: 'install-data-am' に対して行うべき事はありません. make[2]: ディレクトリ '/root/gatena-0.1.0' から出ます make[1]: ディレクトリ '/root/gatena-0.1.0' から出ます
ん?make installされたのかな?whichでgatenaを探してみる。
# which gatena /usr/local/bin/gatena
おお!コンパイルできたんじゃない?では実行!
# gatena
やった動いた!!
いやー無事にgatenaが動作してちょっと感動。gatenaの操作手順などは次回またご紹介できればと思います。