head     1.1;
branch   1.1.1;
access   ;
symbols  klik-booyo:1.1.1.1 probono:1.1.1;
locks    ; strict;
comment  @# @;


1.1
date     2005.05.23.08.10.44;  author tcheun1;  state Exp;
branches 1.1.1.1;
next     ;

1.1.1.1
date     2005.05.23.08.10.44;  author tcheun1;  state Exp;
branches ;
next     ;


desc
@@



1.1
log
@Initial revision
@
text
@#!/bin/sh

#
# klik 0.5 installer w/ cmg support
# point-and-klik software installation
# by probono at myrealbox dot com
# thanks for valuable help from bfree
#

# store the dir to return to it
ORIGDIR=$(pwd)
cd $HOME

if [ -z "$DIALOG" ] ; then
# Determine which dialog to use in which situation:
# Xdialog (in all other cases)
export DIALOG=Xdialog
# kdialog (in case there is no console available and we are running KDE)
( ps -e 2>/dev/null | grep kdeinit >/dev/null 2>&1 ) && export DIALOG=kdialog 
# dialog (in case there is a console available)
GUIMODE=$(tty)
( echo $GUIMODE | grep /dev/tty[:digit:] >/dev/null ) && export DIALOG=dialog
fi

# Setup defaults for whatever dialog we are using
case $DIALOG in
 kdialog)
 DIALOG_OPTIONS=" --caption klik" ;
 KLIKDIR=":klikdir" ;;
 Xdialog|dialog)
 DIALOG_H=12
 DIALOG_W=60
 DIALOG_OPTIONS=" $DIALOG_H $DIALOG_W" ;
 KLIKDIR="~" ;;
esac

dmsgbox(){
 $DIALOG --msgbox "$1" $DIALOG_OPTIONS
}
dyesno(){
 $DIALOG --yesno "$1" $DIALOG_OPTIONS
}
dwarningyesno(){
 case $DIALOG in
 kdialog)
  $DIALOG --warningyesno "$1" $DIALOG_OPTIONS 
 ;;
 Xdialog|dialog)
  $DIALOG --yesno "Warning: $1" $DIALOG_OPTIONS 
 ;;
 esac
}
derror(){
 case $DIALOG in
 kdialog)
 $DIALOG --error "$1" $DIALOG_OPTIONS 
 ;;
 Xdialog|dialog)
 $DIALOG --msgbox "ERROR: $1" $DIALOG_OPTIONS 
 ;;
 esac
}

cat > $HOME/.klik <<\EOF
#!/bin/sh

# klik client 0.2
# point-and-klik KDE software installation
# by probono at myrealbox dot com
# thanks to bfree for non-KDE part

