unzipで日本語が文字化けする例のアレ(Fedora用のrpmを作ってみた)

Windowsからzipファイルを持ってくるとSJISであるためunzipでは文字化けしてしまう。
散々他のサイトでは書かれていると思うので、ここでは省略。

通常なら、パッチを当ててソースからインストールといきたいのですが
Fedoraは、rpmなディストリなのでソースからあんまりインストールしたくない。
出来ることならパッケージをrpmで管理したい。

というわけで、rpmパッケージを見様見真似で作ってみました。
パッケージの中身はFedoraのSRPMに、さらにiconvパッチを当てただけです。

Fedora 21用 x86_64
unzip-6.0-18j.fc21.x86_64.rpm

SRPM(src.rpm)
unzip-6.0-18j.fc21.src.rpm

インストールは
以下のようにしてください。

$ sudo rpm -Uvh –force unzip-6.0-18j.fc21.x86_64.rpm

これで、インストールできます。
※ yum localinstall でも2015/1/31段階ではできますが今後バージョンエラーが起こるかもしれないです。
※ また、予めインストールされているunzipをremoveしようとしたら依存パッケージが大量にあったので、やはり上記の方法がいいと思います。

追記
yum downgradeでもインストールできるみたいです。
また、fc22からパッケージ管理の標準がyumからdnfになったみたいで、以下のコマンドになりました。

$ sudo dnf install unzip-6.0-18j.fc21.x86_64.rpm 
Last metadata expiration check performed x:xx:xxxx ago on xxx xxx xxxx xxxxxxxxx
Dependencies resolved.
==========================================================================================================================================
 Package                      アーキテクチャ                バージョン                          リポジトリー                         容量
==========================================================================================================================================
ダウングレード中:
 unzip                        x86_64                        6.0-18j.fc21                        @commandline                        173 k

トランザクションの要約
==========================================================================================================================================
ダウングレード  1 Package

合計容量: 173 k
これでいいですか? [y/N]

※SRPMを使う場合は、まず、rpm-buildをインストールしてください。
また、gcc,bzip2-devel等も必要ですので入っていなければインストールしてください。

$ sudo dnf install rpm-build gcc bzip2-devel

次にsrpmをrebuildしてください。

$ rpmbuild --rebuild unzip-6.0-18j.fc21.src.rpm

最後に、できあがったRPMをインストールしてください。
※今回は、x86_64です。

$ cd $HOME/rpmbuild/RPMS/`arch`
$ sudo dnf install unzip-6.0-18j.fc21.x86_64.rpm 

インストールが完了すると、unzipに-O -I オプションが増えています。

$ unzip   
UnZip 6.00 of 20 April 2009, by Info-ZIP.  Maintained by C. Spieler.  Send
bug reports using http://www.info-zip.org/zip-bug.html; see README for details.

Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
  Default action is to extract files in list, except those in xlist, to exdir;
  file[.zip] may be a wildcard.  -Z => ZipInfo mode ("unzip -Z" for usage).

  -p  extract files to pipe, no messages     -l  list files (short format)
  -f  freshen existing files, create none    -t  test compressed archive data
  -u  update files, create if necessary      -z  display archive comment only
  -v  list verbosely/show version info       -T  timestamp archive to latest
  -x  exclude files that follow (in xlist)   -d  extract files into exdir
modifiers:
  -n  never overwrite existing files         -q  quiet mode (-qq => quieter)
  -o  overwrite files WITHOUT prompting      -a  auto-convert any text files
  -j  junk paths (do not make directories)   -aa treat ALL files as text
  -U  use escapes for all non-ASCII Unicode  -UU ignore any Unicode fields
  -C  match filenames case-insensitively     -L  make (some) names lowercase
  -X  restore UID/GID info                   -V  retain VMS version numbers
  -K  keep setuid/setgid/tacky permissions   -M  pipe through "more" pager
  -O CHARSET  specify a character encoding for DOS, Windows and OS/2 archives
  -I CHARSET  specify a character encoding for UNIX and other archives

See "unzip -hh" or unzip.txt for more help.  Examples:
  unzip data1 -x joe   => extract all files except joe from zipfile data1.zip
  unzip -p foo | more  => send contents of foo.zip via pipe into program more
  unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer

基本的には、以下のように使用できます。

$ unzip -O sjis filename

しっかり、文字化けせずに展開されます。

※ もともとのSRPMはここからいただきました。(fc21が見つからなかったのでfc22のものを使用)
http://rpmfind.net//linux/RPM/fedora/devel/rawhide/src/u/unzip-6.0-18.fc22.src.html

このSRPMには最初から以下のパッチが含まれていました。

unzip-6.0-bzip2-configure.patch
unzip-6.0-caseinsensitive.patch
unzip-6.0-close.patch
unzip-6.0-exec-shield.patch
unzip-6.0-fix-recmatch.patch
unzip-6.0-format-secure.patch
unzip-6.0-manpage-fix.patch
unzip-6.0-nostrip.patch
unzip-6.0-overflow.patch
unzip-6.0-symlink.patch
unzip-6.0-valgrind.patch
unzip-6.0-x-option.patch

※ iconvパッチは以下のサイトからいただきました。
https://bugs.archlinux.org/task/15256?getfile=3685

Leave a Reply

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

Related Post