forked from Notos/seedbox-from-scratch
-
Notifications
You must be signed in to change notification settings - Fork 17
/
RDPconfig.sh
executable file
·146 lines (125 loc) · 4.21 KB
/
RDPconfig.sh
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
#!/bin/bash
export LANG="C"
id=`id -u`
#################################################################
# Initialise variables and parse any command line switches here #
#################################################################
INTERACTIVE=1
#Identify Distro
Dist=`lsb_release -d -s`
backtitle="LXDE Desktop RDP Config"
questiontitle="Which Users..."
title="Configurator"
DIALOG="dialog"
###############################################
# Text/dialog front-end function declarations #
###############################################
let "HEIGHT = $LINES - 3"
let "WIDTH = $COLUMNS - 8"
# Display a message box
info_window()
{
dialog --backtitle "$backtitle" --title "$title" --msgbox "$dialogtext" 0 0
}
ask_question()
{
dialog --backtitle "$backtitle" --title "$questiontitle" --yesno "$dialogtext" 0 0
Answer=$?
}
apt_update_interactive()
{
sudo apt-get update | dialog --progressbox "Updating package databases..." 30 100
}
# Reads all normal (non-system) accounts
select_local_user_accounts_to_config()
{
if [ -e ./usernames.tmp ]
then
rm -f ./usernames.tmp
fi
getent passwd>/tmp/passwd
userlist=""
usercount=0
linecount=`cat /tmp/passwd | wc -l`
processed=0
percent=0
title="Processing local users in /etc/passwd..."
hit=""
uidmin=`grep '^UID_MIN' /etc/login.defs`
uidmin=${uidmin/#UID_MIN/}
( while read line
do
userno=`echo $line | cut -d":" -f3`
if [ $userno -ge $uidmin ] && [ $userno -lt 65534 ]
then
username=`echo $line | cut -d":" -f1`
if [[ $username != *$ && $username != *smbguest* ]]
then
realname=`echo $line | cut -d":" -f5 | cut -d"," -f1`
hit="\nAdded username $username to list."
let "usercount += 1"
echo "$username:$realname">> ./usernames.tmp
fi
fi
let "processed += 1"
percent=$((${processed}*100/${linecount}))
echo "Processed $processed of $linecount entries in /etc/passwd ...$hit"
echo XXX
echo $percent
done </tmp/passwd ) | dialog --backtitle "$backtitle" --title "$title" "$@" --gauge "Processing..." 15 75 0
allusers=""
usercount=0
while read line
do
username=$(echo $line | cut -d":" -f1)
allusers="$allusers $username"
realname=$(echo $line | cut -d":" -f2)
if [ $usercount == 0 ]
then
userlist=("ALL USERS" "Select all users on this list" off "${username[@]}" "${realname[@]}" off )
else
userlist=("${userlist[@]}" "${username[@]}" "${realname[@]}" off )
fi
let "usercount += 1"
done < ./usernames.tmp
windowsize=(0 0 0)
dialog_param=("--separate-output" "--backtitle" "$backtitle" "--checklist" "Select the user accounts you wish to configure RDP on" "${windowsize[@]}" "${userlist[@]}")
selectedusers=$(dialog "${dialog_param[@]}" 2>&1 >/dev/tty)
echo allusers = $allusers
if [ "$selectedusers" == "" ]
then
dialog --backtitle "$backtitle" --title "No Users Were Selected" --msgbox "\nYou did not select any users!\n\nQuitting the utility now.\n\nClick OK to exit.\n\n" 0 0
exit
fi
if [ "$selectedusers" == "ALL USERS" ]
then
selectedusers=$allusers
fi
rm ./usernames.tmp
}
# creates a .xsession file for each selected local user account
# based on the selected desktop environment
create_xsession()
{
( for username in $selectedusers
do
homedir=`grep "^$username:" /tmp/passwd | cut -d":" -f6`
sudo echo "Creating .xsession file for $username in $homedir" 2>&1
sudo echo "lxsession -s LXDE -e LXDE" > $homedir/.xsession
usergroup=`id -gn $username`
sudo chown $username:$usergroup $homedir/.xsession
sudo chmod u+x $homedir/.xsession
done) | dialog --backtitle "$backtitle" --title "creating .xsession files..." --progressbox "Processing..." 12 80
sleep 3
}
##########################################################
######## End of internal function declarations ###########
##########################################################
##############################################
######## Main routine starts here ############
##############################################
select_local_user_accounts_to_config
create_xsession
rm /tmp/passwd
dialogtext="\nAll selected operations are complete!\n\nThe users you configured will be able to log in via RDP now and be presented with the Mate desktop.\n\n\n\nClick OK to exit the utility.\n\n"
info_window