Skip to content

Instantly share code, notes, and snippets.

@edwinschaap
Created February 16, 2011 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwinschaap/830064 to your computer and use it in GitHub Desktop.
Save edwinschaap/830064 to your computer and use it in GitHub Desktop.
This scripts cleans up some mess from the default Ubuntu 10.10 (32bits)installation done by prefiber. Can be used on debian (not tested).
#!/bin/bash
function print_info {
echo -n -e '\e[1;36m'
echo -n $1
echo -e '\e[0m'
}
function print_warn {
echo -n -e '\e[1;33m'
echo -n $1
echo -e '\e[0m'
}
function check_sanity {
# Do some sanity checking.
if [ $(/usr/bin/id -u) != "0" ]
then
die 'Must be run by root user'
fi
if [ ! -f /etc/debian_version ]
then
die "Distribution is not supported"
fi
}
function check_remove {
if [ -n "`which "$1" 2>/dev/null`" ]
then
DEBIAN_FRONTEND=noninteractive apt-get -q -y remove --purge "$2"
print_info "$2 removed"
else
print_warn "$2 is not installed"
fi
}
function install_dropbear {
if [ ! -f /usr/sbin/dropbear ]
then
apt-get -y install dropbear
fi
# Disable SSH
touch /etc/ssh/sshd_not_to_be_run
invoke-rc.d ssh stop
# Enable dropbear to start. If xinetd exists, we will use that instead.
if [ -f /usr/sbin/xinetd ]
then
cat >> /etc/xinetd.d/dropbear <<END
service ssh
{
socket_type = stream
only_from = 0.0.0.0
wait = no
user = root
protocol = tcp
server = /usr/sbin/dropbear
server_args = -i
disable = no
}
END
invoke-rc.d xinetd restart
else
sed 's/^NO_START=1/NO_START=0/' /etc/default/dropbear > /tmp/db.$$ && \
mv /tmp/db.$$ /etc/default/dropbear
invoke-rc.d dropbear start
fi
}
function install_syslogd {
# We just need a simple vanilla syslogd. Also there is no need to log to
# so many files (waste of fd). Just dump them into
# /var/log/(cron/mail/messages)
if [ ! -f /usr/sbin/syslogd ]
then
apt-get -y install inetutils-syslogd
fi
invoke-rc.d inetutils-syslogd stop
for file in /var/log/*.log /var/log/mail.* /var/log/debug /var/log/syslog
do
[ -f "$file" ] && rm -f "$file"
done
for dir in fsck news
do
[ -d "/var/log/$dir" ] && rm -rf "/var/log/$dir"
done
cat > /etc/syslog.conf <<END
*.*;mail.none;cron.none -/var/log/messages
cron.* -/var/log/cron
mail.* -/var/log/mail
END
[ -d /etc/logrotate.d ] || mkdir -p /etc/logrotate.d
cat > /etc/logrotate.d/inetutils-syslogd <<END
/var/log/cron
/var/log/mail
/var/log/messages {
rotate 4
weekly
missingok
notifempty
compress
postrotate
/etc/init.d/inetutils-syslogd reload >/dev/null
endscript
}
END
invoke-rc.d inetutils-syslogd start
}
function update_upgrade { # Run through the apt-get update/upgrade first. This should be done before
# we try to install any package
apt-get -y update
apt-get -y upgrade
}
function remove_unneeded {
check_remove /sbin/portmap portmap
check_remove /usr/sbin/rsyslogd rsyslog
check_remove /usr/sbin/apache2 'apache2*'
check_remove /usr/sbin/named bind9
check_remove /usr/sbin/smbd 'samba*'
check_remove /usr/sbin/nscd nscd
# Need to stop sendmail as removing the package does not seem to stop it.
if [ -f /usr/lib/sm.bin/smtpd ]
then
invoke-rc.d sendmail stop
check_remove /usr/lib/sm.bin/smtpd 'sendmail*'
fi
}
function remove_apache {
apt-get -y remove --purge apache2*
}
function remove_sendmail {
apt-get -y remove --purge sendmail*
}
function die {
echo "ERROR: $1" > /dev/null 1>&2
exit 1
}
#################
# start program #
#################
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
check_sanity
remove_unneeded
update_upgrade
install_syslogd
install_dropbear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment