File: tune-debian-dev-group-perm

package info (click to toggle)
drbl 5.7.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,984 kB
  • sloc: sh: 43,522; perl: 8,820; xml: 867; makefile: 131
file content (168 lines) | stat: -rwxr-xr-x 4,621 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
# Author: Steven Shiau <steven _at_ clonezilla org>
# License: GPL 
# Description: DRBL utitilty to add users to group plugdev, audio... devices
# Ref: http://drbl.org/faq/index.php#path=./2_System&entry=05_usb_sound.faq

# Load DRBL setting and functions
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions

# Some default setting for Debian
# dialout:x:20
# cdrom:x:24:
# floppy:x:25:
# audio:x:29:
# video:x:44:
# plugdev:x:46:

prog="$(basename $0)"
usage() {
  echo "Enable or disable audio, plugdev permission... to all users."
  echo "Usage: $0 [Options]"
  echo "Options:"
  language_help_prompt_by_idx_no
  echo "-g, --group [GROUP1, GROUP2...]: Assign the GROUP1, GROUP2... to be process"
  echo "-e, --enable        Enable GROUP open to all users"
  echo "-d, --disable       Disable GROUP open to all users"
  echo "-n, --no-update-yp  Do NOT update YP/NIS"
  echo "-r, --no-restart-prompt  Do not show the prompt to restart X"
  echo "-v, --verbose       Prints out verbose information"
  echo 
  echo "Ex:"
  echo "$0 -g \"$desktop_user_group_debian\" -e"
}

# functions
enable_group() {
  local tune_group="$1"
  if [ -z "$tune_group" ]; then
    echo "No assigned tune group! Skip this!"
    return 3
  fi
  # For new device group, better to use
  # "find /usr /sbin /bin -group $tune_group -print" to show the related programs.
  if [ -z "$(grep -E "^$tune_group:" /etc/group)" ]; then
    echo "Group $tune_group does NOT exist! Skip open $tune_group!"
    return 1
  fi
  common_users="$(drbl-get-common-username 2>/dev/null)"
  for iuser in $common_users; do
    if [ "$iuser" != "nobody" -a -z "$(groups $iuser | grep $tune_group)" ]; then
      adduser $iuser $tune_group >/dev/null
    fi
  done
  grp_list="$(grep -E "^$tune_group:.*" /etc/group)"
  for ihost in $drbl_common_root/ $drblroot/* /; do
    if [ -f $ihost/etc/group ]; then
      perl -p -i -e "s/^$tune_group:.*/$grp_list/g" $ihost/etc/group
    fi
  done
} # end of enable_group

disable_group() {
  local tune_group="$1"
  if [ -z "$tune_group" ]; then
    echo "No assigned tune group! Skip this!"
    return 3
  fi
  if [ -z "$(grep "^$tune_group:" /etc/group)" ]; then
    echo "Group $tune_group does NOT exist! Skip open $tune_group!"
    return 1
  fi
  for ihost in $drbl_common_root/ $drblroot/* /; do
    if [ -f $ihost/etc/group ]; then
      # TO modify, make them sync
      perl -p -i -e "s/^($tune_group:.*:.*:).*/\$1/g" $ihost/etc/group
    fi
  done
} # end of disable_group

#
check_if_root

#
while [ $# -gt 0 ]; do
  case "$1" in
    -e|--enable) shift; MODE="enable" ;;
    -d|--disable) shift; MODE="disable" ;;
    -g|--group)
		shift;
                if [ -z "$(echo $1 |grep ^-.)" ]; then
                  # skip the -xx option, in case 
	          GRPS="$1"
		  shift
                fi
		;;
    -l|--language)
		shift;
                if [ -z "$(echo $1 |grep ^-.)" ]; then
                  # skip the -xx option, in case 
		  specified_lang="$1"
		  shift
                fi
		;;
    -n|--no-update-yp:) shift; YP_UPDATE="no" ;;
    -r|--no-restart-prompt) shift; RESTART_PROMPT="no" ;;
    -v|--verbose) shift; VERBOSE="on" ;;
    -*)		echo "${0}: ${1}: invalid option" >&2
		usage >& 2
		exit 2 ;;
    *)		break ;;
  esac
done

#
if [ ! -e /etc/debian_version ]; then
   echo "This is not Debian Linux! This program only works in Debian Linux!!! Program terminated!"
   exit 1
fi
#
ask_and_load_lang_set $specified_lang

[ -z "$GRPS" -o -z "$MODE" ] && usage && exit 1

echo "$msg_delimiter_star_line"
# Part 1: For audio device: dsp mixer
case "$MODE" in
  enable)
     echo -n "Adding normal users to group \"$GRPS\"..."
     for igrp in $GRPS; do
       echo -n "."
       enable_group $igrp
     done
     echo " done!"
     ;;
  disable)
     echo -n "Removing normal users from group \"$GRPS\"..."
     for igrp in $GRPS; do
       echo -n "."
       disable_group $igrp
     done
     echo " done!"
     ;;
esac

# update YP
if [ "$YP_UPDATE" != "no" ]; then
  echo "$msg_delimiter_star_line"
  echo "Updating the YP/NIS for group..."
  make -C /var/yp &>/dev/null
fi

# restart prompt
if [ "$RESTART_PROMPT" != "no" ]; then
  if [ "$MODE" = "enable" ]; then
    echo "$msg_delimiter_star_line"
    [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
    echo "$msg_restart_prompt_for_dev"
    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  fi
fi

[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
if [ "$MODE" = "enable" ]; then 
  echo "$msg_run_update_dev_again:"
  echo "$prog -g \"$GRPS\" -e"
fi
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL