install.sh 6.64 KB
Newer Older
Carlos Remuzzi's avatar
Carlos Remuzzi committed
1
2
# script basado en https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh

Carlos Remuzzi's avatar
Carlos Remuzzi committed
3
4
5
WIFI_INTERFACE=$(cat /proc/net/wireless | perl -ne '/(\w+):/ && print $1')
AP_PSK=libreCast
USER_NAME=$(whoami)
6
OS_RELEASE_FILE=/etc/os-release
Carlos Remuzzi's avatar
Carlos Remuzzi committed
7

Carlos Remuzzi's avatar
Carlos Remuzzi committed
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
verificar_debian_deps() {
  echo "Verificando dependencias ..."

  hash apt >/dev/null 2>&1 || {
    echo "Error: apt no detectado"
    echo "el presente script funciona solo en sistemas"
    echo "basados en Debian"
    exit 1
  }

  hash sudo >/dev/null 2>&1 || {
    echo "Error: sudo no está instalado"
    echo "Por favor contactar el administrador"
    echo "del equipo para proceder con la instalación"
    exit 1
  }

  hash git >/dev/null 2>&1 || {
    echo "Instalando git ..."
    sudo apt install git
  }

  hash gst-launch-1.0  >/dev/null 2>&1 || {
    echo "Instalando gstreamer1.0-tools ..."
    sudo apt install gstreamer1.0-tools
  }

  hash pacmd  >/dev/null 2>&1 || {
    echo "Instalando pulseaudio ..."
    sudo apt install pulseaudio-utils
  }

  hash curl >/dev/null 2>&1 || {
    echo "Instalando curl ..."
    sudo apt install curl
  }

  echo "dependencias OK"
}

verificar_archlinux_deps() {

  echo "Verificando dependencias para ArchLinux ..."
  hash sudo >/dev/null 2>&1 || {
    echo "Error: sudo no está instalado"
    echo "Por favor contactar el administrador"
    echo "del equipo para proceder con la instalación"
    exit 1
  }

  sudo pacman --needed -S git curl xorg-xdpyinfo gstreamer 
}

61
verificar_deps() {
62
63
64
65
66
  if [ -e ${OS_RELEASE_FILE}  ]; then
    . ${OS_RELEASE_FILE}
    echo "Se ha detectado la distro ${PRETTY_NAME} ..."
    case "${ID}-${VERSION_ID}" in
      arch-*)
67
68
        verificar_archlinux_deps
        ;;
69
70
71
      manjaro-*)
        verificar_archlinux_deps
        ;;
72
      ubuntu-18.04*)
73
74
        verificar_debian_deps
        ;;
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
      ubuntu-17.10*)
        verificar_debian_deps
        ;;
      ubuntu-17.04*)
        verificar_debian_deps
        ;;
      ubuntu-16.10*)
        verificar_debian_deps
        ;;
      ubuntu-16.04*)
        verificar_debian_deps
        ;;
      ubuntu-15.10*)
        verificar_debian_deps
        ;;
      ubuntu-15.04*)
        verificar_debian_deps
        ;;
      ubuntu-14.10*)
        verificar_debian_deps
        ;;
      ubuntu-14.04*)
97
98
        verificar_debian_deps
        ;;
99
100
101
      debian-10)
        verificar_debian_deps
        ;;
102
103
104
105
106
107
      debian-9)
        verificar_debian_deps
        ;;
      debian-8)
        verificar_debian_deps
        ;;
108
109
110
      trisquel-8.0)
	verificar_debian_deps
	;;
Rodrigo Garcia's avatar
Rodrigo Garcia committed
111
112
113
      deepin-15*)
	verificar_debian_deps
        ;;
114
      *)
115
116
        echo "ERROR: La distro ${PRETTY_NAME} no esta suportada" >&2
        # Aqui se deberia poder guiar el usuario hacia una instalacion manual
117
118
119
120
121
122
123
124
125
126
        exit 1
        ;;
    esac

  else
    echo "ERROR: Esta distro y/o version no esta suportada." >&2
    exit 1
  fi
}

Carlos Remuzzi's avatar
Carlos Remuzzi committed
127
128
129
130
configurar_ap(){
   if nmcli con show $1 > /dev/null 2>&1 ;then
     echo "la conexión $1 está ya instalada"
   else
Carlos Remuzzi's avatar
Carlos Remuzzi committed
131
     echo "creando nueva conexión $1"
132
133
134
135
     sudo nmcli con add con-name $1 ifname $WIFI_INTERFACE type wifi ssid $1 ip4 192.168.12.2/24 gw4 192.168.12.1
     sudo nmcli con modify $1 ipv4.dns "192.168.26.10"
     sudo nmcli con modify $1 connection.autoconnect no
     sudo nmcli con modify $1 wifi-sec.key-mgmt wpa-psk wifi-sec.psk $2
Carlos Remuzzi's avatar
Carlos Remuzzi committed
136
137
138
   fi
}

