Dash:
[t2.git] / package / base / stone / stone_mod_install.sh
blob0cfacf8c3dec992bdabcf5ef930850c54fb15985
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by scripts/Create-CopyPatch.
3 #
4 # T2 SDE: package/*/stone/stone_mod_install.sh
5 # Copyright (C) 2004 - 2021 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
7 #
8 # More information can be found in the files COPYING and README.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
16 part_mounted_action() {
17 if gui_yesno "Do you want to un-mount the filesystem on $1?"
18 then umount /dev/$1; fi
21 part_swap_action() {
22 if gui_yesno "Do you want to de-activate the swap space on $1?"
23 then swapoff /dev/$1; fi
26 part_mount() {
27 local dev=$1
28 local dir="/ /boot /home /srv /var"
29 [ -d /sys/firmware/efi ] && dir="${dir/boot/boot/efi}"
30 local d
31 for d in $dir; do
32 grep -q " /mnt${d%/} " /proc/mounts || break
33 done
34 gui_input "Mount device $dev on directory
35 (for example ${dir// /, }, ...)" "${d:-/}" dir
36 if [ "$dir" ]; then
37 dir="$(echo $dir | sed 's,^/*,,; s,/*$,,')"
38 # check if at least a rootfs / is already mounted
39 if [ -z "$dir" ] || grep -q " /mnt " /proc/mounts
40 then
41 mkdir -p /mnt/$dir
42 mount /dev/$dev /mnt/$dir
43 else
44 gui_message "Please mount a root filesystem first."
49 part_mkfs() {
50 local dev=$1
51 cmd="gui_menu part_mkfs 'Create filesystem on $dev'"
53 maybe_add () {
54 if #grep -q $1 /proc/filesystems &&
55 type -p $3 > /dev/null; then
56 cmd="$cmd '$1 ($2 filesystem)' \
57 'type wipefs 2>/dev/null && wipefs -a /dev/$dev; $3 $4 /dev/$dev'"
61 maybe_add btrfs 'Better, b-tree, CoW journaling' 'mkfs.btrfs' '-f'
62 maybe_add ext4 'journaling, extents' 'mkfs.ext4'
63 maybe_add ext3 'journaling' 'mkfs.ext3'
64 maybe_add ext2 'non-journaling' 'mkfs.ext2'
65 maybe_add jfs 'IBM journaling' 'mkfs.jfs'
66 maybe_add reiserfs 'journaling' 'mkfs.reiserfs'
67 maybe_add xfs 'Sgi journaling' 'mkfs.xfs' '-f'
68 maybe_add fat 'File Allocation Table' 'mkfs.fat'
70 eval "$cmd" && part_mount $dev
73 part_decrypt() {
74 local dev=$1
76 local dir="root home swap"
77 local d
78 for d in $dir; do
79 [ -e /dev/mapper/$dir ] || break
80 done
81 gui_input "Mount device $dev on directory
82 (for example ${dir// /, }, ...)" "${d:-/}" dir
83 if [ "$dir" ]; then
84 dir="$(echo $dir | sed 's,^/*,,; s,/*$,,')"
85 cryptsetup luksOpen --disable-locks /dev/$dev $dir
89 part_crypt() {
90 local dev=$1
91 cryptsetup luksFormat --disable-locks --type luks1 /dev/$dev || return
93 part_decrypt $dev
96 part_unmounted_action() {
97 gui_menu part "$1" \
98 "Mount an existing filesystem from the partition" \
99 "part_mount $1" \
100 "Create a filesystem on the partition" \
101 "part_mkfs $1" \
102 "Activate an existing swap space on the partition" \
103 "swapon /dev/$1" \
104 "Create a swap space on the partition" \
105 "mkswap /dev/$1; swapon /dev/$1" \
106 "Activate a LUKS encrypted partition" \
107 "part_decrypt $1" \
108 "Encrypt partition using LUKS cryptsetup" \
109 "part_crypt $1"
112 part_add() {
113 local action="unmounted" location="currently not mounted"
114 if grep -q "^/dev/$1 " /proc/swaps; then
115 action=swap; location="swap <no mount point>"
116 elif grep -q "^/dev/$1 " /proc/mounts; then
117 action=mounted
118 location="`grep "^/dev/$1 " /proc/mounts | cut -d ' ' -f 2 |
119 sed "s,^/mnt,," `"
120 [ "$location" ] || location="/"
123 # save partition information
124 disktype /dev/$1 > /tmp/stone-install
125 type="`grep /tmp/stone-install -v -e '^ ' -e '^Block device' \
126 -e '^Partition' -e '^---' |
127 sed -e 's/[,(].*//' -e '/^$/d' -e 's/ $//' | tail -n 1`"
128 size="`grep 'Block device, size' /tmp/stone-install |
129 sed 's/.* size \(.*\) (.*/\1/'`"
131 [ "$type" ] || type="undetected"
132 cmd="$cmd '`printf "%-6s %-24s %-10s" ${1#*/} "$location" "$size"` $type' 'part_${action}_action $1 $2'"
135 disk_action() {
136 if grep -q "^/dev/$1 " /proc/swaps /proc/mounts; then
137 gui_message "Partitions from $1 are currently in use, so you
138 can't modify this disks partition table."
139 return
142 cmd="gui_menu disk 'Edit partition table of $1'"
143 for x in parted cfdisk fdisk pdisk mac-fdisk; do
144 type -p $x > /dev/null &&
145 cmd="$cmd \"Edit partition table using '$x'\" \"$x /dev/$1\""
146 done
148 eval $cmd
151 vg_action() {
152 cmd="gui_menu vg 'Volume Group $1'"
154 if [ -d /dev/$1 ]; then
155 cmd="$cmd 'Display attributes of $1' 'gui_cmd \"display $1\" vgdisplay $1'"
157 if grep -q "^/dev/$1/" /proc/swaps /proc/mounts; then
158 cmd="$cmd \"LVs of $1 are currently in use, so you can't
159 de-activate it.\" ''"
160 else
161 cmd="$cmd \"De-activate VG '$1'\" 'vgchange -an $1'"
163 else
164 cmd="$cmd 'Display attributes of $1' 'gui_cmd \"display $1\" vgdisplay -D $1'"
166 cmd="$cmd \"Activate VG '$1'\" 'vgchange -ay $1'"
169 eval $cmd
172 disk_add() {
173 local x y=0
174 cmd="$cmd 'Edit partition table of $1:' 'disk_action $1'"
175 for x in $(cd /dev; ls $1[0-9]* 2> /dev/null)
177 part_add $x; y=1
178 done
179 [ $y = 0 ] && cmd="$cmd 'Partition table is empty.' ''"
180 cmd="$cmd '' ''"
183 vg_add() {
184 local x= y=0
185 cmd="$cmd 'Logical volumes of $1:' 'vg_action $1'"
186 if [ -d /dev/$1 ]; then
187 for x in $(cd /dev; ls -1 $1/*); do
188 part_add $x; y=1
189 done
190 if [ $y = 0 ]; then
191 cmd="$cmd 'No logical volumes.' ''"
193 else
194 cmd="$cmd 'Volume Group is not active.' ''"
196 cmd="$cmd '' ''"
199 main() {
200 $STONE general set_keymap
202 local cmd install_now=0
203 while
204 cmd="gui_menu install 'Storage setup (partitions and mount-points)
206 This dialog allows you to modify your storage layout and to create filesystems and swap-space - as well as mouting / activating it. Everything you can do using this tool can also be done manually on the command line.'"
208 # protect for the case no disks are present ...
209 found=0
210 local volumes=
211 for x in /sys/block/*; do
212 [ ! -e $x/device -a ! -e $x/dm ] && continue
213 x=${x#/sys/block/}
214 grep -q cdrom /proc/ide/$x/media 2>/dev/null && continue
216 # find user defined alias name
217 local devnode=$(stat -c "%t:%T" /dev/$x)
218 for d in /dev/mapper/*; do
219 [ "$(stat -c "%t:%T" $d)" = "$devnode" ] &&
220 x=${d#/dev/} && break
221 done
223 [[ $x = mapper/* ]] && volumes="$volumes $x" || disk_add $x
224 found=1
225 done
226 for x in $volumes; do
227 part_add $x
228 done
229 for x in $(cat /etc/lvmtab 2> /dev/null); do
230 vg_add "$x"
231 found=1
232 done
233 [ -x /sbin/vgs ] && for x in $(vgs --noheadings -o name 2> /dev/null); do
234 vg_add "$x"
235 found=1
236 done
237 if [ $found = 0 ]; then
238 cmd="$cmd 'No storage found!' ''"
241 cmd="$cmd 'Install the system ...' 'install_now=1'"
243 eval "$cmd" && [ "$install_now" -eq 0 ]
244 do : ; done
246 if [ "$install_now" -ne 0 ]; then
247 $STONE packages
248 mount -v /dev /mnt/dev --bind
249 cat > /mnt/tmp/stone_postinst.sh << EOT
250 #!/bin/bash
251 mount -v /proc
252 mount -v /sys
253 . /etc/profile
254 stone setup
255 umount -v /dev
256 umount -v /proc
257 umount -v /sys
259 chmod +x /mnt/tmp/stone_postinst.sh
260 grep ' /mnt[/ ]' /proc/mounts |
261 sed 's,/mnt/\?,/,' > /mnt/etc/mtab
262 cd /mnt; chroot . ./tmp/stone_postinst.sh
263 rm -fv ./tmp/stone_postinst.sh
264 if gui_yesno "Do you want to un-mount the filesystems and reboot now?"
265 then
266 shutdown -r now
267 else
268 echo
269 echo "You might want to umount all filesystems now and reboot"
270 echo "the system now using the commands:"
271 echo
272 echo " umount -arv"
273 echo " reboot -f"
274 echo
275 echo "Or by executing 'shutdown -r now' which will run the above commands."
276 echo