Add nice svg graphics to the playlist, based on the work of fapasv ( http://kde-look...
[amarok.git] / supplementary_scripts / amarok_live / amarok.live.remaster.part1.sh
blob2ae79905934ef2094f4e780d71c2b6df6f5508d7
1 #!/usr/bin/env bash
2 #set -x
4 ############################################################################
5 # Disassemble an Amarok LiveCD iso file into a specified directory
6 # for the purpose of adding a users own music and putting it back together
8 # Based on a script authored by Ivan Kerekes <ikerekes@gmail.com>
9 # and modified by Leo Franchi <lfranchi at gmaildotcom>, Mike Diehl
10 # <madpenguin8 at yahoodotcom> and Greg Meyer <greg at gkmwebdotcom>
12 # See the file called README for more information
13 ############################################################################
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2 of the License, or
18 # (at your option) any later version.
20 ############################################################################
23 cleanup () {
24 rm -rf $WORK/mklivecd
25 rm -rf $WORK/amarok.live
26 rm -rf $WORK/livecd_data*
29 # We need to be root to mount the loopback
30 # check for root and exit if not
32 if [ `/usr/bin/whoami` = 'root' ]; then
34 iso=$2
36 if [ $iso = 0 ] ; then
37 exit
40 WORK=$1
42 if [ $WORK = 0 ] ; then
43 exit
46 # Determine if enough space
48 redo=0
49 enough=0
50 tmp=$WORK
51 while [ "$redo" = "0" ]; do
52 while [ "$enough" = "0" ]; do # loops until found something
53 if [[ -n `df | grep $tmp` ]] ; then # we got it in df, find the space left
54 anotmp=`df | grep $tmp | sed "s~^\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\)$~\4~"` # now we have a string, first item is free space in /
55 free=`echo $anotmp | sed "s~^\([^ ]*\) \(.*\)~\1~"` # get first space-delimited item
56 # echo "comparing" $free "to 1572864"
57 if [[ $free -gt 1572864 ]] ; then
58 enough=1
59 redo=1
60 break
61 else
62 dcop --all-users amarok playlist popupMessage "Not enough free space. Please select another folder."
63 break
65 else
66 res=`echo "$tmp" | sed "s~/\(.*\)/\([^/]*\)$~/\1~"`
67 if [[ "$tmp" = "$res" ]]; then # last one, regexp fails here
68 tmp="/"
69 else #normal, removes one dir from path
70 tmp=$res
72 # echo "new tmp: " $tmp
74 done
75 if [[ "$redo" = "0" ]]; then
76 WORK=`kdialog --title "Choose working directory" --getexistingdirectory .`
77 tmp=$WORK
78 if [[ "$?" == 0 ]]; then
79 break
80 else
81 exit
83 enough=0
85 done
87 #Mount the iso if not already mounted
88 if [ ! -d "$DATADIR" ]; then
89 DATADIR=$WORK/livecd_data$$
90 mkdir -p "$DATADIR"
91 mount -o loop "$iso" "$DATADIR"
94 # Make the working directories and blow out the initrd.gz into a separate directory
96 mkdir -p $WORK/mklivecd/livecd
97 cp -a --preserve "$DATADIR"/* $WORK/mklivecd/livecd/
98 mkdir -p $WORK/mklivecd/initrd.dir
99 mkdir -p $WORK/mklivecd/initrd.mnt
100 gunzip -c $WORK/mklivecd/livecd/isolinux/initrd.gz > $WORK/mklivecd/livecd/isolinux/initrd
101 mount -o loop $WORK/mklivecd/livecd/isolinux/initrd $WORK/mklivecd/initrd.mnt
102 (cd $WORK/mklivecd/initrd.mnt ; tar cf - .) | (cd $WORK/mklivecd/initrd.dir ; tar xf -)
103 umount $WORK/mklivecd/initrd.mnt
104 rm -f $WORK/mklivecd/livecd/isolinux/initrd
107 # cleanup all temporary files and directories
109 umount "$DATADIR" 2>/dev/null >/dev/null
110 if [ "$?" = "0" ]; then rmdir $DATADIR; fi
112 # at this point we unsquash the fs so the user can add their own music
114 if [[ `cat /proc/filesystems | grep squash | wc -l` = 0 ]]; then
115 modprobe squashfs
116 if [[ `cat /proc/filesystems | grep squash | wc -l` = 0 ]]; then
118 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/"
120 rm -rf $WORK/mklivecd
124 mkdir $WORK/amarok.livecd/
125 mount -o loop -t squashfs $WORK/mklivecd/livecd/livecd.sqfs $WORK/amarok.livecd/
127 # gotta copy it locally so the user can add files to it
129 mkdir $WORK/amarok.live/
130 dcop --all-users amarok playlist shortStatusMessage "Copying files now. Please be patient, this step takes a long time."
131 #echo
132 #echo "Please wait, copying in progress."
133 #echo
134 cp -a $WORK/amarok.livecd/* $WORK/amarok.live/
135 umount $WORK/amarok.livecd/
136 rmdir $WORK/amarok.livecd
138 mkdir $WORK/amarok.live/home/amarok/.kde/share/apps/amarok/playlists
139 chown 500:500 $WORK/amarok.live/home/amarok/.kde/share/apps/amarok/playlists
140 find $WORK/amarok.live/home/amarok/.kde/share/apps/ -type d -print0 | xargs -0 chmod +x
141 chmod -R 777 $WORK/amarok.live/music/
142 chmod -R 777 $WORK/amarok.live/home/amarok/.kde/share/apps/amarok
143 #chmod -R 777 $WORK/mklivecd/
145 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!"
147 else
149 kdialog --title "Amarok livecd remaster" --sorry "You must run this script as root. Try running 'kdesu sh amarok.live.remaster.part1.sh' instead."