0

recently I created a script to install easily a software called AVInaptic. I'd like to know if these steps are good enough and how to get across to the system that the software was installed. Moreover I'd like to link an uninstaller to the installation How can I do?

Here you can see the code

First I get the desktop folder name (depends from the system language )

if [ -r ~/.config/user-dirs.dirs ]
then
    . ~/.config/user-dirs.dirs
fi
if [ "$XDG_DESKTOP_DIR" = "" ]
then
    export XDG_DESKTOP_DIR=$HOME/Desktop
fi
#XDG_DESKTOP_DIR contains the name of the desktop

Declare the variables used in the installer

#It's the command given to the shell to execute the program
export CMD=avinaptic
#It's the name of the program
export NAME="AVInaptic"

#Auto-generated or fixed variables
export TEMP_NAME=~/temp_$CMD
export FOLDER_NAME=/opt/$CMD
export ICON_SUFFIX=.png
export LIB_FOLDER="/usr/lib32"

#Other info
export LINK_ICON="https://chakraos.org/ccr/packages/av/avinaptic2/avinaptic2/avinaptic2.png"
export LINK_SOFTWARE="http://fsinapsi.altervista.org/code/avinaptic/avinaptic.zip"
export GENERIC_NAME="Report Video"
export CATEG="GTK;AudioVideo;"
export EN_COM="A free utility which reports many technical informations about multimedia files."
export IT_COM="Un programma che analizza file file multimediali e mostra informazioni sulle caratteristiche tecniche."

I create the folders I'll use

echo '###Creating folder###'
sudo mkdir -p $FOLDER_NAME
mkdir $TEMP_NAME
mkdir -p ~/bin

I install all the needed libraries

echo '###Installing dependencies###'
sudo mkdir -p $LIB_FOLDER/libgtk
sudo mkdir -p $LIB_FOLDER/libgmp
#Download libraries
#Download libgtk
echo '###Download libgtk###'
wget -q http://fsinapsi.altervista.org/code/avinaptic/libgtk.zip -O $TEMP_NAME/libgtk.zip
#Download libiconv
echo '###Download libiconv###'
sudo wget -q http://fsinapsi.altervista.org/code/avinaptic/libiconv.zip -O $TEMP_NAME/libiconv.zip
#Download libgmp
echo '###Download libgmp###'
sudo wget -q http://fsinapsi.altervista.org/code/avinaptic/libgmp.zip -O $TEMP_NAME/libgmp.zip
#Download libjpeg
sudo wget -q http://ftp.it.debian.org/debian/pool/main/libj/libjpeg6b/libjpeg62_6b1-1_i386.deb -O $TEMP_NAME/libjpeg.deb
#Install libraries
sudo unzip $TEMP_NAME/libgtk.zip -d /usr/lib32/libgtk/
sudo unzip $TEMP_NAME/libiconv.zip -d /usr/lib32/
sudo unzip $TEMP_NAME/libgmp.zip -d /usr/lib32/libgmp/
sudo gdebi --n $TEMP_NAME/libjpeg.deb
#Create config
sudo rm -f /etc/ld.so.conf.d/avinaptic.conf
sudo printf '/usr/lib32\n/usr/lib32/libgtk\n/usr/lib32/libgmp' > /etc/ld.so.conf.d/avinaptic.conf
#Update libraries
sudo ldconfig
echo '###Dependencies installed###'

I download Main Software

echo '###Download Main Software###'
wget "$LINK_SOFTWARE" -O "$TEMP_NAME/$CMD.zip"

#Start settings
echo '###Setting up...###'
#Move Software to his folder
sudo unzip "$TEMP_NAME/$CMD.zip" -d "$FOLDER_NAME"

echo '###Create script###'
echo "#!/bin/bash
# Purpose:  
# Usage:    
# Author:   Timmy93
# Date:     
# Version:  
# Disclaimer:
$FOLDER_NAME/$CMD" > $TEMP_NAME/$CMD
sudo mv "$TEMP_NAME/$CMD" ~/bin/

echo '###Make it executable###'
chmod +x ~/bin/$CMD


