-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusr.sh
More file actions
155 lines (121 loc) · 5.1 KB
/
usr.sh
File metadata and controls
155 lines (121 loc) · 5.1 KB
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
#!/bin/bash
#
# Instrucciones: https://github.com/LomotHo/minecraft-bedrock
# Instrucciones en Español: https://gorobeta.blogspot.com
# Repositorio de GitHub: https://github.com/digiraldo/Minecraft-BE-Server-Panel-Admin-Web
# Colores del terminal
BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
LIME_YELLOW=$(tput setaf 190)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)
BRIGHT=$(tput bold)
NORMAL=$(tput sgr0)
BLINK=$(tput blink)
REVERSE=$(tput smso)
UNDERLINE=$(tput smul)
# Imprime una línea con color usando códigos de terminal
Print_Style() {
printf "%s\n" "${2}$1${NORMAL}"
}
# Función para leer la entrada del usuario con un mensaje
function read_with_prompt {
variable_name="$1"
prompt="$2"
default="${3-}"
unset $variable_name
while [[ ! -n ${!variable_name} ]]; do
read -p "$prompt: " $variable_name < /dev/tty
if [ ! -n "`which xargs`" ]; then
declare -g $variable_name=$(echo "${!variable_name}" | xargs)
fi
declare -g $variable_name=$(echo "${!variable_name}" | head -n1 | awk '{print $1;}')
if [[ -z ${!variable_name} ]] && [[ -n "$default" ]] ; then
declare -g $variable_name=$default
fi
echo -n "$prompt : ${!variable_name} -- aceptar? (y/n)"
read answer < /dev/tty
if [ "$answer" == "${answer#[Yy]}" ]; then
unset $variable_name
else
echo "$prompt: ${!variable_name}"
fi
done
}
cd ~
if [ ! -n "`which sudo`" ]; then
apt-get update && apt-get install sudo -y
fi
sudo apt-get update
sudo apt-get install sed -y
echo "========================================================================="
echo "Crea el Nombre de usuario (predeterminado user): "
Print_Style "Valores permitidos: "Maysculas", "Minusculas": Sin Espacios " "$CYAN"
read_with_prompt UserName "Nombre de Usuario" user
echo "========================================================================="
echo "========================================================================="
Print_Style "Creando Usuario $UserName" "$GREEN"
sudo useradd -u 0 -o -g 0 $UserName
sleep 2s
echo "========================================================================="
echo "========================================================================="
Print_Style "Configurando contraseña del usuario $UserName" "$GREEN"
sudo passwd $UserName
sleep 2s
echo "========================================================================="
echo "========================================================================="
Print_Style "Creando directorio /home/$UserName" "$GREEN"
sudo mkdir /home/$UserName
sleep 2s
echo "========================================================================="
echo "========================================================================="
Print_Style "Creando Grupo para el usuario $UserName" "$GREEN"
sudo chown $UserName:root -R /home/$UserName
sleep 2s
echo "========================================================================="
echo "========================================================================="
Print_Style "Generando Permisos" "$GREEN"
sudo chmod 775 -R /home/$UserName
sleep 2s
echo "========================================================================="
echo "========================================================================="
Print_Style "Asignando Directorio Principal: /home/$UserName al Usuario: $UserName" "$GREEN"
sudo usermod -d /home/$UserName $UserName
sleep 2s
echo "========================================================================="
echo "========================================================================="
Print_Style "Asignando Grupo: $UserName y root a Usuario: $UserName" "$GREEN"
sudo adduser $UserName $UserName
sudo adduser $UserName root
sleep 2s
sudo addgroup $UserName
sudo addgroup root
sleep 2s
echo "========================================================================="
echo "========================================================================="
Print_Style "Asignando shell: bash" "$GREEN"
sudo usermod -s /bin/bash
sudo usermod --shell /bin/bash --home /home/$UserName $UserName
cp /etc/skel/.* /home/$UserName/
sleep 2s
echo "========================================================================="
# Print_Style "Asignando permisos root a $UserName" "$MAGENTA"
# sudo sed -i "/Username ALL\=\(ALL\) NOPASSWD\: ALL/d" /etc/sudoers
# sudo sed -i "$a Username ALL\=\(ALL\) NOPASSWD\: ALL" /etc/sudoers
# sudo sed -n "/Username ALL\=\(ALL\) NOPASSWD\: ALL/p" /etc/sudoers
# sudo sed -i "s:Username:$UserName:g" /etc/sudoers
Print_Style "Asignando permisos root a $UserName" "$MAGENTA"
# Elimina lineas que contenga /Username ALL=(ALL) NOPASSWD: ALL
sudo sed -i "/Username ALL\=\(ALL\) NOPASSWD\: ALL/d" /etc/sudoers
# Crea linea /Username ALL=(ALL) NOPASSWD: ALL al final del archivo
sudo sed -i "$a Username ALL\=\(ALL\) NOPASSWD\: ALL" /etc/sudoers
# Muestra linea /Username ALL=(ALL) NOPASSWD: ALL del archivo
sudo sed -n "/Username ALL\=\(ALL\) NOPASSWD\: ALL/p" /etc/sudoers
# Cambia /Username por el nombre de usuario
sudo sed -i "s:Username:$UserName:g" /etc/sudoers
sudo chmod 755 -R /home/$UserName
sudo rm -rf usr.sh