summarylogtreecommitdiffstats
path: root/packettracer.install
diff options
context:
space:
mode:
Diffstat (limited to 'packettracer.install')
-rw-r--r--packettracer.install174
1 files changed, 174 insertions, 0 deletions
diff --git a/packettracer.install b/packettracer.install
new file mode 100644
index 000000000000..3369d3397fac
--- /dev/null
+++ b/packettracer.install
@@ -0,0 +1,174 @@
+pre_install() {
+ remove_pt ()
+ {
+ if [ -e /opt/pt ]; then
+ echo "Removing old version of Packet Tracer from /opt/pt"
+ sudo rm -rf /opt/pt
+ sudo rm -rf /usr/share/applications/cisco-pt7.desktop
+ sudo rm -rf /usr/share/applications/cisco-ptsa7.desktop
+ sudo rm -rf /usr/share/icons/hicolor/48x48/apps/pt7.png
+ fi
+ if [ -e /opt/packettracer/ ]; then
+ echo "Removing old version of Packet Tracer from /opt/packettracer/"
+ sudo rm -rf /opt/packettracer/
+ sudo rm -rf /usr/share/applications/cisco-pt7.desktop
+ sudo rm -rf /usr/share/applications/cisco-ptsa7.desktop
+ sudo rm -rf /usr/share/icons/hicolor/48x48/apps/pt7.png
+ fi
+ }
+}
+
+post_install() {
+ xdg-icon-resource forceupdate --theme hicolor &> /dev/null
+ # update icon and file assocation
+ sudo xdg-desktop-menu install /usr/share/applications/cisco-pt7.desktop
+ sudo update-mime-database /usr/share/mime
+ sudo gtk-update-icon-cache --force /usr/share/icons/gnome
+
+ # sets the incoming PTDIR as a system environment variable
+ # sets the Qt high resolution as a system environment variable
+ # by modifying /etc/profile
+ PTDIR="/opt/packettracer/"
+
+ # create shortcut
+ sudo ln -sf $PTDIR/packettracer /usr/bin/packettracer
+
+ # check /etc/profile for existance of PT7HOME
+ PROFILE="/etc/profile"
+
+ # error exit if file does not exist or unreadable
+ if [ ! -f $PROFILE ]; then
+ exit 1
+ elif [ ! -r $PROFILE ]; then
+ exit 2
+ fi
+
+ # read contents
+ CONTENTS=""
+ EXPORT_EXISTS=0
+ PT7HOME_EXISTS=0
+ PT7HOME_FOUND=0
+ EXPORT_QT_EXISTS=0
+ QT_EXISTS=0
+ QT_FOUND=0
+ exec 3<&0
+ exec 0<$PROFILE
+ while IFS= read -r line
+ do
+
+ # replace existing entries
+ PT7HOME_FOUND=$(expr match "$line" 'PT7HOME')
+ if [ "$PT7HOME_FOUND" -gt 0 ]; then
+ line="PT7HOME=$PTDIR"
+ PT7HOME_EXISTS=1
+ fi
+
+ QT_FOUND=$(expr match "$line" 'QT_DEVICE_PIXEL_RATIO')
+ if [ "$QT_FOUND" -gt 0 ]; then
+ line="QT_DEVICE_PIXEL_RATIO=auto"
+ QT_EXISTS=1
+ fi
+
+ # check for export statement
+ if [ $EXPORT_EXISTS -eq 0 ]; then
+ EXPORT_QT_EXISTS=$(expr match "$line" 'export QT_DEVICE_PIXEL_RATIO')
+ fi
+
+ if [ "$EXPORT_QT_EXISTS" -eq 0 ]; then
+ EXPORT_QT_EXISTS=$(expr match "$line" 'export QT_DEVICE_PIXEL_RATIO')
+ fi
+
+ #append the line to the contents
+ CONTENTS="$CONTENTS
+$line"
+ done
+ exec 0<&3
+
+ if [ $PT7HOME_EXISTS -eq 0 ]; then
+ CONTENTS="$CONTENTS
+PT7HOME=$PTDIR"
+ fi
+
+ if [ $EXPORT_EXISTS -eq 0 ]; then
+ CONTENTS="$CONTENTS
+export PT7HOME"
+ fi
+
+ if [ $QT_EXISTS -eq 0 ]; then
+ CONTENTS="$CONTENTS
+QT_DEVICE_PIXEL_RATIO=auto"
+ fi
+
+ if [ $EXPORT_EXISTS -eq 0 ]; then
+ CONTENTS="$CONTENTS
+export QT_DEVICE_PIXEL_RATIO"
+ fi
+
+ sudo echo -e "$CONTENTS" | sudo tee /etc/profile > /dev/null
+ sudo sed '1{/^$/d}' -i /etc/profile > /dev/null
+
+ update-desktop-database -q
+}
+
+pre_upgrade() {
+ pre_install
+}
+
+post_upgrade() {
+ post_install
+}
+
+post_remove() {
+ xdg-icon-resource forceupdate --theme hicolor &> /dev/null
+ sudo xdg-desktop-menu uninstall /usr/share/applications/cisco-pt7.desktop
+ sudo xdg-desktop-menu uninstall /usr/share/applications/cisco-ptsa7.desktop
+ sudo update-mime-database /usr/share/mime
+ sudo gtk-update-icon-cache --force /usr/share/icons/gnome
+
+ sudo rm -f /usr/bin/packettracer
+
+ # check /etc/profile for existance of PT7HOME
+ PROFILE="/etc/profile"
+
+ # error exit if file does not exist or unreadable
+ if [ ! -f $PROFILE ]; then
+ true
+ elif [ ! -r $PROFILE ]; then
+ true
+ fi
+
+ # read contents
+ exec 3<&0
+ exec 0<$PROFILE
+ while IFS= read -r line
+ do
+ PT7HOME_FOUND=$(expr match "$line" 'PT7HOME')
+ if [ "$PT7HOME_FOUND" -gt 0 ]; then
+ continue
+ fi
+
+ QT_FOUND=$(expr match "$line" 'QT_DEVICE_PIXEL_RATIO')
+ if [ "$QT_FOUND" -gt 0 ]; then
+ continue
+ fi
+
+ EXPORT_FOUND=$(expr match "$line" 'export PT7HOME')
+ if [ "$EXPORT_FOUND" -gt 0 ]; then
+ continue
+ fi
+
+ EXPORT_QT_FOUND=$(expr match "$line" 'export QT_DEVICE_PIXEL_RATIO')
+ if [ "$EXPORT_QT_FOUND" -gt 0 ]; then
+ continue
+ fi
+
+ CONTENTS="$CONTENTS
+$line"
+ done
+ exec 0<&3
+
+ sudo echo -e "$CONTENTS" | sudo tee /etc/profile > /dev/null
+ sudo sed '1{/^$/d}' -i /etc/profile > /dev/null
+
+ update-desktop-database -q
+}