8b677349ea475357cc29e5b2eee2804e278962b8
[platform/adaptation/setup-scripts.git] / setup-ivi-fstab
1 #!/bin/sh -euf
2
3 # Copyright 2013 Intel Corporation
4 # Author: Artem Bityutskiy
5 # License: GPLv2
6
7 PROG="setup-ivi-fstab"
8 VER="1.0"
9
10 srcdir="$(readlink -ev -- ${0%/*})"
11 PATH="/usr/share/setup-ivi:$srcdir:$PATH"
12
13 . setup-ivi-sh-functions
14 . installerfw-sh-functions
15
16 # This is a small trick which I use to make sure my scripts are portable -
17 # check if 'dash' is present, and if yes - use it.
18 if can_switch_to_dash; then
19         exec dash -euf "$srcdir/$PROG" "$@"
20         exit $?
21 fi
22
23 show_usage()
24 {
25         cat <<-EOF
26 Usage: $PROG [options]
27
28 Create the default Tizen IVI /etc/fstab file.
29
30 Options:
31   -f, --force    re-write /etc/fstab if it exists
32   -v, --verbose  be verbose
33   --version      show the program version and exit
34   -h, --help     show this text and exit
35 EOF
36 }
37
38 show_usage_fail()
39 {
40         IFS= printf "%s\n\n" "$PROG: error: $*" >&2
41         show_usage >&2
42         exit 1
43 }
44
45 # Parse the options
46 tmp=`getopt -n $PROG -o f,v,h --long force,verbose,version,help -- "$@"` ||
47         show_usage_fail "cannot parse command-line options"
48 eval set -- "$tmp"
49
50 force=
51 verbose=
52 while true; do
53         case "$1" in
54         -f|--force)
55                 force="-f"
56                 ;;
57         -v|--verbose)
58                 verbose="-v"
59                 ;;
60         --version)
61                 printf "%s\n" "$VER"
62                 exit 0
63                 ;;
64         -h|--help)
65                 show_usage
66                 exit 0
67                 ;;
68         --) shift; break
69                 ;;
70         *) show_usage_fail "unrecognized option \"$1\""
71                 ;;
72         esac
73         shift
74 done
75
76 installerfw_available || installerfw_restore_env
77
78 fstab="$(installerfw_mnt_prefix "/etc/fstab")"
79
80 if [ -s "$fstab" ] && [ -z "$force" ]; then
81         fatal "\"$fstab\" already exists, use -f to re-write it"
82 fi
83
84 installerfw_verify_defined "INSTALLERFW_PART_COUNT"
85
86 contents="# Generated by $PROG
87 devpts  /dev/pts  devpts  gid=5,mode=620  0 0
88 tmpfs   /dev/shm  tmpfs   defaults        0 0
89 proc    /proc     proc    defaults        0 0
90 sysfs   /sys      sysfs   defaults        0 0"
91
92 pnum=0
93 br="
94 "
95 while [ "$pnum" -lt "$INSTALLERFW_PART_COUNT" ]; do
96         eval uuid="\${INSTALLERFW_PART${pnum}_UUID:-}"
97         eval mountpoint="\${INSTALLERFW_PART${pnum}_MOUNTPOINT:-}"
98         eval fsopts="\${INSTALLERFW_PART${pnum}_FSOPTS:-defaults}"
99         eval fstype="\${INSTALLERFW_PART${pnum}_FSTYPE:-}"
100
101         contents="${contents}${br}UUID=$uuid  $mountpoint  $fstype  $fsopts  0 0"
102
103         pnum="$((pnum+1))"
104 done
105
106 verbose "writing the followint to \"$fstab\": $contents"
107
108 printf "%s" "$contents" > "$fstab"