#!/bin/sh
chmod +x /opt/maemo/usr/bin/openssh-status-config.py
chmod +x /opt/maemo/usr/lib/hildon-desktop/openssh-status-widget.py
chmod +x /opt/maemo/usr/sbin/openssh-status.sh
chmod +x /opt/maemo/usr/sbin/osw-power-management
chmod +x /etc/ssh/sshrlc
if [ ! -f /etc/ssh/sshrc ]; then
  cp /etc/ssh/sshrc.osw /etc/ssh/sshrc
  chmod +x /etc/ssh/sshrc
fi
if [ $(grep -c 'OpenSSH Status Widget' /etc/ssh/sshrc) -eq 0 ]; then
  cp /etc/ssh/sshrc /etc/ssh/sshrc2
  cp /etc/ssh/sshrc.osw /etc/ssh/sshrc
  chmod +x /etc/ssh/sshrc
fi
ln -s /opt/maemo/usr/bin/openssh-status-config.py /usr/bin/openssh-status-config.py
ln -s /opt/maemo/usr/lib/hildon-desktop/openssh-status-widget.py /usr/lib/hildon-desktop/openssh-status-widget.py
ln -s /opt/maemo/usr/sbin/openssh-status.sh /usr/sbin/openssh-status.sh
ln -s /opt/maemo/usr/sbin/osw-power-management /usr/sbin/osw-power-management
sed -i 's/1___/1 minute/g' /home/user/.openssh-status-widget
sed -i 's/5___/5 minutes/g' /home/user/.openssh-status-widget
sed -i 's/15__/15 minutes/g' /home/user/.openssh-status-widget
sed -i 's/30__/30 minutes/g' /home/user/.openssh-status-widget
sed -i 's/60__/60 minutes/g' /home/user/.openssh-status-widget
chown user /home/user/.openssh-status-widget
sed -i '/# OpenSSH Status Widget entry for controling wifi power management/d' /etc/ssh/sshd_config
sed -i '/# OpenSSH Status Widget entry for controlling wifi power management/d' /etc/ssh/ssh_config
sed -i '/# Do not edit, instead edit \/etc\/ssh\/sshrlc2 to add commands/d' /etc/ssh/ssh_config
sed -i '/localCommand \/etc\/ssh\/sshrlc/d' /etc/ssh/ssh_config
sed -i 's/#localCommand/localCommand/g' /etc/ssh/ssh_config
sed -i 's/localCommand/#localCommand/g' /etc/ssh/ssh_config
sed -i '/PermitLocalCommand/d' /etc/ssh/ssh_config
echo "# OpenSSH Status Widget entry for controlling wifi power management" >> /etc/ssh/ssh_config
echo "# Do not edit, instead edit /etc/ssh/sshrlc2 to add commands" >> /etc/ssh/ssh_config
echo "    PermitLocalCommand yes" >> /etc/ssh/ssh_config
echo "    localCommand /etc/ssh/sshrlc" >> /etc/ssh/ssh_config
if [ -f /usr/lib/openssh/session ]; then
  if [ $(grep -c 'Control wifi power management' /usr/lib/openssh/session) -gt 0 ]; then
    rm /usr/lib/openssh/session
  fi
fi
if [ -f /usr/lib/openssh/wifi-power-management ]; then
  if [ $(grep -c 'iwconfig wlan0 power off' /usr/lib/openssh/wifi-power-management) -gt 0 ]; then
    rm /usr/lib/openssh/wifi-power-management
  fi
fi
if [ -f /usr/lib/openssh/session_client ]; then
  rm /usr/lib/openssh/session_client
fi
update-sudoers
