Ceci est une ancienne révision du document !


Script de francisation du live CD

En tant que superutilisateur :

./script_francisation.sh -r 11.04 -u http://cdimage.ubuntu.com/cdimage/daily-live/current/ -d /root/projets/traduction_live_cd
wget -q -O /tmp/traduction_live_cd.txt http://doc.ubuntu-fr.org/data/pages/projets/traduction_live_cd/script_francisation.sh.txt ; sed -n '/#!\/bin\/bash/,/<\/code>/p' /tmp/traduction_live_cd.txt | head -n-1 > script_francisation.sh ; wget -q -O /tmp/traduction_live_cd.txt http://doc.ubuntu-fr.org/data/pages/projets/traduction_live_cd/inside_chroot.sh.txt ; sed -n '/#!\/bin\/bash/,/<\/code>/p' /tmp/traduction_live_cd.txt | head -n-1 > inside_chroot.sh ; rm /tmp/traduction_live_cd.txt
#!/bin/bash
 
# Translation script for Ubuntu CDs
# Copyright (C) 2010  Didier ROCHE, Vincent-Xavier JUMEL, Olivier FRAYSSE, Islem ABD-EL RAHMAN
 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
# Be sure to set up the variables according to your needs and preferences
 
# Usage: usage
# Print the usage.
usage () {
    cat <<EOF
 
Usage: `basename $0` [OPTION]
Localize the CD
 
  -d, --directory=WD      working directory (default to /root/projets/traduction_live_cd)
  -a, --arch=ARCH         Architecture (default to i386)
  -r, --release           Ubuntu release number and name (mandatory)
  -D, --debug		  Turn on debuging, by not purging file
  -u, --url		  Change url (if omissed, the script will try to do some auto-detection)
  -h, --help              print this message and exit
  -v, --version           print the version information and exit
 
Report bugs to <bug-grub@gnu.org>.
EOF
}
 
# This function should be called on error to unmount filesystems
exit_on_error () {
  for i in `grep $1 /proc/mounts | awk '{print $2}' | sort -r` 
  do umount $i ; sleep 2 
  done
  echo "Something went wrong, unmounting filesystems in working directory ..." >&2
  exit 1
}
 
V_NUM=10.10
ARCH=i386 # Architecture
WD=/root/projets/traduction_live_cd # our working directory, should not interfere with anything you have
debug=0 # Setting the debug value
 
# Note that we use `"$@"' to let each command-line parameter expand to a 
# separate word. The quotes around `$@' are essential!
# We need TEMP as the `eval set --' would nuke the return value of getopt.
TEMP=`getopt -o d:a:r:u:hD --long directory:,arch:,release:,help,debug,url: -n 'script_francistation.sh' -- "$@"`
 
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
 
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
 
while true ; do
  case "$1" in
    -d|--directory) WD=$2 ; shift 2;;
    -a|--arch) ARCH=$2 ; shift 2 ;;
    -r|--release) V_NUM=$2 ; shift 2 ;; 
    -D|--debug) debug="1" ; shift 1 ;;
    -u|--url) DL_URL=$2; shift 2 ;;
    --) shift ; break ;;
    *) usage ; exit 0 ;;
  esac
done
 
if [ $ARCH != i386 -a $ARCH != amd64 ]; then
  echo "Arch not recognized or supported" >&2
  exit 1
fi
 
# This will create final working directory, even if the full path don't exists.
for i in mnt extract-cd edit tmp ; do 
  if [ ! -d ${WD}/${i} ]; then 
    mkdir -p ${WD}/${i} ; 
  else
    rm -rf ${WD}/${i}/*
  fi
done
 
# http://paste.ubuntu.com/419825/
 
FLAVOR="desktop"
 
V_NUM_B=$V_NUM
LTS=""
if [ $V_NUM == "10.04" ]; then
  V_NUM_B="10.04.1"
  V_NAME="lucid"
  LTS=" LTS"
elif [ $V_NUM == "10.10" ]; then
  V_NAME="maverick"
elif [ $V_NUM == "11.04" ]; then
  V_NAME="natty"
else 
  echo "Wrong version number" >&2 
  exit 1
fi
 
VERSION=$V_NAME
 
ISOPATH=$(echo $DL_URL | sed s,http://,,)
 
if [[ -z "$ISOPATH" ]]; then
  if [[ "$FLAVOR" = "desktop" ]]; then
    ISOPATH="cdimage.ubuntu.com/cdimage/daily-live/current"
  elif [[ "$FLAVOR" = "alternate" ]]; then
    ISOPATH="cdimage.ubuntu.com/cdimage/daily/current"
  elif [[ "$FLAVOR" = "dvd" ]]; then
    ISOPATH="cdimage.ubuntu.com/cdimage/dvd/current"
  elif [[ "$FLAVOR" = "netbook" ]]; then
    ISOPATH="cdimage.ubuntu.com/cdimage/ubuntu-netbook/daily-live/current"
  elif [[ "$FLAVOR" = "server" ]]; then
    ISOPATH="cdimage.ubuntu.com/cdimage/ubuntu-server/daily/current"
  else
    echo "Unrecognized distribution, set ISOPATH manually"
    exit 1
  fi
fi
ISO=$VERSION-$FLAVOR-$ARCH.iso
 
# Save the original location
ORIG_DIR=$PWD
 
cd $WD
 
# create identical formatted md5sum file from local copy
if [[ -f $ISO ]]; then
  md5sum $ISO | sed -e "s/  / */" > $ISO.md5.local 
