#!/bin/sh
[ "$1" != "upgrade" ] || exit 0
# This is so you can make busybox commit suicide - removing busybox with no other packages
	# providing its files, this will make update-alternatives work, but the update-rc.d part
	# for syslog, httpd and/or udhcpd will fail if there is no other package providing sh
	tmpdir=`mktemp -d /tmp/busyboxrm-XXXXXX`
	ln -s /bin/busybox $tmpdir/[
	ln -s /bin/busybox $tmpdir/test
	ln -s /bin/busybox $tmpdir/head
	ln -s /bin/busybox $tmpdir/sh
	ln -s /bin/busybox $tmpdir/basename
	ln -s /bin/busybox $tmpdir/echo
	ln -s /bin/busybox $tmpdir/mv
	ln -s /bin/busybox $tmpdir/ln
	ln -s /bin/busybox $tmpdir/dirname
	ln -s /bin/busybox $tmpdir/rm
	ln -s /bin/busybox $tmpdir/sed
	ln -s /bin/busybox $tmpdir/sort
	ln -s /bin/busybox $tmpdir/grep
	export PATH=$PATH:$tmpdir
	update-alternatives --remove  bunzip2 /bin/busybox.nosuid
	update-alternatives --remove  bzcat /bin/busybox.nosuid
	update-alternatives --remove  date /bin/busybox.nosuid
	update-alternatives --remove  groups /bin/busybox.nosuid
	update-alternatives --remove  id /bin/busybox.nosuid
	update-alternatives --remove  touch /bin/busybox.nosuid
	update-alternatives --remove  base64 /bin/busybox.nosuid
	update-alternatives --remove  users /bin/busybox.nosuid
	update-alternatives --remove  who /bin/busybox.nosuid
	update-alternatives --remove  patch /bin/busybox.nosuid
	update-alternatives --remove  vi /bin/busybox.nosuid
	update-alternatives --remove  find /bin/busybox.nosuid
	update-alternatives --remove  grep /bin/busybox.nosuid
	update-alternatives --remove  egrep /bin/busybox.nosuid
	update-alternatives --remove  fgrep /bin/busybox.nosuid
	update-alternatives --remove  xargs /bin/busybox.nosuid
	update-alternatives --remove  ash /bin/busybox.nosuid
	update-alternatives --remove  sh /bin/busybox.nosuid
	update-alternatives --remove  lbracket /bin/busybox.nosuid
	update-alternatives --remove  [[ /bin/busybox.nosuid
	update-alternatives --remove  addgroup /bin/busybox.nosuid
	update-alternatives --remove  adduser /bin/busybox.nosuid
	update-alternatives --remove  ar /bin/busybox.nosuid
	update-alternatives --remove  arp /bin/busybox.nosuid
	update-alternatives --remove  awk /bin/busybox.nosuid
	update-alternatives --remove  basename /bin/busybox.nosuid
	update-alternatives --remove  brctl /bin/busybox.nosuid
	update-alternatives --remove  bzip2 /bin/busybox.nosuid
	update-alternatives --remove  cat /bin/busybox.nosuid
	update-alternatives --remove  chgrp /bin/busybox.nosuid
	update-alternatives --remove  chmod /bin/busybox.nosuid
	update-alternatives --remove  chown /bin/busybox.nosuid
	update-alternatives --remove  chroot /bin/busybox.nosuid
	update-alternatives --remove  chvt /bin/busybox.nosuid
	update-alternatives --remove  clear /bin/busybox.nosuid
	update-alternatives --remove  cmp /bin/busybox.nosuid
	update-alternatives --remove  cp /bin/busybox.nosuid
	update-alternatives --remove  cpio /bin/busybox.nosuid
	update-alternatives --remove  crond /bin/busybox.nosuid
	update-alternatives --remove  cut /bin/busybox.nosuid
	update-alternatives --remove  dc /bin/busybox.nosuid
	update-alternatives --remove  dd /bin/busybox.nosuid
	update-alternatives --remove  deallocvt /bin/busybox.nosuid
	update-alternatives --remove  delgroup /bin/busybox.nosuid
	update-alternatives --remove  deluser /bin/busybox.nosuid
	update-alternatives --remove  df /bin/busybox.nosuid
	update-alternatives --remove  diff /bin/busybox.nosuid
	update-alternatives --remove  dirname /bin/busybox.nosuid
	update-alternatives --remove  dmesg /bin/busybox.nosuid
	update-alternatives --remove  dnsdomainname /bin/busybox.nosuid
	update-alternatives --remove  dos2unix /bin/busybox.nosuid
	update-alternatives --remove  du /bin/busybox.nosuid
	update-alternatives --remove  dumpkmap /bin/busybox.nosuid
	update-alternatives --remove  echo /bin/busybox.nosuid
	update-alternatives --remove  eject /bin/busybox.nosuid
	update-alternatives --remove  env /bin/busybox.nosuid
	update-alternatives --remove  ether-wake /bin/busybox.nosuid
	update-alternatives --remove  expr /bin/busybox.nosuid
	update-alternatives --remove  false /bin/busybox.nosuid
	update-alternatives --remove  fbset /bin/busybox.nosuid
	update-alternatives --remove  fdisk /bin/busybox.nosuid
	update-alternatives --remove  flock /bin/busybox.nosuid
	update-alternatives --remove  getopt /bin/busybox.nosuid
	update-alternatives --remove  getty /bin/busybox.nosuid
	update-alternatives --remove  gunzip /bin/busybox.nosuid
	update-alternatives --remove  gzip /bin/busybox.nosuid
	update-alternatives --remove  hd /bin/busybox.nosuid
	update-alternatives --remove  head /bin/busybox.nosuid
	update-alternatives --remove  hexdump /bin/busybox.nosuid
	update-alternatives --remove  hostname /bin/busybox.nosuid
	update-alternatives --remove  ifconfig /bin/busybox.nosuid
	update-alternatives --remove  ifdown /bin/busybox.nosuid
	update-alternatives --remove  ifup /bin/busybox.nosuid
	update-alternatives --remove  inotifyd /bin/busybox.nosuid
	update-alternatives --remove  ionice /bin/busybox.nosuid
	update-alternatives --remove  ip /bin/busybox.nosuid
	update-alternatives --remove  klogd /bin/busybox.nosuid
	update-alternatives --remove  less /bin/busybox.nosuid
	update-alternatives --remove  ln /bin/busybox.nosuid
	update-alternatives --remove  loadfont /bin/busybox.nosuid
	update-alternatives --remove  loadkmap /bin/busybox.nosuid
	update-alternatives --remove  logger /bin/busybox.nosuid
	update-alternatives --remove  logname /bin/busybox.nosuid
	update-alternatives --remove  losetup /bin/busybox.nosuid
	update-alternatives --remove  ls /bin/busybox.nosuid
	update-alternatives --remove  lspci /bin/busybox.nosuid
	update-alternatives --remove  lsusb /bin/busybox.nosuid
	update-alternatives --remove  lzcat /bin/busybox.nosuid
	update-alternatives --remove  lzma /bin/busybox.nosuid
	update-alternatives --remove  lzop /bin/busybox.nosuid
	update-alternatives --remove  lzopcat /bin/busybox.nosuid
	update-alternatives --remove  md5sum /bin/busybox.nosuid
	update-alternatives --remove  microcom /bin/busybox.nosuid
	update-alternatives --remove  mkdir /bin/busybox.nosuid
	update-alternatives --remove  mkdosfs /bin/busybox.nosuid
	update-alternatives --remove  mkfifo /bin/busybox.nosuid
	update-alternatives --remove  mkfs.vfat /bin/busybox.nosuid
	update-alternatives --remove  mknod /bin/busybox.nosuid
	update-alternatives --remove  mkswap /bin/busybox.nosuid
	update-alternatives --remove  mktemp /bin/busybox.nosuid
	update-alternatives --remove  more /bin/busybox.nosuid
	update-alternatives --remove  mountpoint /bin/busybox.nosuid
	update-alternatives --remove  mv /bin/busybox.nosuid
	update-alternatives --remove  nc /bin/busybox.nosuid
	update-alternatives --remove  netstat /bin/busybox.nosuid
	update-alternatives --remove  nice /bin/busybox.nosuid
	update-alternatives --remove  nohup /bin/busybox.nosuid
	update-alternatives --remove  nslookup /bin/busybox.nosuid
	update-alternatives --remove  od /bin/busybox.nosuid
	update-alternatives --remove  openvt /bin/busybox.nosuid
	update-alternatives --remove  pidof /bin/busybox.nosuid
	update-alternatives --remove  printf /bin/busybox.nosuid
	update-alternatives --remove  pwd /bin/busybox.nosuid
	update-alternatives --remove  rdate /bin/busybox.nosuid
	update-alternatives --remove  readahead /bin/busybox.nosuid
	update-alternatives --remove  readlink /bin/busybox.nosuid
	update-alternatives --remove  realpath /bin/busybox.nosuid
	update-alternatives --remove  renice /bin/busybox.nosuid
	update-alternatives --remove  reset /bin/busybox.nosuid
	update-alternatives --remove  rfkill /bin/busybox.nosuid
	update-alternatives --remove  rm /bin/busybox.nosuid
	update-alternatives --remove  rmdir /bin/busybox.nosuid
	update-alternatives --remove  route /bin/busybox.nosuid
	update-alternatives --remove  run-parts /bin/busybox.nosuid
	update-alternatives --remove  sed /bin/busybox.nosuid
	update-alternatives --remove  seq /bin/busybox.nosuid
	update-alternatives --remove  setconsole /bin/busybox.nosuid
	update-alternatives --remove  setsid /bin/busybox.nosuid
	update-alternatives --remove  sha1sum /bin/busybox.nosuid
	update-alternatives --remove  sha3sum /bin/busybox.nosuid
	update-alternatives --remove  sha256sum /bin/busybox.nosuid
	update-alternatives --remove  sha512sum /bin/busybox.nosuid
	update-alternatives --remove  sleep /bin/busybox.nosuid
	update-alternatives --remove  sort /bin/busybox.nosuid
	update-alternatives --remove  start-stop-daemon /bin/busybox.nosuid
	update-alternatives --remove  stat /bin/busybox.nosuid
	update-alternatives --remove  strings /bin/busybox.nosuid
	update-alternatives --remove  stty /bin/busybox.nosuid
	update-alternatives --remove  sulogin /bin/busybox.nosuid
	update-alternatives --remove  swapoff /bin/busybox.nosuid
	update-alternatives --remove  swapon /bin/busybox.nosuid
	update-alternatives --remove  switch_root /bin/busybox.nosuid
	update-alternatives --remove  sync /bin/busybox.nosuid
	update-alternatives --remove  syslogd /bin/busybox.nosuid
	update-alternatives --remove  tail /bin/busybox.nosuid
	update-alternatives --remove  tar /bin/busybox.nosuid
	update-alternatives --remove  taskset /bin/busybox.nosuid
	update-alternatives --remove  tee /bin/busybox.nosuid
	update-alternatives --remove  telnet /bin/busybox.nosuid
	update-alternatives --remove  telnetd /bin/busybox.nosuid
	update-alternatives --remove  test /bin/busybox.nosuid
	update-alternatives --remove  tftp /bin/busybox.nosuid
	update-alternatives --remove  time /bin/busybox.nosuid
	update-alternatives --remove  timeout /bin/busybox.nosuid
	update-alternatives --remove  tr /bin/busybox.nosuid
	update-alternatives --remove  true /bin/busybox.nosuid
	update-alternatives --remove  tty /bin/busybox.nosuid
	update-alternatives --remove  tunctl /bin/busybox.nosuid
	update-alternatives --remove  udhcpc /bin/busybox.nosuid
	update-alternatives --remove  umount /bin/busybox.nosuid
	update-alternatives --remove  uname /bin/busybox.nosuid
	update-alternatives --remove  uncompress /bin/busybox.nosuid
	update-alternatives --remove  uniq /bin/busybox.nosuid
	update-alternatives --remove  unix2dos /bin/busybox.nosuid
	update-alternatives --remove  unxz /bin/busybox.nosuid
	update-alternatives --remove  unlzma /bin/busybox.nosuid
	update-alternatives --remove  unlzop /bin/busybox.nosuid
	update-alternatives --remove  unzip /bin/busybox.nosuid
	update-alternatives --remove  usleep /bin/busybox.nosuid
	update-alternatives --remove  vconfig /bin/busybox.nosuid
	update-alternatives --remove  wc /bin/busybox.nosuid
	update-alternatives --remove  wget /bin/busybox.nosuid
	update-alternatives --remove  which /bin/busybox.nosuid
	update-alternatives --remove  whoami /bin/busybox.nosuid
	update-alternatives --remove  xzcat /bin/busybox.nosuid
	update-alternatives --remove  xz /bin/busybox.nosuid
	update-alternatives --remove  yes /bin/busybox.nosuid
	update-alternatives --remove  zcat /bin/busybox.nosuid
	update-alternatives --remove  ping /bin/busybox.suid
	update-alternatives --remove  ping6 /bin/busybox.suid
	update-alternatives --remove  crontab /bin/busybox.suid
	update-alternatives --remove  login /bin/busybox.suid
	update-alternatives --remove  passwd /bin/busybox.suid
	update-alternatives --remove  su /bin/busybox.suid
	update-alternatives --remove  traceroute /bin/busybox.suid
	update-alternatives --remove  traceroute6 /bin/busybox.suid
OPTS=""

if [ -n "$D" ]; then
    OPTS="--root=$D"
fi

if type systemctl >/dev/null 2>/dev/null; then
	if [ -z "$D" ]; then
		systemctl stop busybox-telnetd.socket
	fi

	systemctl $OPTS disable busybox-telnetd.socket
fi
