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

You are here: start » en » kb » make-ubuntu-privacy-friendly


|

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

 Creative Commons

Rebuild Ubuntu LiveCD with online search results disabled by default

make-ubuntu-privacy-friendly.sh

make-ubuntu-privacy-friendly.sh
#!/bin/bash -e
 
[[ $# -ge 1 ]] || { echo "Usage: $0 filename.iso \"package1.deb [ package2.deb ]\" [ temp_dir_path ]"; exit 0; }
 
# packages that have to be installed
PACKAGES="$2"
 
# ISO file path
ISOFILE=$1				# Ubuntu LiveCD version
 
# set temporary directory
[[ -n $3 ]] && TMPDIR=$3 || 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="${ISOFILE%.iso}-privacy-friendly.iso"
ISOVOLUMEID="$(isoinfo -d -i $ISOFILE | grep -i '^volume id:' | sed -r 's/^volume id:\s+//i') pf"
 
# 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
 
# install packages
PKGDIR=$SQUASHFSDIR/tmp/packages
mkdir $PKGDIR
cp $PACKAGES $PKGDIR
echo 'dpkg -i /tmp/packages/*.deb' | chroot $SQUASHFSDIR
rm -r $PKGDIR
 
# add packages to manifest
for pkg in $PACKAGES; do 
	dpkg -I $pkg | awk '/Package:/ {package=$2} /Version:/ {version=$2} END {print package"\t"version}' >> \
		$ISODATADIR/casper/filesystem.manifest
done
 
# update filesystem.size
du -sx --block-size=1 $SQUASHFSDIR | cut -f1 > $ISODATADIR/casper/filesystem.size
 
# 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 "$ISOVOLUMEID" -J -l -b \
	isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot \
	-boot-load-size 4 -boot-info-table -o \
	"$ISOFILENEW" $ISODATADIR
 
# postprocess image for hybrid mode
isohybrid $ISOFILENEW

Download Ubuntu privacy friendly ISO (ready to use)