Update r14-xdg-update script to allow any user to run the script

against any user directory and to remove bashisms.
pull/2/head
Darrell Anderson 13 years ago
parent 1f1dbc20ea
commit 092b8253e8

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
# #
# A script to perform R14.0.0 XDG compliance updates. # A script to perform R14.0.0 XDG compliance updates.
@ -36,16 +36,16 @@ fi
} }
Display_Message () { Display_Message () {
if [ "$UID" != "0" ] && [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then if [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then
echo -e "$MESSAGE" | xmessage -center -file - > /dev/null 2>/dev/null printf "%b" "$MESSAGE" | xmessage -center -file - > /dev/null 2>/dev/null
else else
echo -e "$MESSAGE" printf "%b" "$MESSAGE"
fi fi
} }
Message_Prefix () { Message_Prefix () {
if [ "$UID" != "0" ] && [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then if [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then
echo -n "[r14-xdg-update] " printf "%s" "[r14-xdg-update] "
fi fi
} }
@ -60,16 +60,30 @@ fi
# Main script: # Main script:
# Allow forced execution of this script regardless of the kdeglobals setting. SCRIPT_NAME="`basename \`readlink -f $0\``"
if [ "$1" = "force" ]; then
# Allow forced execution of this script regardless of the kdeglobals setting
# and allow passing a user home directory as a positional parameter.
if [ "$#" -eq "2" ]; then
if [ "$1" = "force" ] || [ "$2" = "force" ]; then
FORCE="true"
fi
if [ "$1" != "force" ]; then
USER_DIR="$1"
elif [ "$2" != "force" ]; then
USER_DIR="$2"
fi
elif [ "$#" -eq "1" ]; then
if [ "$1" = "force" ]; then
FORCE="true" FORCE="true"
else
USER_DIR="$1"
fi
fi fi
SCRIPT_NAME="`basename \`readlink -f $0\``"
unset KDEGLOBALS_KEY_VALUE unset KDEGLOBALS_KEY_VALUE
WARNING_MESSAGE="Trinity R14 XDG compliance updates will not be performed automatically.\n\nWithout R14 XDG compliance updates, some Trinity apps will fail to\nfunction properly.\n\nFailures include the following:\n\n* Many left-side icon lists will not populate,\n such as the Panel and Konqueror configuration dialogs.\n\n* User-defined keyboard shortcuts fail (khotkeysrc).\n System defined shortcuts remain functional.\n\n* User-defined app preferences fail (profilerc).\n\n* Konqueror navigation/sidebar panel won't open.\n\n* User-defined konqueror service menus, kicker customization,\n konqueror sidebar, Recent Documents list fail.\n\nPlease take appropriate action.\n" WARNING_MESSAGE="Trinity R14 XDG compliance updates will not be performed.\n\nWithout R14 XDG compliance updates, some Trinity apps will fail to\nfunction properly.\n\nFailures include the following:\n\n* Many left-side icon lists will not populate,\n such as the Panel and Konqueror configuration dialogs.\n\n* User-defined keyboard shortcuts fail (khotkeysrc).\n System defined shortcuts remain functional.\n\n* User-defined app preferences fail (profilerc).\n\n* Konqueror navigation/sidebar panel won't open.\n\n* User-defined konqueror service menus, kicker customization,\n* konqueror sidebar, Recent Documents list fail.\n\nPlease exercise appropriate action.\n"
# As the user should not be logged into a Trinity session when running # As the user should not be logged into a Trinity session when running
# this script, or an administrator might run this script remotely, the # this script, or an administrator might run this script remotely, the
@ -77,29 +91,25 @@ WARNING_MESSAGE="Trinity R14 XDG compliance updates will not be performed automa
# We presume $USER_DIR/.trinity and provide a way to pass an environment # We presume $USER_DIR/.trinity and provide a way to pass an environment
# variable to change that location. # variable to change that location.
USER_DIR=${USER_DIR:-"$HOME"} USER_DIR=${USER_DIR:-"$HOME"}
if [ "$USER_DIR" != "$HOME" ] && [ "$UID" != "0" ]; then if [ "$USER_DIR" != "$HOME" ]; then
echo "root privileges are required to run this script against other user directories. Exiting." PROFILE_DIR=${PROFILE_DIR:-"$USER_DIR/.trinity"}
exit 1
fi
if [ "$USER_DIR" != "$HOME" ] && [ "$UID" = "0" ]; then
PROFILE_DIR="$USER_DIR/.trinity"
elif [ "$TDEHOME" = "" ]; then elif [ "$TDEHOME" = "" ]; then
PROFILE_DIR="$USER_DIR/.trinity" PROFILE_DIR=${PROFILE_DIR:-"$USER_DIR/.trinity"}
else else
PROFILE_DIR="$TDEHOME" PROFILE_DIR="$TDEHOME"
fi fi
if [ ! -d "$PROFILE_DIR" ]; then if [ ! -d "$PROFILE_DIR" ]; then
MESSAGE="Warning! Unable to find the user profile directory $PROFILE_DIR.\n\n${WARNING_MESSAGE}" MESSAGE="Warning! Unable to find the user profile directory $PROFILE_DIR.\n\nCheck permissions, paths, and typing.\n\n${WARNING_MESSAGE}"
# Are we in X? Display an X dialog explaining breakage. # Are we in X? Display an X dialog explaining breakage.
if [ "$UID" != "0" ] && [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then if [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then
echo -e "$MESSAGE" | xmessage -center -file - -buttons Continue,Quit > /dev/null 2>/dev/null printf "%b" "$MESSAGE" | xmessage -center -file - -buttons Continue,Quit > /dev/null 2>/dev/null
if [ "$?" = "102" ]; then if [ "$?" = "102" ]; then
# User selected the Quit button: quit this script. # User selected the Quit button: quit this script.
unset PROFILE_DIR unset PROFILE_DIR
fi fi
else else
Message_Prefix Message_Prefix
echo -e "$MESSAGE" printf "%b" "$MESSAGE"
fi fi
exit 1 exit 1
fi fi
@ -115,8 +125,8 @@ if [ -x $BIN_DIR/tde-config ]; then
else else
MESSAGE="Unable to determine the TDE bin directory, where this script should be located." MESSAGE="Unable to determine the TDE bin directory, where this script should be located."
# Are we in X? Display an X dialog explaining breakage. # Are we in X? Display an X dialog explaining breakage.
if [ "$UID" != "0" ] && [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then if [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then
echo -e "$MESSAGE" | xmessage -center -file - -buttons Continue,Quit > /dev/null 2>/dev/null printf "%b" "$MESSAGE" | xmessage -center -file - -buttons Continue,Quit > /dev/null 2>/dev/null
if [ "$?" = "102" ]; then if [ "$?" = "102" ]; then
# User selected the Quit button: quit this script. # User selected the Quit button: quit this script.
unset PROFILE_DIR unset PROFILE_DIR
@ -124,7 +134,7 @@ else
fi fi
else else
Message_Prefix Message_Prefix
echo -e "$MESSAGE\n\n${WARNING_MESSAGE}" printf "%b" "$MESSAGE\n\n${WARNING_MESSAGE}"
fi fi
exit 1 exit 1
fi fi
@ -132,15 +142,28 @@ unset BIN_DIR
Message_Prefix Message_Prefix
echo "Performing a profile update for Trinity release R14 XDG compliance." echo "Performing a profile update for Trinity release R14 XDG compliance."
echo Message_Prefix
echo "To run this script as root or automated from within another script," echo "To run this script against a different user directory, or automated"
echo "set the \$USER_DIR environment variable before running the script." Message_Prefix
echo "For example: USER_DIR=/home/user_name r14-xdg-update" echo "from within another script, pass the directory path as a parameter."
echo Message_Prefix
echo "For example: r14-xdg-update /home/user_dir"
Message_Prefix
echo "Use the user home directory and not the profile directory."
Message_Prefix Message_Prefix
echo "User directory: $USER_DIR" echo "User directory: $USER_DIR"
Message_Prefix
echo "Profile directory: $PROFILE_DIR" echo "Profile directory: $PROFILE_DIR"
echo if [ "$USER_DIR" != "$HOME" ]; then
Message_Prefix
echo "Root (admin) privileges might be required to run this script"
Message_Prefix
echo "against other user directories."
Message_Prefix
echo "This script is being run against $USER_DIR."
Message_Prefix
echo "Your normal user directory is $HOME."
fi
# Do not update when $TDEHOME is a sym link to another profile directory. Trinity should have # Do not update when $TDEHOME is a sym link to another profile directory. Trinity should have
# full reign within its own profile directory (limited to administrative locking), but the error # full reign within its own profile directory (limited to administrative locking), but the error
@ -149,9 +172,9 @@ TDEHOME_LINK="`readlink \"$PROFILE_DIR\"`"
if [ "$TDEHOME_LINK" != "" ]; then if [ "$TDEHOME_LINK" != "" ]; then
# Force this entry to ensure the updates eventually are performed should the user copy the # Force this entry to ensure the updates eventually are performed should the user copy the
# original kdeglobals file into a new Trinity profile. # original kdeglobals file into a new Trinity profile.
# $TDEDIR/bin/kwriteconfig --file "$PROFILE_DIR/share/config/kdeglobals" --group "R14 XDG Updates" --key Updated --type bool 'false' # $TDEDIR/bin/kwriteconfig --file "$PROFILE_DIR/share/config/kdeglobals" --group "R14 XDG Updates" --key Updated --type bool 'false'
# Are we in X? Display an X dialog explaining breakage. # Are we in X? Display an X dialog explaining breakage.
if [ "$UID" != "0" ] && [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then if [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then
echo "[r14-xdg-update] Warning! The profile directory $PROFILE_DIR is a" 1>&2 echo "[r14-xdg-update] Warning! The profile directory $PROFILE_DIR is a" 1>&2
echo " sym link to $TDEHOME_LINK!" 1>&2 echo " sym link to $TDEHOME_LINK!" 1>&2
echo " R14 updates will not be performed because Trinity needs its own" 1>&2 echo " R14 updates will not be performed because Trinity needs its own" 1>&2
@ -160,9 +183,9 @@ if [ "$TDEHOME_LINK" != "" ]; then
fi fi
MESSAGE="Oops! The profile directory $PROFILE_DIR is a sym link to $TDEHOME_LINK.\n\n${WARNING_MESSAGE}\nPossible remedies:\n\n* Contact your system administrator.\n\n* Break the sym link to force creating a fresh Trinity profile.\n\n* Use the migratekde3 script to migrate a KDE3 profile to Trinity." MESSAGE="Oops! The profile directory $PROFILE_DIR is a sym link to $TDEHOME_LINK.\n\n${WARNING_MESSAGE}\nPossible remedies:\n\n* Contact your system administrator.\n\n* Break the sym link to force creating a fresh Trinity profile.\n\n* Use the migratekde3 script to migrate a KDE3 profile to Trinity."
# Are we in X? Display an X dialog explaining breakage. # Are we in X? Display an X dialog explaining breakage.
if [ "$UID" != "0" ] && [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then if [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then
MESSAGE="${MESSAGE}\n\nSelecting the Continue button means retaining the KDE3 profile and\nbreaking the sym link. With the sym link broken, run the migratekde3\nscript before restarting Trinity to migrate a KDE3 profile or\nallow Trinity to create a fresh profile." MESSAGE="${MESSAGE}\n\nSelecting the Continue button means retaining the KDE3 profile and\nbreaking the sym link. With the sym link broken, run the migratekde3\nscript before restarting Trinity to migrate a KDE3 profile or\nallow Trinity to create a fresh profile."
echo -e "$MESSAGE" | xmessage -center -file - -buttons Continue,Quit > /dev/null 2>/dev/null printf "%b" "$MESSAGE" | xmessage -center -file - -buttons Continue,Quit > /dev/null 2>/dev/null
EXIT_CODE="$?" EXIT_CODE="$?"
unset TDEHOME_LINK unset TDEHOME_LINK
if [ "$EXIT_CODE" = "102" ]; then if [ "$EXIT_CODE" = "102" ]; then
@ -179,7 +202,7 @@ if [ "$TDEHOME_LINK" != "" ]; then
fi fi
else else
echo echo
echo -e "$MESSAGE" printf "%b" "$MESSAGE"
echo echo
Wait_For_Response "Break the sym link now?" Wait_For_Response "Break the sym link now?"
Proceed_From_Response Proceed_From_Response
@ -189,14 +212,14 @@ if [ "$TDEHOME_LINK" != "" ]; then
unlink "$USER_DIR/.trinity" 2>/dev/null unlink "$USER_DIR/.trinity" 2>/dev/null
if [ "`readlink \"$USER_DIR/.trinity\"`" = "" ]; then if [ "`readlink \"$USER_DIR/.trinity\"`" = "" ]; then
MESSAGE="Sym link broken. With the sym link broken, run the migratekde3\nscript before restarting Trinity to migrate a KDE3 profile or\nallow Trinity to create a fresh profile." MESSAGE="Sym link broken. With the sym link broken, run the migratekde3\nscript before restarting Trinity to migrate a KDE3 profile or\nallow Trinity to create a fresh profile."
if [ "$UID" != "0" ] && [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then if [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then
Message_Prefix Message_Prefix
fi fi
echo -e "$MESSAGE" printf "%b" "$MESSAGE"
echo echo
else else
MESSAGE="Unable to break the sym link. Check file and directory privileges. Quitting." MESSAGE="Unable to break the sym link. Check file and directory privileges. Quitting."
if [ "$UID" != "0" ] && [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then if [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then
Message_Prefix Message_Prefix
fi fi
echo "$MESSAGE" echo "$MESSAGE"
@ -219,8 +242,8 @@ if [ "$R14_UPDATED" != "true" ] || [ "$FORCE" = "true" ]; then
echo echo
MESSAGE="The r14-xdg-update script has been run at least once.\n\nThe script is not successfully updating.\n\nThe script will run with each login until corrected.\n\nPlease contact an administrator or take appropriate\nadmininstrative action to correct the problem.\n\nThe error code is $R14_UPDATED." MESSAGE="The r14-xdg-update script has been run at least once.\n\nThe script is not successfully updating.\n\nThe script will run with each login until corrected.\n\nPlease contact an administrator or take appropriate\nadmininstrative action to correct the problem.\n\nThe error code is $R14_UPDATED."
# Are we in X? Display an X dialog explaining breakage. # Are we in X? Display an X dialog explaining breakage.
if [ "$UID" != "0" ] && [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then if [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then
echo -e "$MESSAGE" | xmessage -center -file - -buttons Continue,Quit > /dev/null 2>/dev/null printf "%b" "$MESSAGE" | xmessage -center -file - -buttons Continue,Quit > /dev/null 2>/dev/null
if [ "$?" = "102" ]; then if [ "$?" = "102" ]; then
# User select the Quit button: quit this script. # User select the Quit button: quit this script.
unset PROFILE_DIR unset PROFILE_DIR
@ -236,11 +259,11 @@ fi
# Trap when the user runs this script while in a Trinity session. # Trap when the user runs this script while in a Trinity session.
# Most files can be updated "live" but some can't, such as kdeglobals. # Most files can be updated "live" but some can't, such as kdeglobals.
if [ "$USER_DIR" = "$HOME" ] && [ "$UID" != "0" ]; then if [ "$USER_DIR" = "$HOME" ]; then
if [ "$TDE_FULL_SESSION" != "" ] || [ "$TDE_SESSION_UID" != "" ]; then if [ "$TDE_FULL_SESSION" != "" ] || [ "$TDE_SESSION_UID" != "" ]; then
MESSAGE="You are running this script from within a Trinity session.\n\nMost files can be updated \"live\" but some cannot, such as kdeglobals.\n\nThis script might complete successfully and might not." MESSAGE="You are running this script from within a Trinity session.\n\nMost files can be updated \"live\" but some cannot, such as kdeglobals.\n\nThis script might complete successfully and might not."
# Are we in X? Display an X dialog explaining breakage. # Are we in X? Display an X dialog explaining breakage.
if [ "$UID" != "0" ] && [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then if [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then
# As we are in a Trinity session then use kdialog. # As we are in a Trinity session then use kdialog.
kdialog --title "R14-XDG-Update" --warningyesno "${MESSAGE}\n\nContinue?" kdialog --title "R14-XDG-Update" --warningyesno "${MESSAGE}\n\nContinue?"
if [ "$?" -gt "0" ]; then if [ "$?" -gt "0" ]; then
@ -249,7 +272,7 @@ if [ "$USER_DIR" = "$HOME" ] && [ "$UID" != "0" ]; then
fi fi
else else
Message_Prefix Message_Prefix
echo -e "$MESSAGE\n\n${WARNING_MESSAGE}" printf "%b" "$MESSAGE\n\n${WARNING_MESSAGE}"
Wait_For_Response "Continue?" Wait_For_Response "Continue?"
Proceed_From_Response Proceed_From_Response
fi fi
@ -468,11 +491,11 @@ else
$TDEDIR/bin/kwriteconfig --file "$PROFILE_DIR/share/config/kdeglobals" --group "R14 XDG Updates" --key Updated "$KDEGLOBALS_KEY_VALUE" $TDEDIR/bin/kwriteconfig --file "$PROFILE_DIR/share/config/kdeglobals" --group "R14 XDG Updates" --key Updated "$KDEGLOBALS_KEY_VALUE"
MESSAGE="The r14-xdg-update script did not complete successfully.\n\nThe script will run with each login until corrected.\n\nPlease contact an administrator or take appropriate\nadmininstrative action to correct the problem.\n\nThe error code is $KDEGLOBALS_KEY_VALUE.\n\nBe sure to check file and directory permissions." MESSAGE="The r14-xdg-update script did not complete successfully.\n\nThe script will run with each login until corrected.\n\nPlease contact an administrator or take appropriate\nadmininstrative action to correct the problem.\n\nThe error code is $KDEGLOBALS_KEY_VALUE.\n\nBe sure to check file and directory permissions."
# Are we in X? Display an X dialog explaining breakage. # Are we in X? Display an X dialog explaining breakage.
if [ "$UID" != "0" ] && [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then if [ "$USER_DIR" = "$HOME" ] && [ "$DISPLAY" != "" ]; then
echo -e "$MESSAGE" | xmessage -center -file - -buttons OK > /dev/null 2>/dev/null printf "%b" "$MESSAGE" | xmessage -center -file - -buttons OK > /dev/null 2>/dev/null
else else
Message_Prefix Message_Prefix
echo -e "$MESSAGE" printf "%b" "$MESSAGE"
fi fi
fi fi

Loading…
Cancel
Save