Carlos Remuzzi's avatar
Carlos Remuzzi committed
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
main() {
  # colores
  if which tput >/dev/null 2>&1; then
      ncolors=$(tput colors)
  fi
  if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
    RED="$(tput setaf 1)"
    GREEN="$(tput setaf 2)"
    YELLOW="$(tput setaf 3)"
    BLUE="$(tput setaf 4)"
    BOLD="$(tput bold)"
    NORMAL="$(tput sgr0)"
  else
    RED=""
    GREEN=""
    YELLOW=""
    BLUE=""
    BOLD=""
    NORMAL=""
  fi

Carlos Remuzzi's avatar
Carlos Remuzzi committed
160
  # Habilitación de exit-on-error después de colores 
Carlos Remuzzi's avatar
Carlos Remuzzi committed
161
162
  set -e

Carlos Remuzzi's avatar
Carlos Remuzzi committed
163
  verificar_deps
Carlos Remuzzi's avatar
Carlos Remuzzi committed
164

Carlos Remuzzi's avatar
Carlos Remuzzi committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
  if [ ! -n "$LIBRECAST" ]; then
    LIBRECAST=~/librecast
  fi

  if [ -d "$LIBRECAST" ]; then
    printf "${YELLOW}Ya tienes libreCast instalado.${NORMAL}\n"
    printf "tienes que eliminar $LIBRECAST si quieres re-instalar.\n"
    exit
  fi


  # Control de permisos, para evitar la clonacion del repo con privilegios
  # no deseados
  umask g-w,o-w

  printf "${BLUE}Clonando libreCast...${NORMAL}\n"

182
  env git clone https://gitlab.agetic.gob.bo/agetic/librecast.git $LIBRECAST || {
Carlos Remuzzi's avatar
Carlos Remuzzi committed
183
184
185
186
    printf "Error: el git clone del repo librecast ha fallado \n"
    exit 1
  }

Carlos Remuzzi's avatar
Carlos Remuzzi committed
187
  # esto tiene que adaptarse a diferentes distros
188

189
190
191
  mkdir -p $HOME/.local/share/applications
  cp $HOME/librecast/libreCast.desktop $HOME/.local/share/applications/libreCast-s1.desktop
  sed -i -e "s/USER/$USER_NAME/g" $HOME/.local/share/applications/libreCast-s1.desktop
192
193
194
195
196
197
198
199
200
201
  cp $HOME/.local/share/applications/libreCast-s1.desktop $HOME/.local/share/applications/libreCast-s2.desktop
  cp $HOME/.local/share/applications/libreCast-s1.desktop $HOME/.local/share/applications/libreCast-s3.desktop
  cp $HOME/.local/share/applications/libreCast-s1.desktop $HOME/.local/share/applications/libreCast-s4.desktop
  cp $HOME/.local/share/applications/libreCast-s1.desktop $HOME/.local/share/applications/libreCast-s5.desktop
  cp $HOME/.local/share/applications/libreCast-s1.desktop $HOME/.local/share/applications/libreCast-s6.desktop
  sed -i -e "s/libreCast-s1/libreCast-s2/g" $HOME/.local/share/applications/libreCast-s2.desktop
  sed -i -e "s/libreCast-s1/libreCast-s3/g" $HOME/.local/share/applications/libreCast-s3.desktop
  sed -i -e "s/libreCast-s1/libreCast-s4/g" $HOME/.local/share/applications/libreCast-s4.desktop
  sed -i -e "s/libreCast-s1/libreCast-s5/g" $HOME/.local/share/applications/libreCast-s5.desktop
  sed -i -e "s/libreCast-s1/libreCast-s6/g" $HOME/.local/share/applications/libreCast-s6.desktop
Carlos Remuzzi's avatar
Carlos Remuzzi committed
202

Carlos Remuzzi's avatar
Carlos Remuzzi committed
203
204
205
206
207
208
209
210
  if which nmcli >/dev/null 2>&1; then
    # esto tiene que cambiar
    # y jalar un archivo .yaml
    # de configuracion
    configurar_ap libreCast-s0 $AP_PSK
    configurar_ap libreCast-s1 $AP_PSK
    configurar_ap libreCast-s2 $AP_PSK
    configurar_ap libreCast-s3 $AP_PSK
211
212
213
    configurar_ap libreCast-s4 $AP_PSK
    configurar_ap libreCast-s5 $AP_PSK
    configurar_ap libreCast-s6 $AP_PSK
Carlos Remuzzi's avatar
Carlos Remuzzi committed
214
  else
Carlos Remuzzi's avatar
Carlos Remuzzi committed
215
216
217
    echo "Advertencia: nmcli no está instalado"
    echo "Será necesario configurar la conexión wifi manualmente"
    echo "Consultar la guía de instalación para mayores info"
218
    echo "https://gitlab.agetic.gob.bo/agetic/librecast/blob/master/INSTALL.md"
Carlos Remuzzi's avatar
Carlos Remuzzi committed
219
  fi
220

Carlos Remuzzi's avatar
Carlos Remuzzi committed
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
  printf "${GREEN}"
  echo '    ___ __              ______           __  '
  echo '   / (_) /_  ________  / ____/___ ______/ /_ '
  echo '  / / / __ \/ ___/ _ \/ /   / __ `/ ___/ __/ '
  echo ' / / / /_/ / /  /  __/ /___/ /_/ (__  ) /_   '
  echo '/_/_/_.___/_/   \___/\____/\__,_/____/\__/   '
  echo ''
  echo '                        ...ha sido instalado!'
  echo ''
  echo ''
  printf "${NORMAL}"
}

main