Improve update output

This commit is contained in:
Marcus Whybrow 2012-08-12 00:57:54 +01:00
parent 0b47c6c7e1
commit 3e40faf2df

176
init/msm
View File

@ -1966,7 +1966,7 @@ command_config() {
# Downloads latest versions of all MSM files
command_update() {
echo -n "Checking for updates to version ${VERSION}... "
echo -n "Checking for updates to version ${VERSION}..."
local any_files_updated="false"
@ -2021,16 +2021,16 @@ command_update() {
# Download the other files if that version is different (implicitly better) to the current version
if [[ "$VERSION" == "$latest_version" ]]; then
echo "Already at latest version."
echo " Already at latest version."
else
echo "$latest_version is available."
echo " $latest_version is available."
fi
### BEGIN Fancy warnings
echo -n "Checking if any files need to be updated... "
echo -n "Checking if any files need to be updated..."
download_file "bash_completion/msm"
download_file "versioning/versions.txt"
@ -2086,10 +2086,19 @@ command_update() {
download_upstream_versions
echo "Done."
local updating creating
local updated="true"
if files_need_updating; then
files_need_updating && updating="true"
files_need_updating && creating="true"
if ! "$updating" && ! "$creating"; then
echo " No. We're all done."
return 0
else
echo " Done."
fi
if "$updating"; then
echo "Updating will overwrite the following files:"
compare_file "init/msm" "$SCRIPT"
@ -2111,12 +2120,9 @@ command_update() {
[ ! -z "$RETURN" ] && echo " > Version file: $version_path"
fi
done < <(find "${output_dir}/versioning" -mindepth 1 -name \*.${SETTINGS_VERSIONING_FILE_EXTENSION} -type f -print0)
else
updated="true"
fi
local created="false"
if files_need_creating; then
if "$creating"; then
echo "Updating will create the following files:"
[ ! -e "$SCRIPT" ] && echo " > The main MSM script: $SCRIPT"
@ -2132,105 +2138,99 @@ command_update() {
[ ! -e "$version_path" ] && echo " > Version file: $version_path"
fi
done < <(find "${output_dir}/versioning" -mindepth 1 -name \*.${SETTINGS_VERSIONING_FILE_EXTENSION} -type f -print0)
else
created="true"
fi
### END Fancy warnings
if ! "$updated" && ! "$created"; then
echo "Strange, no files need updating or creating. Ah well."
if [[ ! "$noinput" ]]; then
echo -n "Do you want to continue [y/N]: "
read answer
else
if [[ ! "$noinput" ]]; then
echo -n "Do you want to continue [y/N]: "
read answer
else
answer="y"
answer="y"
fi
if [[ "$answer" =~ ^(y|Y|yes)$ ]]; then
echo "Updating MSM to ${latest_version}:"
# Overwrite bash completion file
local created="false"
compare_file "bash_completion/msm" "$COMPLETION"
if [ ! -z "$RETURN" ] || [ ! -e "$COMPLETION" ]; then
[ ! -e "$COMPLETION" ] && created="true"
any_files_updated="true"
local dir="$(dirname "$COMPLETION")"
as_user "root" "mkdir -p \"${dir}\""
as_user "root" "mv -f \"${output_dir}/bash_completion/msm\" \"$COMPLETION\""
source "$COMPLETION"
if "$created"; then
echo " > Created: $COMPLETION"
else
echo " > Updated: $COMPLETION"
fi
fi
if [[ "$answer" =~ ^(y|Y|yes)$ ]]; then
echo "Updating MSM to ${latest_version}:"
# Overwrite the MSM script itself
created="false"
compare_file "init/msm" "$SCRIPT"
if [ ! -z "$RETURN" ] || [ ! -e "$SCRIPT" ]; then
[ ! -e "$SCRIPT" ] && created="true"
# Overwrite bash completion file
local created="false"
compare_file "bash_completion/msm" "$COMPLETION"
if [ ! -z "$RETURN" ] || [ ! -e "$COMPLETION" ]; then
[ ! -e "$COMPLETION" ] && created="true"
any_files_updated="true"
any_files_updated="true"
dir="$(dirname "$SCRIPT")"
as_user "root" "mkdir -p \"${dir}\""
as_user "root" "mv -f \"${output_dir}/init/msm\" \"$SCRIPT\""
as_user "root" "chmod +x \"$SCRIPT\""
local dir="$(dirname "$COMPLETION")"
as_user "root" "mkdir -p \"${dir}\""
as_user "root" "mv -f \"${output_dir}/bash_completion/msm\" \"$COMPLETION\""
source "$COMPLETION"
if "$created"; then
echo " > Created: $COMPLETION"
else
echo " > Updated: $COMPLETION"
fi
if "$created"; then
echo " > Created: $SCRIPT"
else
echo " > Updated: $SCRIPT"
fi
fi
# Overwrite the MSM script itself
# Overwrite the versioning files
manager_property VERSIONING_STORAGE_PATH
manager_property USERNAME
local version_name version_path regex
regex="/(([^/]+/[^/]+)\.[^/\.]*)$"
while IFS= read -r -d $'\0' path; do
created="false"
compare_file "init/msm" "$SCRIPT"
if [ ! -z "$RETURN" ] || [ ! -e "$SCRIPT" ]; then
[ ! -e "$SCRIPT" ] && created="true"
if [[ "$path" =~ $regex ]]; then
version_name="${BASH_REMATCH[1]}"
version_name_without_ext="${BASH_REMATCH[2]}"
version_path="${SETTINGS_VERSIONING_STORAGE_PATH}/${version_name_without_ext}.${SETTINGS_VERSIONING_FILE_EXTENSION}"
any_files_updated="true"
compare_file "${output_dir}/versioning/$version_name" "$version_path"
if [ ! -z "$RETURN" ] || [ ! -e "$version_path" ]; then
[ ! -e "$version_path" ] && created="true"
dir="$(dirname "$SCRIPT")"
as_user "root" "mkdir -p \"${dir}\""
as_user "root" "mv -f \"${output_dir}/init/msm\" \"$SCRIPT\""
as_user "root" "chmod +x \"$SCRIPT\""
any_files_updated="true"
if "$created"; then
echo " > Created: $SCRIPT"
else
echo " > Updated: $SCRIPT"
fi
fi
dir="$(dirname ${SETTINGS_VERSIONING_STORAGE_PATH}/${version_name})"
as_user "root" "mkdir -p \"${dir}\""
as_user "root" "mv -f \"$path\" \"$version_path\""
as_user "root" "chmod +x \"$version_path\""
as_user "root" "chown ${SETTINGS_USERNAME}:${SETTINGS_USERNAME} \"$version_path\""
# Overwrite the versioning files
manager_property VERSIONING_STORAGE_PATH
manager_property USERNAME
local version_name version_path regex
regex="/(([^/]+/[^/]+)\.[^/\.]*)$"
while IFS= read -r -d $'\0' path; do
created="false"
if [[ "$path" =~ $regex ]]; then
version_name="${BASH_REMATCH[1]}"
version_name_without_ext="${BASH_REMATCH[2]}"
version_path="${SETTINGS_VERSIONING_STORAGE_PATH}/${version_name_without_ext}.${SETTINGS_VERSIONING_FILE_EXTENSION}"
compare_file "${output_dir}/versioning/$version_name" "$version_path"
if [ ! -z "$RETURN" ] || [ ! -e "$version_path" ]; then
[ ! -e "$version_path" ] && created="true"
any_files_updated="true"
dir="$(dirname ${SETTINGS_VERSIONING_STORAGE_PATH}/${version_name})"
as_user "root" "mkdir -p \"${dir}\""
as_user "root" "mv -f \"$path\" \"$version_path\""
as_user "root" "chmod +x \"$version_path\""
as_user "root" "chown ${SETTINGS_USERNAME}:${SETTINGS_USERNAME} \"$version_path\""
if "$created"; then
echo " > Created: $version_path"
else
echo " > Updated: $version_path"
fi
if "$created"; then
echo " > Created: $version_path"
else
echo " > Updated: $version_path"
fi
fi
done < <(find "${output_dir}/versioning" -mindepth 1 -name \*.${SETTINGS_VERSIONING_FILE_EXTENSION} -type f -print0)
fi
done < <(find "${output_dir}/versioning" -mindepth 1 -name \*.${SETTINGS_VERSIONING_FILE_EXTENSION} -type f -print0)
echo "Done."
else
echo "MSM was not updated."
fi
echo "Done."
else
echo "MSM was not updated."
fi
# This script will now be replaced. So run the new script's