~woof/woofgui/seamless

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash

#check for root-rights
if [ ! "`whoami`" = "root" ]; then
   echo 'This script must be run as root'
   exit 1
fi

# Find out the actual username who's running the show 
actualuser=`eval logname`

#list of files needed to run woof
dep=( python-gtk2 python-notify )

echo -e "\nHello $actualuser! Welcome to Woof!"

echo -e '\nLet me check dependencies so we can be sure that Woof will run smoothly...\n'

#this works only for debian-like systems
for package in ${dep[@]}
do
   installed='no'
   list=`eval dpkg --get-selections | grep $package`
   if [ ${#list} -gt 0 ]; then
      installed='yes'
   fi
   echo $package installed: $installed
   if [ $installed == 'no' ]; then
      echo -e "\nOps! Sorry, there are missing dependencies: Please install the newest version of $package and run me again.\n"
      exit 1
   fi
done

echo -e '\nAll stuff necessary to run Woof is in place! Awesome! Let us get this show on the road...\n'

confirm='false'
while [ $confirm == 'false' ]
do
   echo "Tell me where you want Woof to be installed (just hit Enter if you do not care - I will put it in $HOME/.woof/ then):"
   read path

   if [ "$path" == '' ]; then
      path="$HOME/.woof/"
   fi

   #check if path already exists and give the choice to change it
   while [ -d $path ]
   do
      echo "$path already exists. Are you updating your Woof-installation? Do you want to overwrite the old files? [yes/no/cancel]"
      read inst

      while [ "$inst" != 'yes' ] && [ "$inst" != 'ye' ] && [ "$inst" != 'y' ] && [ "$inst" != 'no' ] && [ "$inst" != 'n' ] && [ "$inst" != 'cancel' ] && [ "$inst" != 'cance' ] && [ "$inst" != 'canc' ] && [ "$inst" != 'can' ] && [ "$inst" != 'ca' ] && [ "$inst" != 'c' ]
      do
         echo 'Please answer with yes, no or cancel'
         read inst
      done

      if [ "$inst" == 'no' ] || [ "$inst" == 'n' ]; then
         echo "Tell me where you want Woof to be installed (just hit Enter if you do not care - I will put it in $HOME/.woof/ then):"
         read path

         if [ "$path" == '' ]; then
            path="$HOME/.woof/"
         fi
      elif [ "$inst" == 'yes' ] || [ "$inst" == 'ye' ] || [ "$inst" == 'y' ]; then
         break
      else
         echo 'Aborted'
         exit 1
      fi
   done

   #ask for final confirmation - Might skip this step. Ponder about it some more.
   echo "Woof will now be installed to $path. Shall I continue? [yes/no/cancel]"
   read cont

   while [ "$cont" != 'yes' ] && [ "$cont" != 'ye' ] && [ "$cont" != 'y' ] && [ "$cont" != 'no' ] && [ "$cont" != 'n' ] && [ "$cont" != 'cancel' ] && [ "$cont" != 'cance' ] && [ "$cont" != 'canc' ] && [ "$cont" != 'can' ] && [ "$cont" != 'ca' ] && [ "$cont" != 'c' ]
   do
      echo 'Please answer with yes, no or cancel'
      read cont
   done

   if [ "$cont" == 'no' ] || [ "$cont" == 'n' ]; then
      confirm='false'
   elif [ "$cont" == 'yes' ] || [ "$cont" == 'ye' ] || [ "$cont" == 'y' ]; then
      confirm='true'
   else
      echo 'Aborted'
      exit 1
   fi
done

echo "Installing to $path ..."

# For now it is not possible to create a path of folders
if [ ! -d $path ]; then
   sudo mkdir $path
fi

# Delete trailing slash from path-variable
if [[ $path == */ ]]; then
   path=$(echo $path|sed 's/.$//')
fi

#copy the most important files
sudo cp woof $path/woof
sudo chmod +x $path/woof

# Setup symlinks. Should "Share" and "Receive" become shorthandles for the terminal some day? 
# BUG: Install currently complains that the symlink already exists if Woof was installed before. Users should not get this message at all!
sudo ln -s $path/woof /usr/bin/woof

# Discover active desktop-environment
desktop_gnome=`eval ps -e | grep gnome-session`
desktop_kde3=`eval ps -e | grep kdesktop`
desktop_kde4=`eval ps -e | grep plasma`
if [[ $desktop_gnome != '' ]]; then 
   environment='gnome'
elif [ $desktop_kde3 != '' ] || [ $desktop_kde4 != '' ]; then
   environment='kde'  
else
   environment='unknown'
fi

# Copy service-menu entries to file-manager according to desktop-environment
# BUG: ALL desktop-handles (KDE's.desktop and Gnome-scripts) should get a chown for the active user into who's home-directory we're writing
if [ $environment == 'kde' ] || [ $environment == 'gnome' ] ; then
   sudo cp woof.png /usr/share/icons/woof.png #Copy application-icon
   if [ $environment == 'kde' ]; then # If we're in KDE, please check for available file-managers
      echo "I have found an active KDE desktop... installing respective files..."
      if [ -d /usr/share/apps/konqueror/servicemenus/ ]; then
         sudo cp woof.desktop /usr/share/apps/konqueror/servicemenus/woof.desktop
         echo "Installation successful! Thank you for using Woof!"
      fi
      if [ -d /usr/share/apps/d3lphin/servicemenus/ ]; then
         sudo cp woof.desktop /usr/share/apps/d3lphin/servicemenus/woof.desktop
         echo "Installation successful! Thank you for using Woof!"
      fi
   fi
   if [ $environment == 'gnome' ]; then # If we're in Gnome, write to according file-manager
      echo "I have found an active Gnome desktop... installing respective files..."
      if [ -d $HOME/.gnome2/nautilus-scripts/ ]; then # Copy scripts over to Nautilus, change ownership to current user and set their execution-bit
         sudo cp Share $HOME/.gnome2/nautilus-scripts/Share
         sudo chown $actualuser:$actualuser $HOME/.gnome2/nautilus-scripts/Share
         sudo chmod +x $HOME/.gnome2/nautilus-scripts/Share
         sudo cp Receive $HOME/.gnome2/nautilus-scripts/Receive
         sudo chown $actualuser:$actualuser $HOME/.gnome2/nautilus-scripts/Receive
         sudo chmod +x $HOME/.gnome2/nautilus-scripts/Receive
         echo "Installation successful! Thank you for using Woof!" 
      fi      
   fi
   if [ $environment == 'unknown' ]; then # If it's an unknown desktop-environment
      echo "Oops! Sorry, that should not have happened! I was unable to find out about your desktop-environment! If you are running Gnome or KDE, please report this as a bug at https://bugs.launchpad.net/woofgui. Thank you for your help!"
   fi
fi