fi
 
wget -q http://$ISOPATH/MD5SUMS
grep $ISO MD5SUMS > $ISO.md5.server
rm MD5SUMS
diff -q $ISO.md5.local $ISO.md5.server
 
if [ ! $? -eq "0" ]; then
  echo "Performing rsync in $WD"
  rsync -avzhhP rsync://$ISOPATH/$ISO .
  if [ ! $? -eq "0" ]; then
    echo "Nothing have been downloaded :-(" >&2
    exit 1
  fi
else
  echo "no need to refresh"
fi
md5sum $ISO | sed -e "s/  / */" > $ISO.md5.local
diff -q $ISO.md5.local $ISO.md5.server
 
if [ ! $? -eq "0" ]; then
  echo "rsync failed"
  exit 1
else
  echo "success"
fi
 
 
# Going into working directory
cd ${WD}
mount -o loop ${WD}/${V_NAME}-desktop-${ARCH}.iso ${WD}/mnt
rsync --exclude=/casper/filesystem.squashfs -av ${WD}/mnt/ ${WD}/extract-cd
 
unsquashfs -d ${WD}/edit/. -f ${WD}/mnt/casper/filesystem.squashfs
umount mnt
 
# Just replace archives by French ones
 
sed -i 's/archive/fr.archive/' ${WD}/edit/etc/apt/sources.list 
 
# We just uncomment universe and multiverse for special package. They
# will be commented out by the end of the installation dans /var/lib/apt
# will be purged to gain space.
 
sed -i -r -e 's/# (deb .* .*iverse)/\1/' ${WD}/edit/etc/apt/sources.list
 
# Preparing and entering the chroot environment
cp /etc/resolv.conf ${WD}/edit/etc/
cp /etc/hosts ${WD}/edit/etc/
mount --bind /dev/ ${WD}/edit/dev
mount -t proc none ${WD}/edit/proc
mount -t sysfs none ${WD}/edit/sys
mount -t devpts none ${WD}/edit/dev/pts
 
cp $ORIG_DIR/inside_chroot.sh ${WD}/edit/root/fr.sh
 
chroot ${WD}/edit /bin/bash /root/fr.sh $V_NUM $V_NAME $ARCH
 
if [ ! $? -eq "0" ] ; then
  exit_on_error $WD
else
  umount ${WD}/edit/proc
  umount ${WD}/edit/sys
  umount ${WD}/edit/dev/pts
  umount ${WD}/edit/dev
fi
 
# Getting out the chroot environment
mv -f ${WD}/edit/initrd.lz ${WD}/extract-cd/casper/
 
# Updating the autorun.inf
sed -i 's/Install Ubuntu/Installer Ubuntu/' ${WD}/extract-cd/autorun.inf
 
# Correction d'un BUG de traduction dans la 10.04.1 et 10.10
sed -i "s/Installer RELEASE/Installer Ubuntu ${V_NUM_B}${LTS}/g" ${WD}/edit/usr/share/applications/desktop.*.cache # desktop.fr_FR.utf8.cache desktop.C.cache
sed -i "s/Installer RELEASE/Installer Ubuntu ${V_NUM_B}${LTS}/g" ${WD}/edit/usr/share/applications/ubiquity-gtkui.desktop
 
# Dealing with gfxboot 
chmod -R u+w ${WD}/extract-cd/
echo fr > ${WD}/extract-cd/isolinux/lang
echo fr > ${WD}/extract-cd/isolinux/langlist
cp ${WD}/extract-cd/isolinux/fr.* ${WD}/tmp/
rm ${WD}/extract-cd/isolinux/*.hlp ${WD}/extract-cd/isolinux/*.tr
mv ${WD}/tmp/fr.* ${WD}/extract-cd/isolinux/
chmod u-w ${WD}/extract-cd/isolinux ${WD}/extract-cd/isolinux/lang ${WD}/extract-cd/isolinux/langlist
 
# Login in french keyboard and french language (for livecd, or for user "ubuntu" if installed with this user)
mkdir ${WD}/var/cache/gdm/ubuntu
echo "[Desktop]" >  ${WD}/var/cache/gdm/ubuntu/dmrc
echo "Language=fr_FR.UTF-8" >>  ${WD}/var/cache/gdm/ubuntu/dmrc
echo "Layout=fr" >>  ${WD}/var/cache/gdm/ubuntu/dmrc
 
sed -i "
s/\^Try Ubuntu without installing/^Essayer Ubuntu sans l\'installer/;
s/\^Install Ubuntu/^Installer Ubuntu/;
s/\^Check disc for defects/^Vérifier le disque/;
s/Test ^memory/Vérifier la ^mémoire/;
s/\^Boot from first hard disk/^Démarrer sur le premier disque/
" ${WD}/extract-cd/isolinux/txt.cfg
 
# Creating CD manifest
 
chmod +w ${WD}/extract-cd/casper/filesystem.manifest
chroot ${WD}/edit dpkg-query -W --showformat='${Package} ${Version}\n' > ${WD}/extract-cd/casper/filesystem.manifest
cp ${WD}/extract-cd/casper/filesystem.manifest ${WD}/extract-cd/casper/filesystem.manifest-desktop
 
echo -e "Calcule la taille du dossier chroot pour le fichier filesystem.size..."
printf $(du -sx --block-size=1 ${WD}/edit | cut -f1) > ${WD}/extract-cd/casper/filesystem.size
if [[ ! -e "${WD}"/extract-cd/casper/filesystem.size || -z `cat ${WD}/extract-cd/casper/filesystem.size` ]]; then
  echo "can't generate the filesystem.size file, exit..." >&2
  exit 0
fi
 
sed -i '/casper/d;/cryptsetup/d;/dmraid/d;/ecryptfs-utils/d;/gparted/d;/jfsutils/d;/keyutils/d;/kpartx/d;/libdebconfclient0/d;/libdebian-installer4/d;/libdmraid1.0.0.rc15/d;/libecryptfs0/d;/libntfs10/d;/libreadline5/d;/localechooser-data/d;/lupin-casper/d;/ntfsprogs/d;/python-pyicu/d;/rdate/d;/reiserfsprogs/d;/ubiquity/d;/ubiquity-casper/d;/ubiquity-frontend-gtk/d;/ubiquity-slideshow-ubuntu/d;/ubiquity-ubuntu-artwork/d;/user-setup/d;/xfsprogs/d' ${WD}/extract-cd/casper/filesystem.manifest-desktop
 
# Creating the squashfs
rm -f ${WD}/extract-cd/casper/filesystem.squashfs
mksquashfs ${WD}/edit ${WD}/extract-cd/casper/filesystem.squashfs
 
chmod 777 ${WD}/tmp
rm -f ${WD}/tmp/md5sum.txt
rm ${WD}/extract-cd/md5sum.txt
cd ${WD}/extract-cd && find . -type f -not -name md5sum.txt -not -path '*/isolinux/*' -print0 | xargs -0 -- md5sum > ${WD}/tmp/md5sum.txt
cp ${WD}/tmp/md5sum.txt ${WD}/extract-cd/md5sum.txt
 
cd ${WD}/extract-cd
mkisofs -r -V "Ubuntu ${V_NUM_B} Ed. Francophone" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ../ubuntu-${V_NUM_B}-desktop-${ARCH}-fr.iso .
cd ..
echo "Update the Manifest file"
if [[ -s MANIFESTS ]]; then
  sed -i /ubuntu-${V_NUM_B}-desktop-${ARCH}-fr.iso/d MANIFESTS
fi
echo -e `md5sum ubuntu-${V_NUM_B}-desktop-${ARCH}-fr.iso ` "\n"`sha1sum ubuntu-${V_NUM_B}-desktop-${ARCH}-fr.iso ` "\n"` sha512sum ubuntu-${V_NUM_B}-desktop-${ARCH}-fr.iso` >> MANIFESTS
 
if [ $debug -eq "1" ]; then
  cd ${WD}
  rm -rf ${WD}/mnt ${WD}/extract-cd ${WD}/edit ${WD}/tmp *.img
fi
  • projets/traduction_live_cd/script_francisation.sh.1294090242.txt.gz
  • Dernière modification: Le 03/01/2011, 22:30
  • par ysimonx