summaryrefslogtreecommitdiff
path: root/scripts/init-floppy
blob: 6d67965beb1ada4561b42d05c556b9504595160d (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
#!/bin/bash
# **** License ****
# Version: VPL 1.0
#
# The contents of this file are subject to the Vyatta Public License
# Version 1.0 ("License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.vyatta.com/vpl
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# This code was originally developed by Vyatta, Inc.
# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc.
# All Rights Reserved.
#
# Author:	Robert Bays <robert@vyatta.com>
# **** End License ****

shopt -s xpg_echo

test -f /etc/default/vyatta && \
    source /etc/default/vyatta
: ${vyatta_sbindir:=/opt/vyatta/sbin}
: ${vyatta_sysconfdir:=/opt/vyatta/etc}

if [ -n "$1" ]; then
    DRIVE=$1
else   
    DRIVE="/dev/fd0"
fi

# Look and see if we have a floopy drive
if sed -n '/[0-9]\+ fd$/ { q 1 }' /proc/devices || [ ! -e $DRIVE ] ; then
    echo "No floppy device"
    exit 1
fi

echo "This will erase all data on floppy $DRIVE."
read -p 'Continue (y/n)? [y] ' -n 1 -t 5 yorn

if [[ "$yorn" == [nN]* ]] ; then
    echo
    exit 0
fi

fd=/media/floppy

umount_notice="\rAttempting to unmount floppy...\c"
umount__error="\rError: Couldn't unmount $DRIVE."
format_notice="\rFormatting floppy $DRIVE...    \c"
format__error="\rPlease insert a floppy disk in $DRIVE and rerun init-floppy."
create_notice="\rCreating file system...        \c"
create__error="\rError: Couldn't create filesystem on floppy $DRIVE"
mount__notice="\rMounting formatted floppy...   \c"
mount___error="\rError: Couldn't mount floppy $DRIVE to $fd"
config_notice="\rSaving config...               \c"
config__error="\rError: Couldn't save config in $fd/config/config.boot"
bind___notice="\rRedirecting config directory...\c"
bind____error="\rError: redirect to floppy"
saved__notice="\rYour configuration was saved in: $fd/config/config.boot"

mkdir -p $fd

if mount | grep -q $fd/config ; then
    umount $fd/config
fi

if grep -q $DRIVE /proc/mounts ; then
    echo "$umount_notice"
    if ! /bin/umount $fd >/dev/null 2>&1 ; then
	echo "$umount__error"
	exit
    fi
fi

echo "$format_notice"
if ! /usr/bin/fdformat -n $DRIVE >/dev/null 2>&1 ; then
    echo "$format__error"
    exit
fi

echo "$create_notice"
if ! /sbin/mke2fs -q $DRIVE >/dev/null 2>&1 ; then
    echo "$create__error"
    exit
fi

echo "$mount__notice"
if ! /bin/mount /dev/fd0 $fd -t ext2 -o sync >/dev/null 2>&1 ; then
    echo "$mount___error"
    exit
fi

/bin/mkdir $fd/config
/bin/chmod 777 $fd/config

echo "$config_notice"
if ! ${vyatta_sbindir}/vyatta-save-config.pl $fd/config/config.boot >/dev/null
then
    echo "$config__error"
    exit
fi

echo "$bind___notice"
if ! /bin/mount -o bind $fd/config ${vyatta_sysconfdir}/config 2>&1 ; then
    echo "$bind____error"
    exit
fi

echo "$saved__notice"

# Local Variables:
# mode: shell-script
# sh-indentation: 4
# End: