summaryrefslogtreecommitdiff
path: root/kanotix/enable_persistent_live.bash
blob: 0d29e0007215e1ca1fa0259d03e0e454dac468d8 (plain)
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
#!/bin/bash
# This script automatically configures your Live-USB-Stick to be persistent
# 
# Written by Andreas Loibl <andreas@andreas-loibl.de>
KDIALOG="$(which kdialog)"                      || KDIALOG="/usr/bin/kdialog"
ZENITY="$(which zenity)"                        || ZENITY="/usr/bin/zenity"

partition=3
filesystem=ext4

. /etc/default/distro
isodev="$(awk '{if($2=="/live/image"||$2=="/lib/live/mount/medium"||$2=="/run/live/medium"){print $1;}}' /proc/mounts)"
case $isodev in
/dev/sd*) ;;
*) isodev= ;;
esac
case "$( ls /grub.cmdline 2>/dev/null)" in
/grub.cmdline)
if [ -x "$KDIALOG" ]; then
    $KDIALOG --error "Persistent mode seems to be enabled already!" --title "Persistent Live-USB-Stick"
elif [ -x "$ZENITY" ]; then
    $ZENITY --error --text "Persistent mode seems to be enabled already!" --title "Persistent Live-USB-Stick"
fi
exit 1
;;
esac

if [ -d "/run/live/persistence" ]; then
if [ -x "$KDIALOG" ]; then
    $KDIALOG --error "Persistent mode seems to be enabled already!" --title "Persistent Live-USB-Stick"
elif [ -x "$ZENITY" ]; then
    $ZENITY --error --text "Persistent mode seems to be enabled already!" --title "Persistent Live-USB-Stick"
fi
exit 1
fi

if [ "$FLL_DISTRO_MODE" != "live" -o -z "$isodev" ]; then
if [ -x "$KDIALOG" ]; then
    $KDIALOG --error "This script can only be used from a Live USB-Stick!" --title "Persistent Live-USB-Stick"
elif [ -x "$ZENITY" ]; then
        $ZENITY --error --text "This script can only be used from a Live USB-Stick!" --title "Persistent Live-USB-Stick"
fi
exit 1
fi

if ((UID)); then
if [ -x "$KDIALOG" ]; then
$KDIALOG --warningcontinuecancel "This script automatically configures your Live-USB-Stick to be persistent:

* it adds a new partition into the unused space of your stick
* formats the partition with $filesystem filesystem
* writes config files to the new partition

===============================================================
CURRENT CHANGES ARE NOT STORED, YOU HAVE TO REBOOT TO ENABLE PERSISTENCE!
===============================================================

Press \"Continue\" when you are ready to start.

" --title "Persistent Live-USB-Stick" || exit 0
elif [ -x "$ZENITY" ]; then

$ZENITY --question --text "This script automatically configures your Live-USB-Stick to be persistent:

* it adds a new partition into the unused space of your stick
* formats the partition with $filesystem filesystem
* writes config files to the new partition

===============================================================
CURRENT CHANGES ARE NOT STORED, YOU HAVE TO REBOOT TO ENABLE PERSISTENCE!
===============================================================

Press \"Continue\" when you are ready to start.

" --title "Persistent Live-USB-Stick" || exit 0
fi
cp "$0" "/tmp/$(basename "$0")"
chmod +x "/tmp/$(basename "$0")"
if [ -x "$KDIALOG" ]; then
$KDIALOG --progressbar "Please wait..." --title "Persistent Live-USB-Stick" 0
sudo "/tmp/$(basename "$0")" "$@"
elif [ -x "$ZENITY" ]; then
sudo "/tmp/$(basename "$0")" "$@" | $ZENITY --progress --pulsate --text "Please wait..." --title "Persistent Live-USB-Stick" 0
fi

exit $?
fi

exec >/tmp/persistent.log 2>&1
set -x

. /usr/share/acritoxinstaller/modules/partitions
isodisk="$(get_disk $isodev)"
is_removeable "$isodisk" || exit 1

nop() { return 0; }
trap nop TERM KILL HUP

# Debug output
set -x

if [ ! -e "$isodisk"$partition ]; then
	# Add partition
	echo "n|p|$partition|||w" | tr '|' '\n' | fdisk "$isodisk" 
	partprobe "$isodisk"
	while [ ! -e "$isodisk"$partition ]; do sleep 1; done
	mkfs.$filesystem -L "persistence" "$isodisk"$partition
fi

if [ -d /run/live/medium ]; then
    mkdir -p /run/live/persistence
    mount "$isodisk"$partition /run/live/persistence
    set -- $(cat /proc/cmdline)
    shift
    echo "set persistence_cmdline='$@ persistence'" > /run/live/persistence/grub.cmdline
    echo "/ union" > /run/live/persistence/persistence.conf
    umount /run/live/persistence
    rmdir /run/live/persistence

else

if [ -d /lib/live/mount ]; then
    mkdir -p /lib/live/mount/persistence
    mount "$isodisk"$partition /lib/live/mount/persistence
    set -- $(cat /proc/cmdline)
    shift
    echo "set persistence_cmdline='$@ persistence'" > /lib/live/mount/persistence/grub.cmdline
    echo "/ union" > /lib/live/mount/persistence/persistence.conf
    umount /lib/live/mount/persistence
    rmdir /lib/live/mount/persistence
elif [ -d /live ]; then
    mkdir -p /live/persistence
    mount "$isodisk"$partition /live/persistence
    set -- $(cat /proc/cmdline)
    shift
    echo "set persistence_cmdline='$@ persistence'" > /live/persistence/grub.cmdline
    echo "/ union" > /live/persistence/persistence.conf
    umount /live/persistence
    rmdir /live/persistence
fi
fi
#killall -9 kdialog
kill $(ps ax | grep kdialog | grep Live-USB | cut -c2-5)
killall -9 kdialog_progress_helper
exit 0