Changeset 481 for branches/confman-1.9/confman.in
- Timestamp:
- 11/11/2009 14:09:39 (3 years ago)
- Location:
- branches/confman-1.9
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
confman.in (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/confman-1.9
- Property svn:mergeinfo changed
/trunk merged: 462,464,469
- Property svn:mergeinfo changed
-
branches/confman-1.9/confman.in
r480 r481 111 111 } 112 112 113 # Either by prompting or respecting -m/-F, returns a filename on stdout 114 # with a log message in it 115 # $1 contains a file with the output of svn status to display in interactive 116 # log messages 117 # Returns 1 if an abort was requested by the user 118 # Returns 0 if the returned filename is good for a commit 119 function get_log { 120 local status="$1" 121 local finished=false 122 local ignoreline="--This line, and those below, will be ignored--" 123 local orig_log logfile 124 125 # local seems to return true, overwriting the return of the nested 126 # call for && evaluation 127 logfile=$(conf_log_message) && finished=true 128 129 if $finished ; then 130 echo "$logfile" 131 return 0 132 fi 133 134 orig_log=$(conf_tmp_file) 135 printf "\n$ignoreline\n" >> "$logfile" 136 cat "$status" >> "$logfile" 137 cp "$logfile" "$orig_log" 138 139 # I apologize for the redirect, but stdout is being written into a 140 # variable, and at least vim (probably other editors too) gets cranky when 141 # stdout doesn't go to the user. Luckily, the fork in the common section 142 # leaves a copy of the original stdout in fd 3. 143 ${EDITOR} "$logfile" >&3 144 145 while diff "$logfile" "$orig_log" >/dev/null 2>&1 ; do 146 echo "Log message unchanged. (E)dit / (a)bort / (c)ontinue?" 147 read response 148 case "$response" in 149 [cC]*) break;; 150 [aA]*) return 1;; 151 ""|[eE]*) ${EDITOR} "$logfile";; 152 esac 153 done 154 rm -f "$orig_log" 155 ${sed_cmd} -i '' -e "/${ignoreline}/,\$d" "$logfile" 2>/dev/null 156 echo "$logfile" 157 return 0 158 } 159 160 # Arguments are full paths to files within $WORK_PATH to check via svn status. 161 # Returns 1 if the files are unchanged 162 # Returns 0 if the files are changed and prints a filename to stdout 163 # with status info suitable for log message footers 164 function get_status { 165 local status=$(conf_tmp_file) 166 local ABS_WORK=$(${readlink_cmd} -m "$WORK_PATH") 167 168 # Using a subshell to preserve CWD 169 ( 170 cd "$WORK_PATH" 171 until [ -z "$1" ] ; do 172 @SVN@ status "${1#${ABS_WORK}/}" >> "$status" 173 shift 174 done 175 ) 176 177 if [ $(wc -l < "$status") -eq 0 ] ; then 178 rm -f "$status" 179 return 1 180 fi 181 182 echo "$status" 183 return 0 184 } 185 113 186 function commit { 114 if [ -z "$*" ] ; then 115 conf_require_recipe 116 conf_lock_system 117 conf_lock_wcopy 118 local msg=$(conf_tmp_file) 119 local orig_msg=$(conf_tmp_file) 120 local status=$(conf_tmp_file) 121 local modules=$(conf_get_recipe | tr '\n' ',') 122 local ignoreline="--This line, and those below, will be ignored--" 123 # Moved up per Ian's request. 124 $SUDO ${SUDO:+-v} 125 cat $LOG_TEMPLATE > $msg 126 printf "\n${ignoreline}\n" >> $msg 127 conf_get_recipe | tr ' ' '\n' | xargs -I % @SVN@ status \ 128 ${WORK_PATH}/% >> $status 129 cat $status >> $msg 130 cp $msg $orig_msg 131 if [ $(wc -l < $status) -gt 0 ] ; then 132 ${EDITOR} $msg 133 if diff $msg $orig_msg >/dev/null 2>&1 ; then 134 echo "Log message unchanged. (a)bort / (C)ontinue?" 135 read response 136 if [ "${response}" = "a" ] ; then 137 conf_unlock_wcopy 138 conf_unlock_system 139 return 1 140 fi 141 fi 142 fi 143 rm -f $status $orig_msg 144 ${sed_cmd} -i '' -e '/'"$ignoreline"'/,$d' $msg 2>/dev/null 145 $SUDO ${SUDO:+-v} 146 147 #Changed this from just update to fix locking issue - arjun 148 conf_update_tree || conf_cleanExit 149 150 echo "Commit operation started" >&2 151 conf_commit "$(conf_get_recipe)" $msg || return $? 152 for layer in $(conf_get_recipe) ; do 153 echo "Rolling on $layer..." 154 conf_rollout $layer || return $? 155 done 156 for file in $SINGULARITIES ; do 157 conf_assemble_sing $file || return $? 158 done 159 conf_recordAction commit 160 conf_markclean 161 echo "Commit operation finished successfully" >&2 162 rm -f $msg 163 conf_unlock_wcopy 164 conf_unlock_system 165 else 166 print_usage 1 167 fi 187 local msg status modules module modpath 188 local nocommit=true 189 local opt OPTIND OPTARG 190 191 while getopts ":m:F:" opt ; do 192 case $opt in 193 m) LOG_MESSAGE="$OPTARG"; LOG_MESSAGE_SET="true" ;; 194 F) LOG_FILE="$OPTARG" ;; 195 *) echo "Invalid option '-${OPTARG}'." >&4 196 print_usage 1 197 ;; 198 esac 199 done 200 shift $(($OPTIND - 1)) 201 202 [ -z "$1" ] || print_usage 1 203 204 conf_require_recipe 205 conf_lock_system 206 conf_lock_wcopy 207 208 for module in $(conf_get_recipe) ; do 209 modpath=$(${readlink_cmd} -m ${WORK_PATH}/${module}) 210 modules=${modules:+${modules} }${modpath} 211 done 212 213 $SUDO ${SUDO:+-v} 214 conf_update_tree || conf_cleanExit 215 216 if status=$(get_status $modules) ; then 217 nocommit=false 218 msg=$(get_log "$status") || conf_cleanExit 219 rm -f "$status" 220 fi 221 222 $SUDO ${SUDO:+-v} 223 224 echo "Commit operation started" >&2 225 $nocommit || conf_commit "$(conf_get_recipe)" $msg || return $? 226 for layer in $(conf_get_recipe) ; do 227 echo "Rolling on $layer..." 228 conf_rollout $layer || return $? 229 done 230 for file in $SINGULARITIES ; do 231 conf_assemble_sing $file || return $? 232 done 233 conf_recordAction commit 234 conf_markclean 235 echo "Commit operation finished successfully" >&2 236 rm -f $msg 237 conf_unlock_wcopy 238 conf_unlock_system 168 239 } 169 240 … … 171 242 function inst { 172 243 local file livefile 173 174 if [ -z "$*" ] ; then 175 print_usage 1 176 else 177 conf_require_recipe 178 conf_lock_wcopy 179 conf_lock_system 180 local msg=$(conf_tmp_file) 181 local orig_msg=$(conf_tmp_file) 182 local status=$(conf_tmp_file) 183 local modules=$(conf_get_recipe | tr '\n' ',') 184 local ignoreline="---Everything after this line will be ignored---" 185 local files 186 # Moved up per Ian's request. 187 cat $LOG_TEMPLATE > $msg 188 printf "\n${ignoreline}\n" >> $msg 189 for file in "$@"; do 190 if [ -L "$file" ]; then 191 files="$files `${readlink_cmd} -m $file`" 192 fi 193 files="$files $file" 194 done 195 @SVN@ status $files >> $status 196 cat $status >> $msg 197 cp $msg $orig_msg 198 if [ $(wc -l < $status) -gt 0 ] ; then 199 ${EDITOR} $msg 200 if diff $msg $orig_msg >/dev/null 2>&1 ; then 201 echo "Log message unchanged. (a)bort / (C)ontinue?" 202 read response 203 if [ "${response}" = "a" ] ; then 204 conf_unlock_wcopy 205 conf_unlock_system 206 return 1 207 fi 208 fi 209 fi 210 rm $status $orig_msg 211 ${sed_cmd} -i '' -e '/'"$ignoreline"'/,$d' $msg 2>/dev/null 212 $SUDO ${SUDO:+-v} 213 #changed from update to conf_update_tree to implement locking - arjun 214 conf_update_tree || conf_cleanExit 215 216 echo "Installation operation started." >&2 217 conf_commit_file "$msg" "$files" || return $? 218 for layer in $(conf_get_recipe) ; do 219 conf_install $layer "$@" 220 done 221 for file in $SINGULARITIES ; do 222 conf_assemble_sing $file || conf_cleanExit 223 done 224 conf_recordAction install 225 if ! conf_isclean ; then 226 echo "WARNING: Recent 'install' operations prevented a 'sync'" >&2 227 echo "Running a 'commit' is highly recommended." >&2 228 fi 229 echo "Installation operation succeeded." >&2 230 conf_unlock_wcopy 231 conf_unlock_system 232 fi 244 local msg status files file 245 local nocommit=true 246 local opt OPTIND OPTARG 247 248 while getopts ":m:F:" opt ; do 249 case $opt in 250 m) LOG_MESSAGE="$OPTARG"; LOG_MESSAGE_SET="true" ;; 251 F) LOG_FILE="$OPTARG" ;; 252 *) echo "Invalid option '-${OPTARG}'." >&4 253 print_usage 1 254 ;; 255 esac 256 done 257 shift $(($OPTIND - 1)) 258 259 conf_require_recipe 260 conf_lock_wcopy 261 conf_lock_system 262 263 for file in "$@"; do 264 files="${files:+${files} }$(${readlink_cmd} -m "$file")" 265 done 266 267 268 $SUDO ${SUDO:+-v} 269 conf_update_tree || conf_cleanExit 270 271 if status=$(get_status $files) ; then 272 nocommit=false 273 msg=$(get_log "$status") || conf_cleanExit 274 rm -f "$status" 275 fi 276 277 echo "Installation operation started." >&2 278 $nocommit || conf_commit_file "$msg" "$files" || return $? 279 for layer in $(conf_get_recipe) ; do 280 conf_install $layer "$@" 281 done 282 for file in $SINGULARITIES ; do 283 conf_assemble_sing $file || conf_cleanExit 284 done 285 conf_recordAction install 286 if ! conf_isclean ; then 287 echo "WARNING: Recent 'install' operations prevented a 'sync'" >&2 288 echo "Running a 'commit' is highly recommended." >&2 289 fi 290 echo "Installation operation succeeded." >&2 291 conf_unlock_wcopy 292 conf_unlock_system 233 293 } 234 294 … … 894 954 895 955 function recipe_edit { 956 local recipe 957 local new_recipe_file recipe_file 958 local repeat msg status 959 local opt OPTIND OPTARG 960 961 while getopts ":m:F:" opt ; do 962 case $opt in 963 m) LOG_MESSAGE="$OPTARG"; LOG_MESSAGE_SET="true" ;; 964 F) LOG_FILE="$OPTARG" ;; 965 *) echo "Invalid option '-${OPTARG}'." >&4 966 print_usage 1 967 ;; 968 esac 969 done 970 shift $(($OPTIND - 1)) 971 896 972 if [ -z "$1" ] ; then print_usage 1 ; fi 897 local recipe="$1" 898 local recipe_file=$(conf_tmp_file) 899 cat "$(conf_recipe_dir)/${recipe}" > "$recipe_file" 900 $EDITOR "$recipe_file" 901 for module in $(conf_get_recipe ${recipe_file}) ; do 902 if ! [ -d "${WORK_PATH}/${module}" ] ; then 903 echo "Error: recipe references non-existent module $module" >&2 973 974 conf_lock_wcopy 975 recipe="$1" 976 recipe_file=$(conf_recipe_dir)/${recipe} 977 new_recipe_file=$(conf_tmp_file) 978 979 cat "$recipe_file" > "$new_recipe_file" 980 $EDITOR "$new_recipe_file" 981 until conf_recipe_verify "$new_recipe_file" ; do 982 echo -n "(E)dit / (c)ancel? " 983 read repeat 984 case "$repeat" in 985 [Cc]*) return 1;; 986 *) $EDITOR "$new_recipe_file";; 987 esac 988 done 989 990 cat "$new_recipe_file" > "$recipe_file" 991 992 if status=$(get_status "${recipe_file#${WORK_PATH}/}") ; then 993 msg=$(get_log "$status") || return 1 994 conf_commit_recipe "$msg" "$recipe" 995 fi 996 rm -f "$new_recipe_file" 997 conf_unlock_wcopy 998 } 999 1000 function recipe_create { 1001 local recipe recipe_file opt OPTIND msg status 1002 while getopts ":m:F:R:" opt ; do 1003 case $opt in 1004 R) new_recipe_file="$OPTARG" ;; 1005 m) LOG_MESSAGE="$OPTARG"; LOG_MESSAGE_SET="true" ;; 1006 F) LOG_FILE="$OPTARG" ;; 1007 *) echo "Invalid option '-${OPTARG}' for recipe create." >&4 1008 print_usage 1 1009 ;; 1010 esac 1011 done 1012 shift $(($OPTIND - 1)) 1013 1014 eval recipe=$1 1015 1016 if [ -z "$recipe" ] ; then 1017 print_usage 1 1018 fi 1019 1020 conf_lock_wcopy 1021 recipe_file=$(conf_recipe_dir)/${recipe} 1022 conf_recipe_create "$recipe" || return 1 1023 1024 if [ -z "$new_recipe_file" ] ; then 1025 if ! recipe_edit "$recipe" ; then 1026 conf_rm_file --force "${new_recipe_file}" 1027 conf_unlock_wcopy 904 1028 return 1 905 1029 fi 906 done 907 conf_update_recipe "$recipe" "$recipe_file" 908 rm -f "$recipe_file" 909 } 910 911 function recipe_create { 912 if [ -z "$1" ] ; then print_usage 1 ; fi 913 local recipe="$1" 914 conf_recipe_create "$recipe" 915 recipe_edit "$recipe" 1030 conf_unlock_wcopy 1031 return 0 1032 fi 1033 1034 if conf_recipe_verify "$new_recipe_file" ; then 1035 cp "$new_recipe_file" "$recipe_file" 1036 if status=$(get_status "${recipe_file#${WORK_PATH}/}") ; then 1037 msg=$(get_log "$status") || return 1 1038 conf_commit_recipe "$msg" "$recipe" 1039 fi 1040 conf_unlock_wcopy 1041 return 0 1042 else 1043 conf_rm_file --force "${recipe_file}" 1044 conf_unlock_wcopy 1045 return 1 1046 fi 916 1047 } 917 1048 918 1049 function recipe_remove { 919 if [ -z "$*" ] ; then print_usage 1 ; fi 1050 local opt OPTIND OPTARG 1051 local msg status recipes recipe 1052 local nocommit=true 1053 while getopts ":m:F:" opt ; do 1054 case $opt in 1055 m) LOG_MESSAGE="$OPTARG"; LOG_MESSAGE_SET="true" ;; 1056 F) LOG_FILE="$OPTARG" ;; 1057 *) echo "Invalid option '-${OPTARG}'." >&4 1058 print_usage 1 1059 ;; 1060 esac 1061 done 1062 shift $(($OPTIND - 1)) 1063 1064 conf_lock_wcopy 1065 920 1066 conf_remove_recipes "$@" || exit 1 1067 1068 for recipe in "$@" ; do 1069 recipes="${recipes:+${recipes} }$(conf_recipe_dir)/${recipe}" 1070 done 1071 1072 if status=$(get_status $recipes) ; then 1073 nocommit=false 1074 msg=$(get_log "$status") || conf_cleanExit 1075 rm -f "$status" 1076 fi 1077 1078 $nocommit || conf_commit_recipes "$msg" "$@" 1079 1080 conf_unlock_wcopy 921 1081 } 922 1082 … … 935 1095 exit 1 936 1096 fi 1097 conf_lock_wcopy 1098 conf_lock_system 937 1099 conf_set_recipe "$recipe" 1100 conf_unlock_system 1101 conf_unlock_wcopy 938 1102 } 939 1103 … … 949 1113 950 1114 function recipe_list { 951 cd $(conf_recipe_dir) 952 ls 1115 ( 1116 cd $(conf_recipe_dir) 1117 ls 1118 ) 953 1119 } 954 1120 … … 973 1139 974 1140 # Debug mode? 975 while getopts " hdv-" opt ; do1141 while getopts ":h:dv-" opt ; do 976 1142 case $opt in 977 d) DEBUG="true" ; shift ;;978 h) shift ; print_help "$@" ; conf_cleanExit 0 ;;1143 d) DEBUG="true" ;; 1144 h) print_help "$OPTARG" ; conf_cleanExit 0 ;; 979 1145 v) print_version ; conf_cleanExit 0 ;; 980 *) print_usage 1 ;; 1146 *) echo "Invalid options '-${OPTARG}'." >&4 1147 print_usage 1 1148 ;; 981 1149 esac 982 1150 done 983 1151 1152 # Argument checking 1153 if [ -n "$LOG_FILE" ] && ! [ -r "$LOG_FILE" ] ; then 1154 echo "Log file $LOG_FILE does not exist or is not readable." >&4 1155 conf_cleanExit 1 1156 fi 1157 1158 if $LOG_MESSAGE_SET && [ -n "$LOG_FILE" ] ; then 1159 echo "Cannot specify both a message with -m and a file with -F." >&4 1160 conf_cleanExit 1 1161 fi 1162 984 1163 # Dispatch the subcommand. This must happen last and in the global context. 985 subcommand=$1 986 shift 1164 eval subcommand=\$$OPTIND 1165 shift $OPTIND 1166 987 1167 trap "conf_interrupt_trap" HUP INT QUIT TERM 988 1168 case $subcommand in
Note: See TracChangeset
for help on using the changeset viewer.
