Last active
August 29, 2015 14:01
-
-
Save yoshinari-nomura/bb9a197e0e01ad81c883 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
CMD_NAME=`basename $0` | |
OLD_MHC_TOP_DIR="${1%/}" # remove trailing slash | |
NEW_MHC_TOP_DIR="${2%/}" # remove trailing slash | |
LOG_FILE="$NEW_MHC_TOP_DIR/$CMD_NAME$$.log" | |
usage() { | |
echo "Usage: $CMD_NAME <top-dir> <new-top-dir>" | |
echo " $CMD_NAME copies old mhc files from <top-dir> into" | |
echo " <new-top-dir> migrating to the new format." | |
echo " New format is:" | |
echo " + X-SC-Record-Id is now in UUID style." | |
echo " + Each filename is in the form of {UUID}.mhc, not [0-9]+." | |
echo " + UUID in X-SC-Record-Id is same as its file's base name." | |
echo " + All articles are flatly placed in TOP/spool/ directory." | |
} >&2 | |
################################################################ | |
## sanity checks | |
if [ $# -ne 2 ]; then | |
usage | |
exit 1 | |
fi | |
if [ ! -d "$OLD_MHC_TOP_DIR" ]; then | |
echo "Error: $OLD_MHC_TOP_DIR does not exist." >&2 | |
usage | |
exit 1 | |
fi | |
printf "Converting... logfile will be in $LOG_FILE\n" >&2 | |
for file in $(find "$OLD_MHC_TOP_DIR" -type f -name '*[0-9]' | grep -v trash) | |
do | |
UUID=`uuidgen` | |
newdir="$NEW_MHC_TOP_DIR/spool" | |
newpath="$newdir/$UUID.mhc" | |
printf "$file -> $newpath\n" | |
if [ ! -d "$newdir" ]; then | |
mkdir -p "$newdir" | |
fi | |
LANG=C sed "s/^X-SC-Record-Id:.*/X-SC-Record-Id: $UUID/" "$file" > "$newpath" | |
done > "$LOG_FILE" 2>&1 | |
exit 0 | |
# Copyright (C) 2015 MHC developing team. All rights reserved. | |
# | |
# Redistribution and use in source and binary forms, with or without | |
# modification, are permitted provided that the following conditions | |
# are met: | |
# | |
# 1. Redistributions of source code must retain the above copyright | |
# notice, this list of conditions and the following disclaimer. | |
# 2. Redistributions in binary form must reproduce the above copyright | |
# notice, this list of conditions and the following disclaimer in the | |
# documentation and/or other materials provided with the distribution. | |
# 3. Neither the name of the team nor the names of its contributors | |
# may be used to endorse or promote products derived from this software | |
# without specific prior written permission. | |
# | |
# THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' | |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | |
# THE TEAM OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
# OF THE POSSIBILITY OF SUCH DAMAGE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@tats san, I've added the mention about the license.
Sorry for missing your comment.