install.sh 6.47 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
99
100
101
102
103
104
105
        verificar_debian_deps
        ;;
      debian-9)
        verificar_debian_deps
        ;;
      debian-8)
        verificar_debian_deps
        ;;
      *)
106
107
        echo "ERROR: La distro ${PRETTY_NAME} no esta suportada" >&2
        # Aqui se deberia poder guiar el usuario hacia una instalacion manual
108
109
110
111
112
113
114
115
116
117
        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
118
119
120
121
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
122
     echo "creando nueva conexión $1"
Carlos Remuzzi's avatar
Carlos Remuzzi committed
123
     nmcli con add con-name $1 ifname $WIFI_INTERFACE type wifi ssid $1 ip4 192.168.12.2/24 gw4 192.168.12.1
Carlos Remuzzi's avatar
Carlos Remuzzi committed
124
     nmcli con modify $1 ipv4.dns "192.168.26.10"
Carlos Remuzzi's avatar
Carlos Remuzzi committed
125
126
127
128
129
     nmcli con modify $1 connection.autoconnect no
     nmcli con modify $1 wifi-sec.key-mgmt wpa-psk wifi-sec.psk $2
   fi
}

Carlos Remuzzi's avatar
Carlos Remuzzi committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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
151
  # Habilitación de exit-on-error después de colores 
Carlos Remuzzi's avatar
Carlos Remuzzi committed
152
153
  set -e

Carlos Remuzzi's avatar
Carlos Remuzzi committed
154
  verificar_deps
Carlos Remuzzi's avatar
Carlos Remuzzi committed
155

Carlos Remuzzi's avatar
Carlos Remuzzi committed
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
  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"

173
  env git clone https://gitlab.agetic.gob.bo/agetic/librecast.git $LIBRECAST || {
Carlos Remuzzi's avatar
Carlos Remuzzi committed
174
175
176
177
    printf "Error: el git clone del repo librecast ha fallado \n"
    exit 1
  }

Carlos Remuzzi's avatar
Carlos Remuzzi committed
178
  # esto tiene que adaptarse a diferentes distros
179

180
181
182
  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
183
184
185
186
187
188
189
190
191
192
  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
193

Carlos Remuzzi's avatar
Carlos Remuzzi committed
194
195
196
197
198
199
200
201
  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
202
203
204
    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
205
  else
Carlos Remuzzi's avatar
Carlos Remuzzi committed
206
207
208
    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"
209
    echo "https://gitlab.agetic.gob.bo/agetic/librecast/blob/master/INSTALL.md"
Carlos Remuzzi's avatar
Carlos Remuzzi committed
210
  fi
211

Carlos Remuzzi's avatar
Carlos Remuzzi committed
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
  printf "${GREEN}"
  echo '    ___ __              ______           __  '
  echo '   / (_) /_  ________  / ____/___ ______/ /_ '
  echo '  / / / __ \/ ___/ _ \/ /   / __ `/ ___/ __/ '
  echo ' / / / /_/ / /  /  __/ /___/ /_/ (__  ) /_   '
  echo '/_/_/_.___/_/   \___/\____/\__,_/____/\__/   '
  echo ''
  echo '                        ...ha sido instalado!'
  echo ''
  echo ''
  printf "${NORMAL}"
}

main