Skip to content

Instantly share code, notes, and snippets.

@st63jun
Created November 5, 2017 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save st63jun/7ebee5b73a6b043fc85386c064d7e9c4 to your computer and use it in GitHub Desktop.
Save st63jun/7ebee5b73a6b043fc85386c064d7e9c4 to your computer and use it in GitHub Desktop.
Windows でも文字化けせずに開ける Zip ファイルを作るスクリプト
#!/bin/bash
#
# Windows でも文字化けせずに開ける Zip ファイルを作るスクリプト。
# convmv(1) と zip(1) と pwqgen(1) が必要です。
#
# SYNOPSIS
#
# $ # 普通のZipファイルを作る
# $ winzip foo.txt
# Ready! I converted 0 files in 0 seconds.
# adding: stepcounter (deflated 14%)
#
# ファイル名: stepcounter.zip
#
# $ # 暗号化したZipファイルを作る
# $ winzip -e foo.txt
# Ready! I converted 0 files in 0 seconds.
# adding: stepcounter (deflated 14%)
#
# ファイル名: 20171105122622-encrypt.zip
# パスワード: negate7Chilly9italy
#
usage() {
echo "Usage: $0 [-e] paths..."
exit 1
}
while getopts eh OPT
do
case $OPT in
e) encryption=1
;;
h) usage
;;
\?) usage
;;
esac
done
shift $((OPTIND - 1))
if [ ! $1 ]; then
usage
fi
if [ $encryption ]; then
out=$(date +%Y%m%d%H%M%S)-encrypt.zip
else
out=$(basename $1).zip
fi
tempdir=$(mktemp -d)
IFS="
"
for file in $@; do
cp -Rp "$file" $tempdir
convmv -r -f utf8 -t sjis --notest --qto --qfrom "$tempdir/$(basename $file)" 2>&1 > /dev/null
done
if [ $encryption ]; then
pass=$(pwqgen)
zip -r -j -e -P$pass $out $tempdir
else
zip -r -j $out $tempdir
fi
if [ -f $out ]; then
echo
echo ファイル名: $out
if [ $encryption ]; then
echo パスワード: $pass
fi
else
echo 'なんかエラーになったっぽい。'
fi
rm -rf $tempdir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment