Help Linux - до свидания! См. Новости проекта

You are here: start » en » kb » make-ubuntu-safe


|

Дополнительно

 Creative Commons

Remove unsafe packages from Ubuntu LiveCD

This is an old way, please consider the new and better one instead: http://www.helplinux.ru/wiki/en:kb:make-ubuntu-privacy-friendly

make-ubuntu-safe.sh

make-ubuntu-safe.sh
#!/bin/bash -e
 
# packages that have to be purged
PACKAGES="unity-lens-shopping unity-scope-video-remote unity-scope-musicstores"
 
[[ $# -ge 1 ]] || { echo "Usage: $0 filename.iso [ temp_dir_path ]"; exit 0; }
 
# ISO file path
ISOFILE=$1				# Ubuntu LiveCD version
[[ -n $2 ]] && TMPDIR=$2 || TMPDIR=/tmp
 
# create temporary directories
EXT4IMG=$(mktemp -p $TMPDIR)		# Image file
EXT4MNT=$(mktemp -d)			# Mounting point for building
ISOMNT=$(mktemp -d)			# Mounting point for ISO image
 
# set ISO paths
ISOFILE=$(readlink -e "$ISOFILE")
ISOFILENEW="$(isoinfo -d -i $ISOFILE | grep -i '^volume id:' | sed -r 's/^volume id:\s+//i') safe"
 
# clean up on stop
trap "exit 1" INT
trap "echo 'Clean up ...'; umount $ISOMNT || true; umount $EXT4MNT || true; rmdir $ISOMNT; rm $EXT4IMG; rmdir $EXT4MNT; exit 0" EXIT
 
# install required tools
apt-get install squashfs-tools rsync genisoimage xorriso
 
# create ext4 image file and mount
truncate -s 5G $EXT4IMG
mkfs.ext4 -F $EXT4IMG
mount $EXT4IMG $EXT4MNT -o loop
 
# create temporary directories inside ext4 image
ISODATADIR=$EXT4MNT/isodata; mkdir $ISODATADIR
SQUASHFSDIR=$EXT4MNT/squashfs
 
# mount livecd
mount -o loop,ro "$ISOFILE" $ISOMNT
 
# extract squashfs
rsync --exclude=/casper/filesystem.squashfs -a $ISOMNT/ $ISODATADIR
unsquashfs -d $SQUASHFSDIR $ISOMNT/casper/filesystem.squashfs
 
# purge unsafe packages
chroot $SQUASHFSDIR dpkg -P $PACKAGES
 
# remove unsafe packages from manifest
for pkg in $PACKAGES; do 
	sed -i "/^$pkg\s/d" $ISODATADIR/casper/filesystem.manifest
done
 
# compress filesystem
mksquashfs $SQUASHFSDIR $ISODATADIR/casper/filesystem.squashfs
 
# remove old md5sum.txt and calculate new md5 sums
pushd $ISODATADIR
find -type f | grep -vE '(\./isolinux/|\./md5sum.txt)' | xargs -l md5sum | tee md5sum.txt
popd
 
# build iso
xorrisofs -D -r -V "$ISOFILENEW" -J -l -b \
	isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot \
	-boot-load-size 4 -boot-info-table -o \
	"${ISOFILE%.iso}-safe.iso" $ISODATADIR

Download Ubuntu safe ISO (ready to use)