#Create Hard Link
echo '###Create Hard Link###'
sudo ln -s ~/bin/$CMD /usr/local/bin
#Download Icon
wget -q $LINK_ICON -O $TEMP_NAME/$CMD$ICON_SUFFIX
sudo mv $TEMP_NAME/$CMD$ICON_SUFFIX /usr/share/pixmaps

#Create Shortcuts
shortcut="[Desktop Entry]
Encoding=UTF-8
Version=1.0
Name=$NAME
GenericName=$GENERIC_NAME
Exec=$CMD
Terminal=false
Icon=$CMD
Type=Application
Categories=$CATEG
Comment=$EN_COM
Comment[it]=$IT_COM"
echo "$shortcut" > "$TEMP_NAME/$NAME.desktop"
chmod +x "$TEMP_NAME/$NAME.desktop"
sudo cp "$TEMP_NAME/$NAME.desktop" /usr/share/applications/
cp "$TEMP_NAME/$NAME.desktop" "$XDG_DESKTOP_DIR/$NAME.desktop"

I remove useless files

rm -rf -f "$TEMP_NAME"

echo '###All done###'

EDIT: Here is the uninstaller I've written (I've omitted the variable because they are equals):

echo '###Start unistalling ...###'
#Remove dependencies
sudo rm -rf -f $LIB_FOLDER/libgtk/
sudo rm -rf -f $LIB_FOLDER/libgmp/
sudo rm -f $LIB_FOLDER/libiconv.so.2
sudo rm -f /etc/ld.so.conf.d/avinaptic.conf
#Removes folders
sudo rm -f -rf $FOLDER_NAME
sudo rm -f -rf $TEMP_NAME
#Removes scripts
sudo rm -f /usr/local/bin/$CMD
sudo rm -f ~/bin/$CMD
#Removes setting
sudo rm -f /etc/ld.so.conf.d/avinaptic.conf
#Removes icon
sudo rm -f /usr/share/pixmaps/$CMD$ICON_SUFFIX
#Removes shortcuts
sudo rm -f /usr/share/applications/$NAME.desktop
sudo rm -f $XDG_DESKTOP_DIR/$NAME.desktop

#Update libraries
sudo ldconfig
echo '###All done###'
Timmy
  • 693
  • 2
  • 8
  • 26
  • So, where is it failing? – anishsane Dec 22 '15 at 10:00
  • 1
    Why not just package it as a .deb and let the native Ubuntu/Mint/Debian installer of choice do the job for you? – Joe Dec 22 '15 at 10:01
  • @anishsane No it isn't failing but for example I'd like to link the unistaller when from the menu I press: "Right click on the software>Uninstall" – Timmy Dec 22 '15 at 10:04
  • @Joe but it's possible to download all the libriaries and install them in the right folder? Sorry for the elementar question but I'm a newbie and I've never created a deb – Timmy Dec 22 '15 at 10:06
  • @Timmy I'm not sure quite what you mean. .debs allow you to specify the dependencies of the package so the package manager knows it must install them. If you're targeting some kind of installer at Ubuntu you should really use their package management system; it's what people would expect. – Joe Dec 22 '15 at 10:10
  • @Timmy If you're interesting in going that route, there's plenty of help available! http://stackoverflow.com/questions/1165727/resources-on-writing-a-debian-ubuntu-deb-package – Joe Dec 22 '15 at 10:13
  • @Joe In the paragraph: "I install all the needed libraries" I download 3 zips, unzip and move them to a specific folder then I download also a .deb and install it using gdebi. All these things can be made also using .deb? EDIT: Thank you I'll read the topic to understand what can and waht cannot be done with deb – Timmy Dec 22 '15 at 10:16
  • @Timmy The "needed libraries" are dependencies of your package. So you can inform the package manager of this requirement in your .deb file. It will then go off and install them as well as your package when you install it. If you look at installing a simple ubuntu package you'll notice that it will automatically install anything that package needs, if you install, say kubuntu-desktop you don't get just one package installed but LOADS! This is why you want to use a real package manager, otherwise you have to manage everything that those libraries depend on too.... – Joe Dec 22 '15 at 10:20

0 Answers0