source: lmd/trunk/fuentes/lmd-server.install/usr/sbin/lmd-import-img.sh @ 3526

Last change on this file since 3526 was 3526, checked in by joamuran, 4 years ago

fixed lmd-import-img

  • Property svn:executable set to *
File size: 3.8 KB
Line 
1#!/bin/bash
2
3##
4
5lang=$(locale | grep LANGUAGE | cut -d= -f2 | cut -d_ -f1)
6
7if [[ ${lang} == "ca_ES" ]] || [[ ${lang} == "ca_ES@valencia" ]] || [[ ${lang} == "ca" ]] || [[ ${lang} == "ca@valencia" ]];
8then
9    MSG_INFO_IMPORT="Aneu a importar la imatge: "
10    MSG_EXTRACTING="Extraient la imatge. Espereu un moment... "
11    MSG_CANCELLED="El procés ha estat cancel·lat"
12    MSG_CREATE_SQUASHFS="S'està creant la imatge al servidor."
13    MSG_SUCCESS="La imatge de client lleuger s'ha exportat"
14    MSG_PASS_TITLE="Contrassenya d'administrador"
15    MSG_PASS="Inseriu la contrassenya d'administrador"
16    MSG_EXISTS_CHROOT="Ja existeix una imatge amb este nom. Voleu sobreescriure-la?"
17    MSG_REMOVING="Esborrant la imatge prèvia..."
18elif  [[ ${lang} == "es_ES" ]] || [[ ${lang} == "es" ]];
19then
20    MSG_INFO_IMPORT="Va a importar la imagen: "
21    MSG_EXTRACTING="Extrayendo imagen. Espere un momento. "
22    MSG_CANCELLED="El proceso se ha cancelado"
23    MSG_CREATE_SQUASHFS="Creando la imagen en el servidor..."
24    MSG_SUCCESS="La imagen de cliente ligero se ha exportado"
25    MSG_PASS_TITLE="Contraseña del administrador"
26    MSG_PASS="Inserte la contraseña de administrador"
27    MSG_EXISTS_CHROOT="¿Ya existe una imagen con este nombre. Desea sobreescribirla?"
28    MSG_REMOVING="Borrando la imagen previa..."
29else
30    MSG_INFO_IMPORT="You are going to import image: "
31    MSG_EXTRACTING="Extracting image. Please wait... "
32    MSG_CANCELLED="Process has been cancelled"
33    MSG_CREATE_SQUASHFS="Creating image in server..."
34    MSG_SUCCESS="Thin client image has been exporported"
35    MSG_PASS_TITLE="Admin Password"
36    MSG_PASS="Insert admin password"
37    MSG_EXISTS_CHROOT="An image with this name alreasy exists. Overwrite it?"
38    MSG_REMOVING="Deleting previous image..."
39fi
40
41
42if [ $# -ne 1 ]; 
43    then echo "USAGE: lmd-import-img.sh image.lmdimg" 
44    exit -1;
45fi
46
47# Confirm message
48zenity --question --text "${MSG_INFO_IMPORT} ${1}"
49if [ $? -eq 1 ];
50then
51    exit 1
52fi
53
54# Admin Password
55PASS=`zenity --password --text "${MSG_PASS}" --title "${MSG_PASS_TITLE}"`
56   
57# Remove previous images in tmp
58echo "[lmd Import] Removing prevous uncompressed images in tmp..."
59
60if [[ -d /tmp/extracted_image ]]
61then
62    rm -r /tmp/extracted_image
63fi
64mkdir /tmp/extracted_image
65
66#### Ubicar dins la llista d'opcions el que hem creat n4d
67
68echo "[lmd Import] Extracting file..."
69tar -xvzf ${1} -C /tmp/extracted_image | zenity --progress --pulsate --auto-close --text "${MSG_EXTRACTING}" 
70
71if [ $? -ne 0 ] ; then
72zenity --error --text "${MSG_CANCELLED}"
73exit -1
74fi
75
76# Moving
77extracted_image=`ls /tmp/extracted_image/opt/ltsp/*/*.json | cut -d "/" -f 6`
78extracted_filename=`ls /tmp/extracted_image/opt/ltsp/*/*.json | cut -d "/" -f 7`
79new_imagename="${extracted_filename%.*}"
80
81
82if [ -d /opt/ltsp/${new_imagename} ];
83then
84    zenity --question --text "${MSG_EXISTS_CHROOT}"
85    if [ $? -eq  1 ]; then
86        exit -1
87    else
88        rm -r /opt/ltsp/${new_imagename} | zenity --progress --auto-close --pulsate --text "${MSG_REMOVING}"
89    fi
90fi
91
92
93echo "moving /tmp/extracted_image/opt/ltsp/${extracted_image} to /opt/ltsp/${new_imagename}"
94echo "moving /opt/ltsp/${new_imagename}/${extracted_filename} to /etc/ltsp/images/"
95
96mv /tmp/extracted_image/opt/ltsp/${extracted_image}  /opt/ltsp/${new_imagename}
97mv /opt/ltsp/${new_imagename}/${extracted_filename}  /etc/ltsp/images/
98
99# Update kernels and regenerate image
100ltsp-update-kernels ${new_imagename}
101ltsp-update-sshkeys
102ltsp-update-image ${new_imagename} | zenity --progress --pulsate --text "${MSG_CREATE_SQUASHFS}"
103lmd-server.install/usr/sbin/lmd-import-img.sh
104
105if [ $? -ne 0 ] ; then
106zenity --error --text "${MSG_CANCELLED}"
107exit -1
108fi
109
110# Setting image into bootMenu
111n4d-client -c LlxBootManager -m pushToBootList -u ${USER} -p ${PASS} -a ltp_label${new_imagename}
112 
113# Restarting NBD
114invoke-rc.d nbd-server restart
115
116zenity --info --text "${MSG_SUCCESS}"
117exit 0
Note: See TracBrowser for help on using the repository browser.