-
Notifications
You must be signed in to change notification settings - Fork 1
/
instalar.sh
executable file
·97 lines (72 loc) · 2.44 KB
/
instalar.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
#!/bin/bash
if [ $# -ne 1 ] || [ "$1" == "." ]; then
echo "* Error. Faltan parámetros."
echo
echo "* Indicar el directorio donde se encuentran los archivos de vídeos ha reproducir."
echo
echo "* Ejemplo: ./instalar.sh ~/Vídeos/mis_videos"
exit
fi
if [ ! -e "$1" ] || [ ! -d "$1" ]; then
echo "* Directorio de vídeos no válido."
exit
fi
# Lugar en donde se encuentran los vídeos.
videos="$1"
# Archivo de configuración de xscreensaver
config=$HOME/.xscreensaver
# Ubicación de destino del script
destino=$HOME/.local/bin
# Nombre del script de destino
script=xscr_video.sh
usr_bin="/usr/bin"
usr_local_bin="/usr/local/bin"
# Verificar si existe el programa MPV
if [ ! -e $usr_bin/mpv ] && [ ! -e $usr_local_bin/mpv ]; then
echo "* No se encontró instalado el programa MPV."
exit
fi
# Verificar si existe el programa ed
if [ ! -e $usr_bin/ed ] && [ ! -e $usr_local_bin/ed ]; then
echo "* No se encontró instalado el programa ed."
echo "* Necesario sólo para el script 'instalar.sh'"
exit
fi
# Verificar si existe el programa xscreensaver-demo
if [ ! -e $usr_bin/xscreensaver-demo ] && [ ! -e $usr_local_bin/xscreensaver-demo ]; then
echo "* No se encontró instalado el programa xscreensaver-demo."
exit
fi
# Verificar si existe el archivo .xscreensaver
if [ ! -e "$config" ]; then
echo "* El archivo $config no existe. Ejecute xscreensaver-demo primero."
exit
fi
# Verificar que no exista ya el script...
if [ -e "$destino/$script" ]; then
echo "* El archivo $destino/$script ya existe. ¿Sobrescribirlo? S/n"
read -n 1 continuar
echo
if [ "$continuar" != "S" ]; then
echo; echo "* No se completo la instalación."
exit
fi
fi
# Crear el directorio por si no existe.
mkdir -p $destino
# .. se continua, copiar el script al directorio bin.
cp $script $destino/$script
echo "* El scipt '$script' se ha instalado en: '$destino/$script'"
chmod +x $destino/$script
# Actualizar .xscreensaver
# Busca la última linea de 'programs':
linea=$(grep -n '\\n\\' $config | cut -d: -f1 | tail -n 1)
# Escribir en la siguiente.
linea=$(($linea + 1))
programa="\"XSCR_VIDEO\" $destino/$script $videos \$XSCREENSAVER_WINDOW \\n\\"
# Agregamos el ítem en dónde corresponde.
printf '%s\n' H ${linea}i "$programa" . wq | ed -s $config
echo; echo "* La instalación se completó con éxito."
echo; echo "* A continuación inicie 'xscreensaver-demo' y luego"
echo " seleccione XSCR_VIDEO en la lista de 'Modos de visualización'".
exit 0