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