[Motorola Droid 4] daniel_m:
For those who, like me, customise their ROM and are sick of uninstalling/freezing apps and re-installing system apps or scripts after updating to a new nightly, here is a nice automatic script (found in this XDA thread and modified).

This is my personal setup, so don't use it without modifying it to suit your needs! It will remove Trebuchet launcher and the Google keyboard (among other apps), leaving you with nothing, if you don't have any alternatives installed!.

Copy the following code into a text file (named e.g. "91-mycustomisation.sh", make sure the file ending is ".sh"), customise which files to keep and which to delete and copy it to "\system\addon.d\".

#!/sbin/sh
#
# /system/addon.d/91-jebb.sh
# During a CM11 upgrade, this script backs up files in /system,
# /system is formatted and reinstalled, then the file is restored.
#

. /tmp/backuptool.functions

list_files() {
cat <<EOF

#Custom system apps
priv-app/org.jtb.alogrec.apk
priv-app/com.asksven.betterbatterystats_xdaedition.apk

#AFWall+ start-up script
etc/init.d/afwallstart

#Google Play store
priv-app/GoogleLoginService.apk
priv-app/GoogleServicesFramework.apk
priv-app/Phonesky.apk

#Google contacts (necessary to display advanced fields in People app)
app/GoogleContactsSyncAdapter.apk

#Custom ring tones
#media/audio/ringtones/PumpedUpKicksQ4.ogg
#media/audio/ringtones/SystemShockElevatorQ4.ogg

#Maps api for Tasker
etc/permissions/com.google.android.maps.xml
framework/com.google.android.maps.jar

EOF
}

case "$1" in
backup)
list_files | while read FILE DUMMY; do
backup_file $S/"$FILE"
done
;;
restore)
list_files | while read FILE REPLACEMENT; do
R=""
[ -n "$REPLACEMENT" ] && R="$S/$REPLACEMENT"
[ -f "$C/$S/$FILE" ] && restore_file $S/"$FILE" "$R"
done
rm -f /system/media/audio/ui/camera_click.ogg
rm -f /system/media/audio/ui/camera_focus.ogg
rm -f /system/media/audio/ui/Lock.ogg
rm -f /system/media/audio/ui/LowBattery.ogg
rm -f /system/media/audio/ui/Unlock.ogg
rm -f /system/media/audio/ui/VideoRecord.ogg
rm -f /system/media/audio/ui/VideoStop.ogg
rm -f /system/media/video/AndroidInSpace.240p.mp4
rm -f /system/media/video/AndroidInSpace.480p.mp4
rm -f /system/media/video/Sunset.240p.mp4
rm -f /system/media/video/Sunset.480p.mp4
rm -f /system/app/Apollo.apk
rm -f /system/app/appdirectedsmspermission.apk
rm -f /system/app/BasicDreams.apk
rm -f /system/app/Browser.apk
rm -f /system/app/Calculator.apk
rm -f /system/app/Calendar.apk
# replaced by Google calendar app from Play store due to interoperability with aCalendar
rm -f /system/app/Camera2.apk
rm -f /system/app/CellBroadcastReceiver.apk
rm -f /system/priv-app/CMAccount.apk
rm -f /system/app/CMFileManager.apk
rm -f /system/app/CMHome.apk
rm -f /system/priv-app/CMUpdater.apk
rm -f /system/app/CMWallpapers.apk
rm -f /system/app/Email.apk
rm -f /system/app/Exchange2.apk
rm -f /system/app/Gallery2.apk
rm -f /system/app/Galaxy4.apk
rm -f /system/app/HoloSpiralWallpaper.apk
rm -f /system/app/LatinIME.apk
rm -f /system/app/LiveWallpapers.apk
rm -f /system/app/LiveWallpapersPicker.apk
rm -f /system/app/LockClock.apk
rm -f /system/app/MagicSmokeWallpapers.apk
rm -f /system/app/NoiseField.apk
rm -f /system/priv-app/OneTimeInitializer.apk
rm -f /system/app/PhaseBeam.apk
rm -f /system/app/PhotoPhase.apk
rm -f /system/app/PhotoTable.apk
rm -f /system/app/PrintSpooler.apk
rm -f /system/app/Provision.apk
rm -f /system/app/QuickSearchBox.apk
rm -f /system/priv-app/ThemeChooser.apk
# rm -f /system/priv-app/ThemesProvider.apk (needed to change wallpaper)
rm -f /system/priv-app/Trebuchet.apk
rm -f /system/app/VerizonSSOEngine.apk
rm -f /system/app/VideoEditor.apk
rm -f /system/app/VisualizationWallpapers.apk
rm -f /system/priv-app/VoiceDialer.apk
rm -f /system/app/VoicePlus.apk
rm -f /system/app/VZWAPNLib.apk
rm -f /system/app/vzwapnpermission.apk
rm -f /system/app/VZWAPNService.apk
rm -f /system/app/WAPPushManager.apk
;;
pre-backup)
# Stub
;;
post-backup)
# Stub
;;
pre-restore)
# Stub
;;
post-restore)
# Stub
;;
esac

The script uses "\system\" as basic directory, which means you can only backup or delete files within "\system\". When updating your ROM, "\system\" will be formatted, but the scripts in "\system\addon.d\" will be kept and they will be executed before/after you update your ROM.

The topmost part between

list_files() {
cat <<EOF

and

EOF
}

will backup whatever is listed there. Since I don't have GApps on my Droid, I copied the Play store and the Google services manually into the system directory and therefore need to backup these files to keep them after a ROM update. Use these files as an example of how the keep your things together after an update.

The lines starting with

done
rm -f /system/ ....

will delete files. Use these to remove bloat-ware from CM, like media files and unnecessary apps. The apps in my list are a personal preference and not "wisdom’s last conclusion"! There are many services that I don't use and many apps that I substituted with better versions from the Play store or (preferably) F-Droid. If you search for any of these system apps, you will likely encounter lists of system apps and what they actually do (also here on XDA).

If, for some reason, you break something and get a boot-loop after updating your ROM, delete the script from within TWRP and install the ROM update again (or transfer the script to your PC to find out what could have caused the boot-loop). A very good tool to fix things with TWRP is the AROMA File Manager. Remember that you can transfer files from your PC to your Droid easily with adb or USB in TWRP and that you can copy/move/delete anything and change file permissions with AROMA File Manager. Also keep in mind that you can quickly backup and restore the system partition with TWRP. This is basic knowledge, but it is very useful to get used to these tools in case of boot-loops and it can help to get your ROM to boot again without the need to re-install everything.

Whenever you mess around with files/apps yourself, remember to set the right permissions afterwards! Use a good file explorer with root functionality like Simple Explorer or FS File Explorer to copy/move files and edit permissions.

It might be labour-intensive to get the script running and to get it to do what you wish, but after that you can install as many nightlies as you want without having to think about "cleaning up" afterwards.

For those who use the XPosed framework, there is another addon.d script that will enable XPosed automatically after an update of your ROM. I have been using Fiouz' script for a while now and it never failed on me once (I never tried rovo89's script that Fiouz quoted in his/her post). This script will save you booting your ROM, enabling XPosed and rebooting again. It is especially useful if you use XPrivacy and don't want your Droid to be unprotected after an update of your ROM.