1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
#!/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 -r", if you would like it cleared afterwards (e.g. "/tmp/portage/*")
PORTAGE_TEMP="/var/tmp/portage/*"
# Services that are safe to restart if they have deleted files open (e.g. "apache2 sshd vixie-cron")
SAFE_SERVICES="cupsd fail2ban lvmetad ntpd proftpd smartd sshd tor syslog-ng"
# ====== EDIT VARIABLES ABOVE HERE ======
# Handle arguments
while test $# -gt 0
do
case "$1" in
--skip-sync) export SKIP_SYNC="true" # In case we don't want to sync repositories
;;
--skip-news) export SKIP_NEWS="true" # In case we don't want to read new news before continuing
;;
--skip-update) export SKIP_UPDATE="true" # In case we don't want to do the actual "emerge --update" and update of -9999 packages
;;
--skip-depclean) export SKIP_DEPCLEAN="true" # In case we don't want to do an "emerge --depclean"
;;
--skip-preserved-rebuild) export SKIP_PRESERVED_REBUILD="true" # In case we don't want to do an "emerge @preserved-rebuild"
;;
--skip-etc-update) export SKIP_ETC_UPDATE="true" # In case we don't want to do an "etc-update"
;;
--exclude) # Followed by a list of packages as a single argument to pass to emerge --exclude for @world and -9999 updates, e.g. --exclude "app-editors/nano media-gfx/blender"
export EXCLUDE_LIST="$2"
shift
;;
--*) echo "bad argument '$1'" ; exit 1
;;
*) echo "unexpected argument '$1'" ; exit 1
;;
esac
shift
done
# Sync all repositories configured with auto-sync, unless skipped
if [ -z ${SKIP_SYNC+x} ]; then
echo 'emaint sync --auto'
emaint sync --auto || (echo "$0: error: failed to sync repositories" ; echo exit 1)
fi
# Check to see if there's any news, unless skipped
if [ -z ${SKIP_NEWS+x} ] && [ $(eselect news count new) -ne "0" ]; then
echo "IMPORTANT: at least 1 news item needs reading"
echo "Use eselect news read to view new items"
exit 1
fi
# Do a @world update, unless skipped
if [ -z ${SKIP_UPDATE+x} ]; then
echo "emerge --keep-going -av --update --newuse --deep --with-bdeps=y --exclude \"$EXCLUDE_LIST\" @world"
emerge --keep-going -av --update --newuse --deep --with-bdeps=y --exclude "$EXCLUDE_LIST" @world || exit 1
# Update -9999 packages since they aren't included in a @world update
pkgs9999=$(find /var/db/pkg/ -mindepth 2 -maxdepth 2 -name '*-9999')
if [ "$pkgs9999" != "" ] ; then
echo "emerge -1av $(find /var/db/pkg/ -mindepth 2 -maxdepth 2 -name '*-9999' | tr '\n' ' ' | sed 's|/var/db/pkg/|=|g') --exclude \"$EXCLUDE_LIST\""
emerge -1av $(find /var/db/pkg/ -mindepth 2 -maxdepth 2 -name '*-9999' | tr '\n' ' ' | sed 's|/var/db/pkg/|=|g') --exclude "$EXCLUDE_LIST"
fi
fi
# Remove unnecessary dependencies, unless skipped
if [ -z ${SKIP_DEPCLEAN+x} ]; then
echo 'emerge -av --depclean'
emerge -av --depclean || exit 1
fi
# Rebuild any packages known to be built against old/missing packages, unless skipped
if [ -z ${SKIP_PRESERVED_REBUILD+x} ]; then
echo 'emerge -av --keep-going @preserved-rebuild'
emerge -av --keep-going @preserved-rebuild || exit 1
fi
# 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]"
if [ "$?" -eq 0 ]; then
echo "/etc/init.d/$service restart"
/etc/init.d/"$service" restart || exit 1
fi
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 -r $PORTAGE_TEMP here, do not have the balls yet due to rm -ring a variable" || exit 1
# Run etc-update, unless skipped
if [ -z ${SKIP_ETC_UPDATE+x} ]; then
echo 'etc-update'
etc-update
fi
# Print disk space
echo 'df -H'
df -H || exit 1
# Print an SSH warning
echo -e '\nAll done! If sshd was restarted, now would be a good time to verify you can SSH in to this machine...'
|