aboutsummaryrefslogtreecommitdiff
path: root/tools/Linux/packaging
diff options
context:
space:
mode:
authorceros7 <ceros7@svn>2009-12-02 01:31:43 +0000
committerceros7 <ceros7@svn>2009-12-02 01:31:43 +0000
commitd9cc521a033a44465b9b8c58564c586c6b2152e3 (patch)
tree93701605518302e120e8a292b07d3735267388ff /tools/Linux/packaging
parent19cb47ff402b9d07999e2f43a6e57a0a8772bd00 (diff)
Implement new way of editing /etc/sudoers for xbmc-live. This uses visudo for checking.
This allows for fixing the /etc/sudoers file via dpkg-reconfigure xbmc-live. The xbmc-live postrm script also only deletes the specific XBMC lines now. git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@25202 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
Diffstat (limited to 'tools/Linux/packaging')
-rwxr-xr-xtools/Linux/packaging/debian/xbmc-live.postinst42
-rwxr-xr-xtools/Linux/packaging/debian/xbmc-live.postrm36
2 files changed, 76 insertions, 2 deletions
diff --git a/tools/Linux/packaging/debian/xbmc-live.postinst b/tools/Linux/packaging/debian/xbmc-live.postinst
index 00569ee901..ce83b461b4 100755
--- a/tools/Linux/packaging/debian/xbmc-live.postinst
+++ b/tools/Linux/packaging/debian/xbmc-live.postinst
@@ -55,6 +55,48 @@ case "$1" in
fi
done
+ SUDOERS="$(cat /etc/sudoers)"
+
+ XBMC_ENTRIES="### XBMC-specific configuration ###
+ # XBMC
+ Cmnd_Alias SHUTDOWN_CMDS = /sbin/shutdown, /sbin/reboot, /sbin/halt # XBMC
+ Cmnd_Alias MOUNT_CMDS = /bin/mount, /bin/umount # XBMC
+ $xbmcUser ALL=(ALL) ALL # XBMC
+ $xbmcUser ALL=NOPASSWD: SHUTDOWN_CMDS, MOUNT_CMDS # XBMC"
+
+ SUDOERS_TEMPFILE=$(mktemp -q)
+
+ # Add xbmc to the sudoers file (if not already done)
+ # Here we make use of perl to check the current sudoers file and create one
+ # for us in case we need to add the xbmc specific entries.
+ if ! perl -e '$sudoers=$ARGV[0]; $entries=$ARGV[1];' \
+ -e '$entries =~ s/^\s*?(\S)/$1/msg;' \
+ -e '($sudoers =~ m/$entries/ms) ? exit 0 : exit 1;' \
+ "$SUDOERS" "$XBMC_ENTRIES"; then
+
+ # First write a sudoers file to a tempfile.
+ perl -e '$sudoers=$ARGV[0]; $entries=$ARGV[1];' \
+ -e '$entries =~ s/^\s*?(\S)/$1/msg;' \
+ -e '$sudoers =~ s/\Q### XBMC-specific configuration ###\E\n//g;' \
+ -e '$sudoers =~ s/\n.*# XBMC.*//g;' \
+ -e 'chomp $sudoers;' \
+ -e 'print "$sudoers\n\n$entries\n";' \
+ "$SUDOERS" "$XBMC_ENTRIES" >$SUDOERS_TEMPFILE
+
+ # Check if sudoers file is ok with visudo and write to /etc/sudoers if
+ # it is ok, else display a message to the user.
+ if visudo -c -f $SUDOERS_TEMPFILE >/dev/null 2>&1; then
+ cat $SUDOERS_TEMPFILE >/etc/sudoers
+ else
+ # TODO: Use debconf for this message.
+ echo "Couldn't edit /etc/sudoers, must be manually edited."
+ echo "Please edit /etc/sudoers using 'visudo' and add the following"
+ echo "entries:"
+ echo "$XBMC_ENTRIES"
+ fi
+ fi
+ rm $SUDOERS_TEMPFILE
+
# Our set of PolicyKit actions
# This is a list of actions that the 'xbmc' user should be allowed to
diff --git a/tools/Linux/packaging/debian/xbmc-live.postrm b/tools/Linux/packaging/debian/xbmc-live.postrm
index edb680ff61..f067ad3b1d 100755
--- a/tools/Linux/packaging/debian/xbmc-live.postrm
+++ b/tools/Linux/packaging/debian/xbmc-live.postrm
@@ -4,8 +4,40 @@
# see: dh_installdeb(1)
set -e
-if [ "$1" = "purge" ]
-then
+if [ "$1" = "purge" ]; then
+ SUDOERS="$(cat /etc/sudoers)"
+
+ SUDOERS_TEMPFILE=$(mktemp -q)
+
+ # Check if there are XBMC specific entries in /etc/sudoers and remove
+ # them if so. This makes use of perl for checking and writing a sudoers
+ # file
+ if perl -e '$sudoers=$ARGV[0]; $entries=$ARGV[1];' \
+ -e '($sudoers =~ m/$entries/ms) ? exit 0 : exit 1;' \
+ "$SUDOERS" "### XBMC-specific configuration ###"; then
+
+ # First write a sudoers file to a tempfile.
+ perl -e '$sudoers=$ARGV[0];' \
+ -e '$sudoers =~ s/\Q### XBMC-specific configuration ###\E\n//g;' \
+ -e '$sudoers =~ s/\n.*# XBMC.*//g;' \
+ -e 'chomp $sudoers;' \
+ -e 'print "$sudoers\n";' \
+ "$SUDOERS" >$SUDOERS_TEMPFILE
+
+ # Check if sudoers file is ok with visudo and write to /etc/sudoers if
+ # it is ok, else display a message to the user.
+ if visudo -c -f $SUDOERS_TEMPFILE >/dev/null 2>&1; then
+ cat $SUDOERS_TEMPFILE >/etc/sudoers
+ else
+ # TODO: Use debconf for this message.
+ echo "Couldn't edit /etc/sudoers, must be manually edited."
+ echo "Please edit /etc/sudoers using 'visudo' and add the following"
+ echo "entries:"
+ echo "$XBMC_ENTRIES"
+ fi
+ fi
+ rm $SUDOERS_TEMPFILE
+
POLKIT_ACTIONS="org.freedesktop.hal.dockstation.undock
org.freedesktop.hal.wol.enabled
org.freedesktop.hal.wol.enable