File indexing completed on 2024-04-28 04:48:05

0001 #!/usr/bin/env bash
0002 #set -x 
0003 
0004 ############################################################################
0005 # Disassemble an Amarok LiveCD iso file into a specified directory
0006 # for the purpose of adding a users own music and putting it back together
0007 #
0008 # Based on a script authored by Ivan Kerekes <ikerekes@gmail.com>
0009 # and modified by Leo Franchi <lfranchi at gmaildotcom>, Mike Diehl 
0010 # <madpenguin8 at yahoodotcom> and Greg Meyer <greg at gkmwebdotcom> 
0011 #
0012 # See the file called README for more information
0013 ############################################################################
0014 #
0015 # This program is free software; you can redistribute it and/or modify
0016 # it under the terms of the GNU General Public License as published by
0017 # the Free Software Foundation; either version 2 of the License, or
0018 # (at your option) any later version.
0019 #
0020 ############################################################################
0021 
0022 
0023 cleanup () {
0024     rm -rf $WORK/mklivecd
0025     rm -rf $WORK/amarok.live
0026     rm -rf $WORK/livecd_data*
0027 }
0028 
0029 # We need to be root to mount the loopback
0030 # check for root and exit if not
0031 
0032 if [ `/usr/bin/whoami` = 'root' ]; then
0033 
0034 iso=$2
0035 
0036 if [ $iso = 0 ] ; then
0037     exit
0038 fi
0039 
0040 WORK=$1
0041 
0042 if [ $WORK = 0 ] ; then
0043     exit
0044 fi
0045 
0046 # Determine if enough space
0047 
0048 redo=0
0049 enough=0
0050 tmp=$WORK
0051 while [ "$redo" = "0" ]; do
0052     while [ "$enough" = "0" ]; do # loops until found something
0053         if [[ -n  `df | grep $tmp` ]] ; then # we got it in df, find the space left
0054             anotmp=`df | grep $tmp |  sed "s~^\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\)$~\4~"`  # now we have a string, first item is free space in /
0055             free=`echo $anotmp  | sed "s~^\([^ ]*\) \(.*\)~\1~"` # get first space-delimited item
0056 #                       echo "comparing" $free "to 1572864"
0057             if [[ $free -gt 1572864 ]] ; then
0058                 enough=1
0059                 redo=1
0060                 break
0061             else
0062                 dcop --all-users amarok playlist popupMessage "Not enough free space. Please select another folder."
0063                 break
0064             fi
0065         else
0066             res=`echo "$tmp" | sed "s~/\(.*\)/\([^/]*\)$~/\1~"`
0067             if [[ "$tmp" = "$res" ]]; then # last one, regexp fails here
0068                 tmp="/"
0069             else #normal, removes one dir from path
0070                 tmp=$res
0071             fi
0072 #            echo "new tmp: " $tmp
0073         fi
0074     done
0075     if [[ "$redo" = "0" ]]; then
0076         WORK=`kdialog --title "Choose working directory" --getexistingdirectory .`
0077                 tmp=$WORK
0078                 if [[ "$?" == 0 ]]; then
0079                         break
0080         else
0081            exit 
0082                 fi
0083                 enough=0
0084     fi
0085 done
0086 
0087 #Mount the iso if not already mounted
0088 if [ ! -d "$DATADIR" ]; then
0089    DATADIR=$WORK/livecd_data$$
0090    mkdir -p "$DATADIR"
0091    mount -o loop "$iso" "$DATADIR"
0092 fi
0093 
0094 # Make the working directories and blow out the initrd.gz into a separate directory 
0095  
0096 mkdir -p $WORK/mklivecd/livecd
0097 cp -a --preserve "$DATADIR"/* $WORK/mklivecd/livecd/
0098 mkdir -p $WORK/mklivecd/initrd.dir
0099 mkdir -p $WORK/mklivecd/initrd.mnt
0100 gunzip -c $WORK/mklivecd/livecd/isolinux/initrd.gz > $WORK/mklivecd/livecd/isolinux/initrd
0101 mount -o loop $WORK/mklivecd/livecd/isolinux/initrd $WORK/mklivecd/initrd.mnt
0102 (cd $WORK/mklivecd/initrd.mnt ; tar cf - .) | (cd $WORK/mklivecd/initrd.dir ; tar xf -)
0103 umount $WORK/mklivecd/initrd.mnt
0104 rm -f $WORK/mklivecd/livecd/isolinux/initrd
0105 
0106 
0107 # cleanup all temporary files and directories
0108 
0109 umount "$DATADIR" 2>/dev/null >/dev/null
0110 if [ "$?" = "0" ]; then rmdir $DATADIR; fi
0111 
0112 # at this point we unsquash the fs so the user can add their own music
0113 
0114 if [[  `cat /proc/filesystems | grep squash | wc -l` = 0 ]]; then
0115         modprobe squashfs
0116         if [[  `cat /proc/filesystems | grep squash | wc -l` = 0 ]]; then
0117 
0118          dcop --all-users amarok playlist popupMessage "You do not have squashfs support enabled. You need to have a patched kernel with squashfs. You can find more info about squashfs, and how to patch your kernel, here: http://tldp.org/HOWTO/SquashFS-HOWTO/"
0119         
0120                 rm -rf $WORK/mklivecd
0121         fi
0122 fi
0123 
0124 mkdir $WORK/amarok.livecd/
0125 mount -o loop -t squashfs $WORK/mklivecd/livecd/livecd.sqfs $WORK/amarok.livecd/
0126 
0127 # gotta copy it locally so the user can add files to it
0128 
0129 mkdir $WORK/amarok.live/
0130 dcop --all-users amarok playlist shortStatusMessage "Copying files now. Please be patient, this step takes a long time."
0131 #echo
0132 #echo "Please wait, copying in progress."
0133 #echo
0134 cp -a $WORK/amarok.livecd/* $WORK/amarok.live/
0135 umount $WORK/amarok.livecd/
0136 rmdir $WORK/amarok.livecd
0137 
0138 mkdir $WORK/amarok.live/home/amarok/.kde/share/apps/amarok/playlists
0139 chown 500:500 $WORK/amarok.live/home/amarok/.kde/share/apps/amarok/playlists
0140 find $WORK/amarok.live/home/amarok/.kde/share/apps/ -type d -print0 | xargs -0 chmod +x
0141 chmod -R 777 $WORK/amarok.live/music/
0142 chmod -R 777 $WORK/amarok.live/home/amarok/.kde/share/apps/amarok
0143 #chmod -R 777 $WORK/mklivecd/
0144 
0145 dcop --all-users amarok playlist popupMessage "Copying done. To add music to the Amarok livecd, select the tracks you wish to add in the playlist, and select \"Add to livecd\" from the right click menu. Please do not add more than about 380 mb, as then the resulting ISO will be too large to fit on a CD-ROM. Once you are done, select Create Remastered CD. Enjoy!"
0146 
0147 else 
0148 
0149 kdialog --title "Amarok livecd remaster" --sorry "You must run this script as root. Try running 'kdesu sh amarok.live.remaster.part1.sh' instead."
0150 
0151 fi