3 # Purpose: Program to copy config files and mount them back for editing
4 # Authors: grml-team (grml.org), (c) Michael Gebetsroither <gebi@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 # Latest change: Thu Feb 10 06:25:01 CET 2005 [gebi]
8 ################################################################################
15 #. /etc/grml/sysexits-sh
23 # real vars (script defaults)
24 target_="/ramdisk/grml-bind"
25 runsFromHd && target_="/tmp/grml-bind" # where to save the file
26 file_ro_="" # secured input filename (source)
27 target_path_="" #secured path to target + filename
29 # command parameter vars
31 remove_mapping_=0 # user wants to remove the mapping
32 create_mapping=0 # user wants to create the mapping
44 Usage: "grml-bind" [OPTIONS] <file you want to edit>
46 grml-bind is a program to prepare a file on a read-only fs for writing
47 It copies the file to a ramdisk and mount --bind it back.
48 Very usefull for knoppix-like distributions.
51 -c create the file-mapping
52 -r remove the file-mapping
53 -v verbose (show what is going on, v++)
55 () create the file-mapping
61 # function to create the mapping
62 function createMapping
64 isExistent "$file_ro_" die
65 isNotExistent "$target_path_" die
67 # --preserve=mode,ownership,timestamps can be a problem for normal user
68 # but neverless mount --bind requires extended privilegs, so who cares?
69 execute "cp -rL \"$file_ro_\" \"$target_\"" warn \
70 "Problms copying data to ramdisk"
72 # mount--bind the file from ramdisk back over the r/o file
73 execute "mount --bind \"$target_path_\" \"$file_ro_\"" warn || \
74 execute "rm -r \"$target_path_\"" die
81 function removeMapping
83 isExistent "$target_path_" die \
84 "You have not edited this file yet: \"$target_path_\""
86 execute "umount \"$file_ro_\"" warn
87 execute "rm -r \"$target_path_\"" die
98 while getopts vrhc opt_ ; do
100 r) remove_mapping_=1 ;;
101 c) create_mapping=1 ;;
102 h) printUsage; exit ;;
103 v) let verbose_=$verbose_+1 ;;
104 ?) printUsage; exit 64 ;;
107 shift $(($OPTIND - 1)) # set ARGV to the first not parsed commandline parameter
115 setExitFunction "printUsage"
116 # hmmm user has not given us a filename/path
118 die "you need to give me a file/path" 64
121 # hmmm user gave us the wrong number of arguments
122 if [ "$#" -ne 1 ]; then
123 die "wrong number of arguments" 64
129 # does our target-path exist? if not create it
130 if [ ! -d $target_ ]; then
131 warn "target path \"$target_\" does not exist => creating"
132 execute "mkdir -p $target_" die
133 runsFromHd && execute "chmod 751 $target_" die
136 # secure the input file/path
137 file_ro_=`secureInput "$1"`
139 # check if input file is a link, if yes resolve it
140 if [ -L $file_ro_ ]; then
141 file_ro_=`execute "readlink \"$file_ro_\""`
144 #create all possible pathformats to absolut paths
145 normalized_source_path_=`relToAbs "$file_ro_"`
146 file_ro_=$normalized_source_path_
147 target_path_=$target_/`execute "basename \"$normalized_source_path_\""`
149 # do what the user wants, maybee *g*
150 if [ $remove_mapping_ -eq 1 ]; then # ok, the user wants to remove his mapping
152 else # no, user wants to create the mapping
156 # END OF FILE ################################################################################