#!/bin/bash clear ############### Instalacion de hamachi para Ubuntu Hardy, Intrepid, Jaunty o Karmic ################ ########################################################################## ### INSTALL ### DOWNLOAD=http://files.hamachi.cc/linux/hamachi-0.9.9.9-20-lnx.tar.gz FILE=hamachi-0.9.9.9-20-lnx.tar.gz VERSION=hamachi-0.9.9.9-20-lnx ### ghamachi ### DOWNLOADGHAMACI=http://harvie.cz/wan/tools/hamachi/gHamachi_0.8.1.tar.gz GHAMACHIICON=http://wonsheimlan.wo.funpic.de/hamachi.png GHAMACHIVERSION=gHamachi.tar.gz ### hamachi-gui - i386-hardy ### DOWNLOADHAMACHIGUII386=http://internap.dl.sourceforge.net/sourceforge/hamachi-gui/hamachi-gui_0.9.6-1_i386-hardy.deb ### hamachi-gui - i386-intrepid ### DOWNLOADHAMACHIGUII386=http://internap.dl.sourceforge.net/sourceforge/hamachi-gui/hamachi-gui_0.9.6-1_i386-hardy.deb ### hamachi-gui - i386-jaunty ### DOWNLOADHAMACHIGUII386=http://internap.dl.sourceforge.net/sourceforge/hamachi-gui/hamachi-gui_0.9.6-1_i386-hardy.deb ### hamachi-gui - i386-karmic ### DOWNLOADHAMACHIGUII386=http://internap.dl.sourceforge.net/sourceforge/hamachi-gui/hamachi-gui_0.9.6-1_i386-hardy.deb ### hamachi-gui - amd64-hardy ### DOWNLOADHAMACHIGUIAMD64=http://internap.dl.sourceforge.net/sourceforge/hamachi-gui/hamachi-gui_0.9.6-1_amd64-hardy.deb ### hamachi-gui - amd64-intrepid ### DOWNLOADHAMACHIGUIAMD64=http://internap.dl.sourceforge.net/sourceforge/hamachi-gui/hamachi-gui_0.9.6-1_amd64-hardy.deb ### hamachi-gui - amd64-jaunty ### DOWNLOADHAMACHIGUIAMD64=http://internap.dl.sourceforge.net/sourceforge/hamachi-gui/hamachi-gui_0.9.6-1_amd64-hardy.deb ### hamachi-gui - amd64-karmic ### DOWNLOADHAMACHIGUIAMD64=http://internap.dl.sourceforge.net/sourceforge/hamachi-gui/hamachi-gui_0.9.6-1_amd64-hardy.deb ############################################################ ### Leer version de Ubuntu ### function UBUNTUVERSION { distro=`lsb_release -i -r -s` case $distro in Ubuntu*8.04|Ubuntu*8.10|Ubuntu*9.04|Ubuntu*9.10) ;; *) echo distro $distro no soportada; read -p "Press any key to exit " var exit 1;; esac } ### Eliminar TUN de /etc/modules ### function REMOVETUN { find /etc/modules -exec sed -i '/tun/d' {} \; } ### Install Hamachi ### function INSTALLHAMACHI { if [ ! -r /usr/bin/hamachi ]; then sleep 1 echo "Installing required packages..." echo distro=`lsb_release -i -r -s` case $distro in Ubuntu*8.04) if [ `uname -m` = x86_64 ]; then sudo apt-get -y install build-essential ia32-libs upx-ucl else sudo apt-get -y install build-essential upx-ucl fi ;; Ubuntu*8.10) if [ `uname -m` = x86_64 ]; then sudo apt-get -y install build-essential ia32-libs upx-ucl else sudo apt-get -y install build-essential upx-ucl fi ;; Ubuntu*9.04) if [ `uname -m` = x86_64 ]; then sudo apt-get -y install build-essential ia32-libs upx-ucl else sudo apt-get -y install build-essential upx-ucl fi ;; Ubuntu*9.10) if [ `uname -m` = x86_64 ]; then sudo apt-get -y install build-essential ia32-libs upx-ucl else sudo apt-get -y install build-essential upx-ucl fi ;; *) echo distro $distro no soportada; exit 1;; esac echo sleep 1 sudo modprobe tun sudo bash -c "echo tun >> /etc/modules" cd /home/$USER wget $DOWNLOAD sleep 1 tar -zxvf $FILE cd $VERSION sleep 1 sudo make install cd /usr/bin sleep 1 sudo upx -d hamachi sleep 1 cd /home/$USER rm $FILE rm -Rv $VERSION sleep 1 echo echo "Setting up groups and creating RSA key pairs." sudo /sbin/tuncfg sleep 1 echo echo "Creating hamachi group..." sudo groupadd hamachi sleep 1 echo echo "Adding user root to the hamachi group..." sudo gpasswd -a root hamachi sleep 1 echo echo "Adding user $USER to the hamachi group..." sudo gpasswd -a $USER hamachi sleep 1 echo if [ ! -d /home/$USER/.hamachi/ ]; then echo "Creating RSA key pairs..." sleep 1 hamachi-init fi sleep 1 sudo chown -R $USER:$USER ~/.hamachi echo if [ "$?" = "0" ]; then echo "Congratulations, hamachi has been installed" echo read -p "Press ENTER to continue " var sleep 1 sudo chmod 760 /var/run/tuncfg.sock sudo chgrp hamachi /var/run/tuncfg.sock clear fi else echo echo "*** hamachi is already installed ***" echo fi } ### Revisar si hamachi ya esta instalado ### function HAMACHIINSTALLED { if [ ! -r /usr/bin/hamachi ]; then clear echo echo "*** Install hamachi before continuing ***" echo read -p "Press ENTER to exit " var echo exit 1 fi } ### Comprobar si la carpeta .hamachi esiste ### function HAMACHIFOLDER { if [ ! -d /home/$USER/.hamachi ]; then clear echo echo "*** /home/$USER/.hamachi does not exist ***" echo break fi sleep 1 } ### Comprobar si ghamachi esta instalado ### function GHAMACHIINSTALLED { if [ ! -r /usr/bin/ghamachi ]; then clear echo echo "*** ghamachi is not installed ***" echo break fi sleep 1 } ### Comprobar si hamachi-gui esta instalado ### function HAMACHIGUIINSTALLED { if [ ! -r /usr/bin/hamachi-gui ]; then clear echo echo "*** hamachi-gui is not installed ***" echo break fi sleep 1 } ### Comprobar si la carpeta autostart esiste ### function AUTOSTARTFOLDER { if [ ! -d /home/$USER/.config/autostart/ ]; then mkdir /home/$USER/.config/autostart/ fi sleep 1 } ### Crear ghamachi.desktop ### function GHAMACHIDESKTOP { if [ ! -e /usr/share/applications/ghamachi.desktop ]; then sudo bash -c "echo '[Desktop Entry]' > /usr/share/applications/ghamachi.desktop" sudo bash -c "echo 'Name=gHamachi' >> /usr/share/applications/ghamachi.desktop" sudo bash -c "echo 'Exec=ghamachi' >> /usr/share/applications/ghamachi.desktop" sudo bash -c "echo 'Icon=/usr/share/pixmaps/hamachi.png' >> /usr/share/applications/ghamachi.desktop" sudo bash -c "echo 'Type=Application' >> /usr/share/applications/ghamachi.desktop" sudo bash -c "echo 'Categories=Network;Application;' >> /usr/share/applications/ghamachi.desktop" sudo bash -c "echo 'Comment=Instant VPN software' >> /usr/share/applications/ghamachi.desktop" fi } ### Crear binarios /etc/init.d/tuncfg ### function CREATETUNCFG { if [ ! -e /etc/init.d/tuncfg ]; then sudo bash -c "echo '#! bin/sh' > /etc/init.d/tuncfg" sudo bash -c "echo '# /etc/init.d/tuncfg' >> /etc/init.d/tuncfg" sudo bash -c "echo '/sbin/tuncfg' >> /etc/init.d/tuncfg" echo sudo chmod 755 /etc/init.d/tuncfg sudo update-rc.d tuncfg defaults echo fi } ### Copia de seguridad hamachi ### function BACKUPHAMACHI { echo echo "Searching for users..." echo cat /etc/passwd | grep "/bin/bash" | cut -d: -f1 echo echo -n "For what user do you want to create a backup? " read BACKUPFILES if [ "$BACKUPFILES" = "root" ]; then echo echo "Backing up hamachi files: $BACKUPFILES to the Desktop..." echo sudo tar -cvpzf /home/$USER/Desktop/hamachi_backup_root.tar.gz /root/.hamachi sleep 1 sudo chown $USER:$USER /home/$USER/Desktop/hamachi_backup_root.tar.gz echo else echo echo "Backing up hamachi files: $BACKUPFILES to the Desktop..." echo sudo tar -cvpzf /home/$USER/Desktop/hamachi_backup.tar.gz /home/$BACKUPFILES/.hamachi sleep 1 sudo chown $USER:$USER /home/$USER/Desktop/hamachi_backup.tar.gz echo fi } ### Eliminar hamachi ### function REMOVEHAMACHI { echo echo "Stopping hamachi..." sudo hamachi stop echo sudo rm -fv /usr/bin/hamachi-init sudo rm -fv /usr/bin/hamachi sudo rm -fv /sbin/tuncfg echo echo "Deleting hamachi groups..." echo sudo groupdel hamachi sudo find /var/run -type f -name "tuncfg.*" -exec rm -f {} \; sudo find /etc/modules -exec sed -i '/tun/d' {} \; echo echo -n "Do you want to delete the hamachi user files? (y/n): " read answer if [ "$answer" = "y" ]; then echo echo "Searching for users..." echo cat /etc/passwd | grep "/bin/bash" | cut -d: -f1 echo echo -n "What hamachi user files do you want to delete?: " read REMOVEFILES if [ "$REMOVEFILES" = "root" ]; then echo echo "Deleting hamachi user files: $REMOVEFILES ..." sudo rm -Rvf /root/.hamachi echo else echo echo "Deleting hamachi user files: $REMOVEFILES ..." sudo rm -Rvf /home/$REMOVEFILES/.hamachi echo fi fi } ################ Empezar Script ################ UBUNTUVERSION ################ Menu ################ menu= until [ "$menu" = "0" ]; do echo echo "Script maintained by soker site:portalubuntu.blogspot.com" echo "Translated by Andrew site:www.webupd8.org" echo echo "version 1.0.2" echo "-------------------------------------------------------------" echo "Install or remove hamachi in Ubuntu" echo echo "-------------------------------------------------------------" echo echo "1. Install hamachi for Ubuntu `lsb_release -r -s` - `uname -m`" echo "2. Install ghamachi - (hamachi GUI for Linux)" echo "3. Install hamachi-gui - (another hamachi GUI for Linux)" echo "4. Backup, restore and / or remove hamachi, ghamachi, and hamachi-gui" echo "0. Exit" echo echo "-------------------------------------------------------------" echo echo -n "Enter a number [0-4]: " read selection echo case $selection in ################ Instalar y configurar hamachi ################ 1 ) clear echo echo -n "Install packages needed by hamachy? (y/n): " read answer if [ "$answer" = "y" ]; then echo INSTALLHAMACHI echo else echo REMOVETUN echo "hamachi has not beed installed" echo fi ;; ################ Instalar ghamachi ################ 2 ) clear HAMACHIINSTALLED echo echo -n "Install ghamachi? (y/n): " read answer if [ "$answer" = "y" ]; then echo echo "Installing additional packages needed by ghamachi..." echo sudo apt-get -y install gnome-rdp sleep 1 echo echo mkdir /home/$USER/ghamchidownload/ wget -O /home/$USER/ghamchidownload/$GHAMACHIVERSION "$DOWNLOADGHAMACI" tar -zxvf /home/$USER/ghamchidownload/$GHAMACHIVERSION -C /home/$USER/ghamchidownload/ wget -O /home/$USER/ghamchidownload/hamachi.png "$GHAMACHIICON" sudo mv /home/$USER/ghamchidownload/hamachi.png /usr/share/pixmaps/ sudo mv /home/$USER/ghamchidownload/ghamachi /usr/bin/ sudo chmod +x /usr/bin/ghamachi GHAMACHIDESKTOP rm -fR /home/$USER/ghamchidownload echo if [ "$?" = "0" ]; then echo echo "Done installing ghamachi" echo echo "You can find it under - [Applications -> Internet -> gHamachi]" echo echo echo "*** For boot configuration, log off and then log back in ***" sleep 1 echo sudo chown -R $USER:$USER ~/.hamachi echo read -p "Press ENTER to continue " var echo echo -n "Do you want to open ghamachi when the system boots? (y/n): " read answer if [ "$answer" = "y" ]; then echo CREATETUNCFG echo echo sudo chmod 755 /etc/init.d/tuncfg sudo update-rc.d tuncfg defaults echo echo "Adding ghamachi to the Startup Applications - [System -> Preferences -> Startup Applications]" AUTOSTARTFOLDER sudo cp /usr/share/applications/ghamachi.desktop /home/$USER/.config/autostart/ sleep 1 sudo chown -R $USER:$USER /home/$USER/.config/autostart/ghamachi.desktop if [ "$?" = "0" ]; then echo echo "Done, ghamachi will be loaded at boot time" echo echo echo "*** For boot configuration, log off and then log back in ***" echo echo read -p "Press ENTER to continue " var else echo echo "Cannot add ghamachi to the Startup Applications." echo fi fi fi else echo echo "ghamachi has not been installed" echo fi ;; ################ Instalar hamachi-gui ################ 3 ) clear HAMACHIINSTALLED echo echo -n "Install hamachi-gui? (y/n): " read answer distro=`lsb_release -i -r -s` case $distro in Ubuntu*8.04) ;; Ubuntu*8.10) ;; Ubuntu*9.04) ;; Ubuntu*9.10) ;; *) echo distro $distro not supported; read -p "Press ENTER to exit " var exit 1;; esac if [ "$answer" = "y" ]; then echo cd /home/$USER case $distro in Ubuntu*8.04|Ubuntu*8.10|Ubuntu*9.04|Ubuntu*9.10) if [ `uname -m` = x86_64 ]; then wget $DOWNLOADHAMACHIGUIAMD64 sleep 1 sudo dpkg -i hamachi-gui* else wget $DOWNLOADHAMACHIGUII386 sleep 1 sudo dpkg -i hamachi-gui* if [ "$?" = "0" ]; then echo echo "hamachi-gui has been installed" echo echo else echo echo "Could not install hamachi-gui." echo fi fi ;; *) echo "ERROR: This script does not support Ubuntu `lsb_release -r -s` !" break ;; esac echo sudo apt-get -y install gnome-rdp echo rm hamachi-gui* if [ "$?" = "0" ]; then echo echo "Done installing Hamachi-gui!" echo echo "You can find it under - [Applications -> Internet -> hamachi-gui]" echo echo echo "*** For boot configuration, log off and then log back in ***" echo sleep 1 sudo chown -R $USER:$USER ~/.hamachi echo read -p "Press ENTER to continue " var echo echo -n "Do you want to open Hamachi-gui when the system boots? (y/n): " read answer if [ "$answer" = "y" ]; then echo CREATETUNCFG echo echo sudo chmod 755 /etc/init.d/tuncfg sudo update-rc.d tuncfg defaults echo echo "Adding hamachi-gui to the Startup Applications - [System -> Preferences -> Startup Applications]" AUTOSTARTFOLDER sudo cp /usr/share/applications/hamachi-gui.desktop /home/$USER/.config/autostart/ sleep 1 sudo chown -R $USER:$USER /home/$USER/.config/autostart/hamachi-gui.desktop if [ "$?" = "0" ]; then echo echo "Done, hamachi-gui will be loaded at boot time" echo echo echo "*** For boot configuration, log off and then log back in ***" echo echo read -p "Press ENTER to continue " var else echo echo "Cannot add hamachi-gui to the Startup Applications." echo fi fi fi else echo echo "hamachi-gui has not been installed" echo fi ;; ################ Backup/Remove hamachi menu ################ 4 ) clear removebackupmenu= until [ "$removebackupmenu" = "0" ]; do echo echo "Remove or make backups of hamachi" echo echo "-------------------------------------------------------------" echo echo "[1] Back-up hamachi user settings" echo "[2] Restore hamachi user settings" echo "[3] Remove hamachi" echo "[4] Remove ghamachi" echo "[5] Remove hamachi-gui" echo "[0] Exit" echo echo "-------------------------------------------------------------" echo echo -n "Enter a number [0-5]: " read removebackupselection echo case $removebackupselection in ################ Configuracion copias de seguridad de hamachi ################ 1 ) echo HAMACHIFOLDER echo -n "Create back-ups for the hamachi user settings? (y/n): " read answer if [ "$answer" = "y" ]; then BACKUPHAMACHI else echo echo "Leaving the menu..." echo fi ;; ################ Restaurar configuraciones de hamachi ################ 2 ) echo echo -n "Restore hamachi user settings? (y/n): " read answer if [ "$answer" = "y" ]; then echo echo "Searching for users..." echo cat /etc/passwd | grep "/bin/bash" | cut -d: -f1 echo echo -n "For what user do you want to restore the hamachi config files?: " read BACKUPFILES if [ "$BACKUPFILES" = "root" ]; then if [ ! -e /home/$USER/Desktop/hamachi_backup_root.tar.gz ]; then echo echo "hamachi_backup_root.tar.gz does not exist!" echo else echo "Backing up hamachi files: $BACKUPFILES to the Desktop..." if [ ! -d /root/.hamachi ]; then sudo mkdir /root/.hamachi fi sudo tar -zxvf /home/$USER/Desktop/hamachi_backup_root.tar.gz -C /root/.hamachi echo fi else if [ ! -e /home/$USER/Desktop/hamachi_backup.tar.gz ]; then echo echo "hamachi_backup.tar.gz does not exist!" echo else echo "Backing up hamachi files: $BACKUPFILES to the Desktop..." if [ ! -d /root/.hamachi ]; then sudo mkdir /root/.hamachi fi sudo tar -zxvf /home/$USER/Desktop/hamachi_backup.tar.gz -C /home/$USER/.hamachi echo fi fi else echo echo "Leaving the menu..." echo fi ;; ################ Eliminar hamachi ################ 3 ) echo HAMACHIINSTALLED echo echo -n "Do you want to backup the configuration files before removing hamachi? (y/n): " read answer if [ "$answer" = "y" ]; then BACKUPHAMACHI sleep 1 REMOVEHAMACHI else REMOVEHAMACHI fi ;; ################ Eliminar ghamachi ################ 4 ) echo GHAMACHIINSTALLED echo -n "Remove ghamachi? (y/n): " read answer if [ "$answer" = "y" ]; then echo sudo rm -vf /usr/share/pixmaps/hamachi.png sudo rm -vf /usr/bin/ghamachi sudo rm -vf /usr/share/applications/ghamachi.desktop sudo rm -vf /home/$USER/.config/autostart/ghamachi.desktop sleep 1 sudo killall tuncfg sleep 1 sudo update-rc.d -f tuncfg remove sleep 1 sudo rm -vf /etc/init.d/tuncfg echo if [ "$?" = "0" ]; then echo echo "ghamachi has been removed!" echo else echo echo "ghamachi could not be removed." echo fi else echo echo "ghamachi has not beed removed" echo fi ;; ################ Eliminar hamachi-gui ################ 5 ) echo HAMACHIGUIINSTALLED echo -n "Remove hamachi-gui? (y/n): " read answer if [ "$answer" = "y" ]; then echo sudo dpkg -r hamachi-gui sudo rm -vf /usr/share/applications/hamachi-gui.desktop sleep 1 sudo killall tuncfg sleep 1 sudo update-rc.d -f tuncfg remove sleep 1 sudo rm -vf /etc/init.d/tuncfg echo if [ "$?" = "0" ]; then echo echo "hamachi-gui has been removed!" echo else echo echo "hamachi-gui could not be removed." echo fi else echo echo "hamachi-gui has not beed removed" echo fi ;; ################ Fin del Menu de Copia de seguridad/Eliminar hamachi################ 0 ) echo "Exiting ..." echo break ;; * ) echo "That's not a valid number! Enter a number between: [0-5]: " echo ;; esac done ;; ################ Fin del Script ################ 0 ) echo echo "Thank you for using this script. Pease visit portalubuntu.blogspot.com if you encounter any issues" echo read -p "Press ENTER to continue " var echo exit 0 ;; * ) echo "That's not a valid number! Enter a number between: [0-4]: " echo ;; esac done