# try to get the human-readable version of the host OS
export VERSION=$(cat /etc/*-version 2>/dev/null | head -n 1)

#
# support different types of dialog, thanks bfree
#

if [ -z "$DIALOG" ] ; then
# Determine which dialog to use in which situation:
# Xdialog (in all other cases)
DIALOG=Xdialog
# kdialog (in case there is no console available and we are running KDE)
( ps -e 2>/dev/null | grep kdeinit >/dev/null 2>&1 ) &&  DIALOG=kdialog 
# dialog (in case there is a console available)
GUIMODE=$(tty)
( echo $GUIMODE | grep /dev/tty[:digit:] >/dev/null ) && DIALOG=dialog
fi

# Setup defaults for whatever dialog we are using
case $DIALOG in
 kdialog)
 DIALOG_OPTIONS=" --caption klik" ;
 KLIKDIR=":klikdir" ;;
 Xdialog|dialog)
 DIALOG_H=12
 DIALOG_W=60
 DIALOG_OPTIONS=" $DIALOG_H $DIALOG_W" ;
 KLIKDIR="~" ;;
esac

dmsgbox(){
 $DIALOG --msgbox "$1" $DIALOG_OPTIONS
}
dyesno(){
 $DIALOG --yesno "$1" $DIALOG_OPTIONS
}
dwarningyesno(){
 case $DIALOG in
 kdialog)
  $DIALOG --warningyesno "$1" $DIALOG_OPTIONS 
 ;;
 Xdialog|dialog)
  $DIALOG --yesno "Warning: $1" $DIALOG_OPTIONS 
 ;;
 esac
}
derror(){
 case $DIALOG in
 kdialog)
 $DIALOG --error "$1" $DIALOG_OPTIONS 
 ;;
 Xdialog|dialog)
 $DIALOG --msgbox "ERROR: $1" $DIALOG_OPTIONS 
 ;;
 esac
}
dexistingdir(){
 case $DIALOG in
 kdialog)
 $DIALOG --getexistingdirectory $KLIKDIR $DIALOG_OPTIONS 
 ;;
 Xdialog)
 $DIALOG --dselect $KLIKDIR $DIALOG_OPTIONS 
 ;;
 dialog)
 $DIALOG --fselect $KLIKDIR $DIALOG_OPTIONS
 ;;
 esac
}

export RUN=`echo $1 | sed s@@klik:\/\/@@@@` && (wget -q http://klik.atekon.de/apt/?package=$RUN -U "klik/0.1.3cli (`uname -a` @@$VERSION@@)" -O - | sh || derror "Error while trying to run $RUN" )

EOF
chmod 700 ~/.klik

#
# create helper protocol for konqueror to send klicks to the klik script
#

cat > $HOME/.kde/share/services/klik.protocol <<EOF
# klik 0.2
# helper protocol for konqueror to send klicks to the klik script
# by probono
[Protocol]
exec=$HOME/.klik '%u'
protocol=klik
input=none
output=none
helper=true
listing=false
reading=false
writing=false
makedir=false
deleting=false
icon=package
Description=klik
EOF

#
# create ~/.kde/share/applnk/klik
#

mkdir -p  $HOME/.kde/share/applnk/klik

cat > $HOME/.kde/share/applnk/klik/.directory <<EOF
[Desktop Entry]
Encoding=UTF-8
Name=Applications (installed by klik)
Name[de]=Programme (installiert mit klik)
Icon=rebuild
#package_applications
EOF

#
# link to the store
#

cat > $HOME/.kde/share/applnk/klik/klik.desktop <<EOF
[Desktop Entry]
Encoding=UTF-8
Exec=konqueror http://klik.atekon.de?from=profile
Icon=package_network
Name=Install more software...
Name[de]=Weitere Software installieren...
EOF


#
# set klik protocol handler in Mozilla (tested with Firefox 0.9.3)
#

PROFILES=$(find $HOME/.mozilla/ | grep prefs.js$)
if [ -z "$PROFILES" ]
then
dmsgbox "You need to start the mozilla/firefox browser once before running the klik installer if you want it to support klik.  If you do not use mozilla/firefox you can ignore this message.  If you plan on using mozilla/firefox with klik please run and exit the browser and then install klik again."
else
for i in $PROFILES
do
	USERJS="$(dirname "$i")/user.js"
	( cat $USERJS 2>/dev/null | grep "klik" >/dev/null 2>&1 ) || ( echo "user_pref(\"network.protocol-handler.app.klik\", \"~/.klik\");" >> $USERJS )
done

( ps -d | grep mozilla ) && dmsgbox "You need to restart Mozilla/Firefox before you will be able to use klik there."
fi

#
# Add support for the klik protocol to elinks
#
[ -e $HOME/.elinks ] || mkdir $HOME/.elinks
[ -e $HOME/.elinks/elinks.conf ] || touch $HOME/.elinks/elinks.conf
cat >> $HOME/.elinks/elinks.conf <<EOF

## protocol
## protocol.user 
## protocol.user.klik 
## protocol.user.klik._template_ <str> 
set protocol.user.klik._template_ = "" 
## protocol.user.klik.unix <str> 
set protocol.user.klik.unix = "~/.klik %h" 
## protocol.user.klik.unix-xwin <str> 
set protocol.user.klik.unix-xwin = "~/.klik %h"
EOF

#
DESCRIPTION="EXPERIMENTAL implementation of cmg-compressed AppDirs (AppImages, really) for klik. Using this technology, every app is contained inside one file that is mounted and unmounted transparently on demand."
#

mkdir -p $HOME/.kde/share/mimelnk/all
cat > $HOME/.kde/share/mimelnk/all/cmg.desktop <<\EOF
[Desktop Entry]
Comment=
Hidden=false
Icon=view_remove
MimeType=all/cmg
Patterns=*.cmg
Type=MimeType
EOF

mkdir -p $HOME/.kde/share/applnk/.hidden
cat > $HOME/.kde/share/applnk/.hidden/AppRun.desktop<<\EOF
[Desktop Entry]
Comment=
Exec=$HOME/.zAppRun %U
Icon=view_remove
InitialPreference=2
MimeType=all/cmg;Application
Name=
ServiceTypes=
Terminal=false
Type=Application
EOF

cat > $HOME/.zAppRun <<\EOF
#!/bin/sh

# by probono at myrealbox dot com
# thanks to bfree
# GPL

#
# ok we need dialogs now
#
if [ -z "$DIALOG" ] ; then
# Determine which dialog to use in which situation:
# Xdialog (in all other cases)
export DIALOG=Xdialog
# kdialog (in case there is no console available and we are running KDE)
( ps -e 2>/dev/null | grep kdeinit >/dev/null 2>&1 ) && export DIALOG=kdialog 
# dialog (in case there is a console available)
GUIMODE=$(tty)
( echo $GUIMODE | grep /dev/tty[:digit:] >/dev/null ) && export DIALOG=dialog
fi

# Setup defaults for whatever dialog we are using
case $DIALOG in
 kdialog)
 DIALOG_OPTIONS=" --caption klik" ;
 KLIKDIR=":klikdir" ;;
 Xdialog|dialog)
 DIALOG_H=12
 DIALOG_W=60
 DIALOG_OPTIONS=" $DIALOG_H $DIALOG_W" ;
 KLIKDIR="~" ;;
esac

derror(){
 case $DIALOG in
 kdialog)
 $DIALOG --error "$1" $DIALOG_OPTIONS 
 ;;
 Xdialog|dialog)
 $DIALOG --msgbox "ERROR: $1" $DIALOG_OPTIONS 
 ;;
 esac
}

# check fstab and warn if neccessary entries are not there
# better use /media/klik according to FSH?
if [ -z "$(cat /etc/fstab | grep app/7)" ]
then
  derror "Your /etc/fstab is not yet prepared for mounting .cmg images. 
  As root, please make /mnt/app writeable and add the following lines:
  
  ################################################################
/mnt/app/1/image /mnt/app/1 cramfs,iso9660 user,noauto,ro,loop,exec 0 0
/mnt/app/2/image /mnt/app/2 cramfs,iso9660 user,noauto,ro,loop,exec 0 0
/mnt/app/3/image /mnt/app/3 cramfs,iso9660 user,noauto,ro,loop,exec 0 0
/mnt/app/4/image /mnt/app/4 cramfs,iso9660 user,noauto,ro,loop,exec 0 0
/mnt/app/5/image /mnt/app/5 cramfs,iso9660 user,noauto,ro,loop,exec 0 0
/mnt/app/6/image /mnt/app/6 cramfs,iso9660 user,noauto,ro,loop,exec 0 0
/mnt/app/7/image /mnt/app/7 cramfs,iso9660 user,noauto,ro,loop,exec 0 0
################################################################"
  exit 1
fi

# rewrite cmdline to use absolute instead of relative paths, thanks bfree
NEWCMD=$(perl -e '$newcmd=shift(@@ARGV);foreach $arg (@@ARGV){ @@part=split(/\=/,$arg); foreach $part (@@part){ (-e "$ENV{PWD}/$part") && ($part="$ENV{PWD}/$part");}$newcmd.=" ".join ("=",@@part);} print "$newcmd";' $@@)
set -- $NEWCMD

# if no arguments are passed and 
# there is a .cmg in the same directory as this
# script, then use the .cmg
DIRNAME=$(dirname $0)
if [ -z $1 ]
then
  CMG=$(find "$DIRNAME" -iname '*.cmg'|head -n 1) || exit 1
  echo "Found $CMG, using it"
else
  CMG="$1"
  shift
fi

# make path to CMG absolute, thanks bfree
case $CMG in
/*) ;; 
*) CMG=$(pwd)/$CMG ;; 
esac

# determine which filesystem is used as .cmg
file $CMG | grep ": data" >/dev/null && FS=squash # who knows a better way to recognize it?
file $CMG | grep "Compressed ROM" >/dev/null && FS=cram
file $CMG | grep "ISO 9660" >/dev/null && FS=iso

if [ -n "$FS" ]
then
  NUMBERS="7 6 5 4 3 2 1"
  for NUMBER in $NUMBERS
    do
    [ -e "/mnt/app/$NUMBER" ] || MNTNUM=$NUMBER
  done
  case $FS in
    squash) MOUNT=/mnt/squash/$MNTNUM ;;
    *) MOUNT=/mnt/app/$MNTNUM ;;
  esac
  mkdir -p $MOUNT || exit 1
  ln -s $CMG $MOUNT/image || exit 1
  mount $MOUNT || derror "Unable to mount $MOUNT"
else
  # NOTE: exit now cause our cmg isn't mounted
  derror "$CMG does not appear to be either a squashfs, iso9660 or a cramfs file"
  exit 1
fi
    
  #
  # execute the wrapper
  # the wrapper should take care to keep running until its app closes
  #
  
  # we need this so that on the cmdline, pipes etc work
  CMDLINE="yes"
  ( tty | grep ^/dev/tty >/dev/null ) && CMDLINE=""
  ( tty | grep ^/dev/pts >/dev/null ) && CMDLINE=""
  if [ "$CMDLINE" = "yes" ] ; then
    RESULT=$($MOUNT/wrapper $@@ 2>&1) || error "$RESULT" 
  else
    $MOUNT/wrapper $@@
  fi

  # kill all child processes
  kill $(pidof -x -o %PPID) 2>/dev/null
  
  # unmount and clean up
  umount $MOUNT
  rm -f $MOUNT/cramfs
  rm -r $MOUNT/

EOF

chmod 777 $HOME/.zAppRun 

#
# Create the script for root to install cmg support
#

if [ -z "$(cat /etc/fstab | grep app/7)" ]
then

cat > "$HOME/klik-cmg-install-root" <<EOF
#!/bin/sh
echo >> /etc/fstab "
/mnt/app/1/image /mnt/app/1 cramfs,iso9660 user,noauto,ro,loop,exec 0 0
/mnt/app/2/image /mnt/app/2 cramfs,iso9660 user,noauto,ro,loop,exec 0 0
/mnt/app/3/image /mnt/app/3 cramfs,iso9660 user,noauto,ro,loop,exec 0 0
/mnt/app/4/image /mnt/app/4 cramfs,iso9660 user,noauto,ro,loop,exec 0 0
/mnt/app/5/image /mnt/app/5 cramfs,iso9660 user,noauto,ro,loop,exec 0 0
/mnt/app/6/image /mnt/app/6 cramfs,iso9660 user,noauto,ro,loop,exec 0 0
/mnt/app/7/image /mnt/app/7 cramfs,iso9660 user,noauto,ro,loop,exec 0 0
"
if ! [ -e /mnt/app ]
then
mkdir /mnt/app
chmod 0777 /mnt/app
#dmsgbox "/mnt/app has been created so it can be used by anyone. You may want to make /mnt/app only writable by one group (like users) which you could do with: \nchgrp users /mnt/app \nchmod 770 /mnt/app\"
fi
EOF
chmod 777 "$HOME/klik-cmg-install-root"

(sudo sh "$HOME/klik-cmg-install-root" && rm -f "$HOME/klik-cmg-install-root") || (dmsgbox "Your /etc/fstab is not setup to use cmg files. Please run $HOME/klik-cmg-install-root as root.") 
fi

#
#
#

case $DIALOG in
Xdialog) BROWSER="firefox http://klik.atekon.de?from=profile" ;;
dialog) BROWSER="elinks http://klik.atekon.de?from=profile" ;;
*) BROWSER="konqueror http://klik.atekon.de?from=profile" ;;
esac

kbuildsycoca 2>/dev/null
dmsgbox "Now you can start installing software. \n Opening the klik point-and-klik software store..." && $BROWSER

cd $ORIGDIR@


1.1.1.1
log
@initial klik
@
text
@@
