summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xportage-update.sh80
1 files changed, 80 insertions, 0 deletions
diff --git a/portage-update.sh b/portage-update.sh
new file mode 100755
index 0000000..307c1c5
--- /dev/null
+++ b/portage-update.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+
+# Luke's all singing, all dancing, Gentoo Portage @world update script
+
+
+# ====== EDIT VARIABLES BELOW HERE ======
+
+# Portage temporary directory to be passed to "rm -rf", if you would like it cleared afterwards (e.g. "/tmp/portage/*")
+PORTAGE_TEMP="/tmp/portage/*"
+
+# Services that are safe to restart if they have deleted files open (e.g. "apache2 sshd vixie-cron")
+SAFE_SERVICES="apache2 cupsd lvmetad ntpd proftpd smartd sshd tor syslog-ng vixie-cron webmin"
+
+# ====== EDIT VARIABLES ABOVE HERE ======
+
+
+# Handle arguments
+while test $# -gt 0
+do
+ case "$1" in
+ --skip-update) export SKIP_UPDATE="true" # In case we don't want to do the actual "emerge --update"
+ ;;
+ --*) echo "bad argument '$1'" ; exit 1
+ ;;
+ *) echo "unexpected argument '$1'" ; exit 1
+ ;;
+ esac
+ shift
+done
+
+# Sync the Portage tree
+echo 'emerge --sync'
+emerge --sync || exit 1
+
+# Do a @world update, unless skipped
+if [ -z ${SKIP_UPDATE+x} ]; then
+ echo 'emerge --keep-going -av --update --newuse --deep --with-bdeps=y @world'
+ emerge --keep-going -av --update --newuse --deep --with-bdeps=y @world || exit 1
+fi
+
+# Remove unnecessary dependencies
+echo 'emerge -av --depclean'
+emerge -av --depclean || exit 1
+
+# Rebuild any packages known to be built against old/missing packages
+echo 'emerge -av --keep-going @preserved-rebuild'
+emerge -av --keep-going @preserved-rebuild || exit 1
+
+# Search for any remaining packages built against old/missing packages
+echo 'revdep-rebuild -p'
+revdep-rebuild -- -av || exit 1
+
+# Restart any defined safe-to-restart services that have open but deleted files
+DELETED=$(lsof -n | grep "DEL\|deleted")
+for service in ${SAFE_SERVICES[@]}; do
+ echo "$DELETED" | grep -Eq "^$service\s+[0-9]"
+ echo "/etc/init.d/$service restart"
+ /etc/init.d/"$service" restart || exit 1
+done
+
+# Print any remaining processes that have open but deleted files
+echo 'lsof -n | grep "DEL\|deleted" | less'
+echo "$(echo -e 'These things might need manually restarting afterwards due to having open files:\n' && lsof -n | grep DEL)" | less || exit 1
+
+# Clean up /etc/portage/package.*
+echo 'portpeek -arq'
+portpeek -arq || exit 1
+
+# Remove distfiles not owned by any installed package
+echo 'eclean-dist --destructive'
+eclean-dist --destructive || exit 1
+
+# Clear Portage's temporary directory, as defined above
+echo 'rm -r '"$PORTAGE_TEMP"
+#rm -r "$PORTAGE_TEMP" || exit 1
+echo "Would do rm -rf $PORTAGE_TEMP here, do not have the balls yet due to rm -rfing a variable" || exit 1
+
+# Print disk space
+echo 'df -H'
+df -H || exit 1