mac_uu2linux

Suite à mon billet d'hier (1) voici un script qui permet facilement d'avoir son fichier utilisable sous linux d'un fichier UU prevenant de macOs. Pour identifier ce genre de fichier :

$ file lettre\ associations.rtf
lettre associations.rtf: uuencoded or xxencoded text

Voici le contenu du script mac_uu2linux

#!/bin/bash

# usage
[ ! "$#" = "2" ] && echo "USAGE: `basename $0` SOURCE DEST" && exit 1

# test uudecode
if [ ! "`type uudecode 2> /dev/null`" ]
then
        echo "ERROR: `basename $0` needs uudecode from gnu package sharutils \
        (http://www.gnu.org/software/sharutils/sharutils.html)."
        exit 1
fi

# source file
F_OR="$1"
[ ! -e "$F_OR" ] && echo "ERROR: $F_OR: No such file or directory" && exit 1

# destination file
F_DS="$2"
[ -e "$F_DS" ] && echo "ERROR: $F_DS already exists" && exit 1

# temporary file
F_TMP="/tmp/`basename $1`.`date +%s`"
[ -e "$F_TMP" ] && echo "ERROR: $F_TMP already exists" && exit 1

# copy source file, add ^M in last lien and decode file to destination file
cp "$F_OR" "$F_TMP" && echo "" >> "$F_TMP" && uudecode -o "$F_DS" "$F_TMP"

#remove temporary file and exit
rm "$F_TMP"
exit 0
  1. http://www.gnunux.info/dotclear/index.php?2006/03/30/148-lire-un-document-compresse-depuis-macos-9

Haut de page