#!/usr/bin/bash

# 5% speed boost on application load.

## Revert everything:
# prelink --all --undo

apt install -y prelink

## File list
# /etc/cron.daily/prelink
# /etc/default/prelink
# /etc/prelink.conf
# /usr/sbin/prelink
# /usr/sbin/prelink.bin
# /usr/share/doc/prelink/README.Debian
# /usr/share/doc/prelink/TODO
# /usr/share/doc/prelink/changelog.Debian.amd64.gz
# /usr/share/doc/prelink/changelog.Debian.gz
# /usr/share/doc/prelink/changelog.gz
# /usr/share/doc/prelink/copyright
# /usr/share/doc/prelink/prelink.pdf.gz
# /usr/share/lintian/overrides/prelink
# /usr/share/man/man8/prelink.8.gz
# /usr/share/man/man8/prelink.bin.8.gz


## /etc/default/prelink
# The options explained:
# -a 	"All": prelinks all the binaries
# -m 	Conserve the virtual memory space. This is needed if you have a lot of libraries that need to be prelinked.
# -R 	Random -- randomize the address ordering, this enhances security against buffer overflows.
PRELINKING="unknown"
PRELINK_OPTS="-amR"
PRELINK_FULL_TIME_INTERVAL=14
PRELINK_NONRPM_CHECK_INTERVAL=7

sed -i 's,^\(PRELINKING=\).*,\1'${PRELINKING}',' /etc/default/prelink
sed -i 's,^\(PRELINK_OPTS=\).*,\1'${PRELINK_OPTS}',' /etc/default/prelink
sed -i 's,^\(PRELINK_FULL_TIME_INTERVAL=\).*,\1'${PRELINK_FULL_TIME_INTERVAL}',' /etc/default/prelink
sed -i 's,^\(PRELINK_NONRPM_CHECK_INTERVAL=\).*,\1'${PRELINK_NONRPM_CHECK_INTERVAL}',' /etc/default/prelink

## /etc/prefix.conf
# `-l ', the directory hierarchy will be walked as long as filesystem boundaries are not crossed.
# `-h ', symbolic links in a directory hierarchy are followed.
# `-b ' prefix will be blacklisted.
cat > /etc/prelink.conf <<'EOF'
# This config file contains a list of directories both with binaries
# and libraries prelink should consider by default.
# If a directory name is prefixed with `-l ', the directory hierarchy
# will be walked as long as filesystem boundaries are not crossed.
# If a directory name is prefixed with `-h ', symbolic links in a
# directory hierarchy are followed.
# Directories or files with `-b ' prefix will be blacklisted.
-b *.la
-b *.png
-b *.py
-b *.pl
-b *.pm
-b *.sh
-b *.xml
-b *.xslt
-b *.a
-b *.js
-b /lib/modules
-b /usr/lib/locale
-l /usr/local/sbin
-l /sbin
-l /usr/sbin
-l /usr/local/bin
-l /bin
-l /usr/bin
-l /usr/X11R6/bin
-l /usr/games
-l /usr/local/lib
-l /lib
-l /usr/lib
-l /usr/X11R6/lib
EOF
