bt-audio: check for presence of snd-bt-sco
[grml-scripts.git] / usr_sbin / mkdosswapfile
1 #!/bin/sh
2 # Filename:      mkdosswapfile
3 # Purpose:       create GRML swapfile on an existing DOS partition
4 # Authors:       (c) Klaus Knopper Mar 2001, (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 # Latest change: Fre Apr 20 00:40:15 CEST 2007 [mika]
8 ################################################################################
9
10 PATH="/bin:/sbin:/usr/bin:/usr/sbin"
11 export PATH
12
13 # XDIALOG_HIGH_DIALOG_COMPAT=1
14 # export XDIALOG_HIGH_DIALOG_COMPAT
15
16 [ "`id -u`" != "0" ] && exec sudo "$0" "$@"
17
18 #TMP="/tmp/mkdosswapfile.tmp$$"
19 TMP=$(mktemp)
20
21 bailout(){
22   rm -f "$TMP"
23   exit 0
24 }
25
26 DIALOG="dialog"
27 # [ -n "$DISPLAY" ] && [ -x /usr/bin/Xdialog ] && DIALOG="Xdialog"
28
29 trap bailout 1 2 3 15
30
31 # LANGUAGE etc.
32 [ -r /etc/default/locale ] && . /etc/default/locale
33
34 DOSPARTITIONS=""
35
36 # Find all DOS partitions
37 if [ -f /proc/partitions ]
38 then
39 partitions=""
40 for p in $(awk 'BEGIN{old="__start"}{if($0==old){exit}else{old=$0;if($4&&$4!="name"){print $4}}}' /proc/partitions); do
41 case $p in
42  hd?|sd?) partitions="$partitions /dev/$p"; ;;
43  *) ;;
44 esac
45 done
46 if [ -n "$partitions" ]
47 then
48 foundp="$(LANG=C LC_ALL=C fdisk -l $partitions 2>/dev/null)"
49 for p in `echo "$foundp" | awk '/^\/dev\//{if(/FAT/){print $1}}'`
50 do
51 d="/mnt/${p##*/}"
52 if mount -o ro -t vfat $p $d 2>/dev/null; then
53 [ ! -f $d/grml.swp ] && DOSPARTITIONS="$DOSPARTITIONS $p"
54 umount $d
55 fi
56 done
57 fi
58 fi
59
60 if [ -n "$DOSPARTITIONS" ]; then
61 echo -n "\ec"
62 for p in $DOSPARTITIONS; do
63 # Language-dependent Messages
64 case "$LANGUAGE" in
65 de|at|ch)
66 MESSAGE1="Moechten Sie eine SWAP-Datei 'grml.swp' fuer GRML auf Ihrer bestehenden DOS-Partition $p anlegen? Eine solche SWAP-Datei ermoeglicht es Ihnen, trotz geringem Hauptspeicher Programmpakete wie KDE zu benutzen. Sie koennen diese Datei nach Beendigung Ihrer GRML-Session gefahrlos wieder loeschen."
67 MESSAGE2="Bitte geben Sie an, wieviel MB Sie als SWAP verwenden wollen. Empfohlen: 60 - 128. Frei: "
68 MESSAGE3="Erzeuge swapfile 'grml.swp' auf $p..."
69 ERROR1="Leider ist nicht genug Platz auf dieser Partition ($p), es sollten mindestens 60 MB frei sein."
70 SUCCESS="Das Einrichten des Swapfiles 'grml.swp' auf $p war erfolgreich."
71 ;;
72 es)
73 MESSAGE1="¿Quiere crear un fichero de memoria virtual (swap) 'grml.swp' en su partición DOS existente $p? Un fichero swap le permite utilizar grandes aplicaciones como KDE incluso si su ordenador tiene poca memoria. Puede borrar tranquilamente el fichero swap una vez haya finalizado su sesión con GRML."
74 MESSAGE2="Por favor, especifique la cantidad de espacio en disco que quiere utilizar como SWAP. Recomendado: 60 - 128. Libre: "
75 MESSAGE3="Creando archivo de memoria virtual 'grml.swp' en $p..."
76 ERROR1="Lo siento, no hay suficiente espacio libre en $p. Son necesarios al menos 60 MB."
77 SUCCESS="Archivo swap 'grml.swp' en $p creado satisfactoriamente."
78 ;;
79 *)
80 MESSAGE1="Do you want to create a swapfile 'grml.swp' on your existing DOS partition $p? A swapfile allows you to use huge application packages like KDE even if your computer is low on memory. You can safely delete the swapfile after finishing your GRML session."
81 MESSAGE2="Please specify the amount of diskspace that you want to use as SWAP. Recommended: 60 - 128. Free: "
82 MESSAGE3="Creating swapfile 'grml.swp' on $p..."
83 ERROR1="Sorry, not enough free space on $p. At least 60 MB required."
84 SUCCESS="Swapfile 'grml.swp' on $p successfully created."
85 ;;
86 esac
87
88 d="/mnt/${p##*/}"
89 f="$d/grml.swp"
90 if mount -o umask=000,rw -t vfat $p $d; then
91 if $DIALOG --yesno "$MESSAGE1" 11 62; then
92 AVAIL=$(df -m $d | awk '/^\/dev\//{print $4}')
93 if [ "$AVAIL" -lt 60 ]; then
94 $DIALOG --msgbox "$ERROR1" 10 45
95 umount $d
96 else
97 rm -f "$TMP"
98 $DIALOG --inputbox "$MESSAGE2 $AVAIL" 8 62 "60" 2>"$TMP" || { umount "$d" ; bailout; }
99 IN="`cat $TMP`" 
100 [ "$IN" -ge 60 -a "$IN" -le "$AVAIL" ] 2>/dev/null || IN="60"
101 echo "$MESSAGE3"
102 dd if=/dev/zero of="$f" bs=1000k count="$IN" && \
103 mkswap -v1 "$f" && swapon -v "$f" 2>/dev/null && \
104 echo "$f swap swap defaults 0 0" >>/etc/fstab
105 [ "$?" = "0" ] && { sleep 2 ; $DIALOG --msgbox "$SUCCESS" 10 45; } || umount "$d" 2>/dev/null
106 mount -o remount,ro $d
107 fi
108 else
109 umount "$d"
110 fi
111 fi
112 done
113 else
114 case "$LANGUAGE" in
115 de|at|ch)
116 ERROR2="Leider sind auf Ihrem System keine geeigneten DOS-Partitionen zum Einrichten eines Swapfile vorhanden."
117 ;;
118 es)
119 ERROR2="Lo siento, no se han encontrado particiones disponibles de tipo DOS para el fichero swap de memoria virtual."
120 ;;
121 *)
122 ERROR2="Sorry, no DOS partitions available for swapfile."
123 ;;
124 esac
125
126 $DIALOG --msgbox "$ERROR2" 10 45
127 fi
128
129 bailout
130
131 ## END OF FILE #################################################################