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

Last change on this file since 5552 was 5552, checked in by joamuran, 2 years ago

using getxpraConnections

  • Property svn:executable set to *
File size: 5.2 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..."
18    MSG_OK="Accepta"
19    MSG_CANCEL="Cancel·la"
20elif  [[ ${lang} == "es_ES" ]] || [[ ${lang} == "es" ]];
21then
22    MSG_INFO_IMPORT="Va a importar la imagen: "
23    MSG_EXTRACTING="Extrayendo imagen. Espere un momento. "
24    MSG_CANCELLED="El proceso se ha cancelado"
25    MSG_CREATE_SQUASHFS="Creando la imagen en el servidor..."
26    MSG_SUCCESS="La imagen de cliente ligero se ha exportado"
27    MSG_PASS_TITLE="Contraseña del administrador"
28    MSG_PASS="Inserte la contraseña de administrador"
29    MSG_EXISTS_CHROOT="¿Ya existe una imagen con este nombre. Desea sobreescribirla?"
30    MSG_REMOVING="Borrando la imagen previa..."
31    MSG_OK="Aceptar"
32    MSG_CANCEL="Cancelar"
33else
34    MSG_INFO_IMPORT="You are going to import image: "
35    MSG_EXTRACTING="Extracting image. Please wait... "
36    MSG_CANCELLED="Process has been cancelled"
37    MSG_CREATE_SQUASHFS="Creating image in server..."
38    MSG_SUCCESS="Thin client image has been exporported"
39    MSG_PASS_TITLE="Admin Password"
40    MSG_PASS="Insert admin password"
41    MSG_EXISTS_CHROOT="An image with this name alreasy exists. Overwrite it?"
42    MSG_REMOVING="Deleting previous image..."
43    MSG_OK="Ok"
44    MSG_CANCEL="Cancel"
45fi
46
47ZEN_ERROR="--ok-label=$MSG_OK"
48ZEN_QUESTION="--cancel-label=$MSG_CANCEL $ZEN_ERROR"
49
50if [ $# -ne 1 ];
51    then echo "USAGE: lmd-import-img.sh image.lmdimg" 
52    exit -1;
53fi
54
55# Confirm message
56zenity --question --text "${MSG_INFO_IMPORT} ${1}" $ZEN_QUESTION
57if [ $? -eq 1 ];
58then
59    exit 1
60fi
61
62# Admin Password
63PASS=`zenity --password --text "${MSG_PASS}" --title "${MSG_PASS_TITLE}" $ZEN_QUESTION`
64   
65# Remove previous images in tmp
66echo "[lmd Import] Removing prevous uncompressed images in tmp..."
67
68if [[ -d /tmp/extracted_image ]]
69then
70    rm -r /tmp/extracted_image
71fi
72mkdir /tmp/extracted_image
73
74#### Ubicar dins la llista d'opcions el que hem creat n4d
75
76echo "[lmd Import] Extracting file..."
77echo "[lmd Import] Extracting file... " > /tmp/importlog.txt
78tar -xvzf ${1} -C /tmp/extracted_image | zenity --progress --pulsate --auto-close --text "${MSG_EXTRACTING}" $ZEN_QUESTION
79
80if [ $? -ne 0 ] ; then
81zenity --error --text "${MSG_CANCELLED}" $ZEN_ERROR
82exit -1
83fi
84
85echo "[lmd Import] Extracted. No errors untaring. " >> /tmp/importlog.txt
86
87
88# Moving
89extracted_image=`ls /tmp/extracted_image/opt/ltsp/*/*.json | cut -d "/" -f 6`
90extracted_filename=`ls /tmp/extracted_image/opt/ltsp/*/*.json | cut -d "/" -f 7`
91new_imagename="${extracted_filename%.*}"
92
93echo "[lmd Import] Extracted image is  $extracted_image" >> /tmp/importlog.txt
94
95
96if [ -d /opt/ltsp/${new_imagename} ];
97then
98    zenity --question --text "${MSG_EXISTS_CHROOT}" $ZEN_QUESTION
99    if [ $? -eq  1 ]; then
100        echo "[lmd Import] Cancelled. Image exists." >> /tmp/importlog.txt
101        exit -1
102    else
103        echo "[lmd Import] Image already exists, but deleting that" >> /tmp/importlog.txt
104        rm -r /opt/ltsp/${new_imagename} | zenity --progress --auto-close --pulsate --text "${MSG_REMOVING}" $ZEN_QUESTION
105    fi
106fi
107
108
109echo "moving /tmp/extracted_image/opt/ltsp/${extracted_image} to /opt/ltsp/${new_imagename}"
110echo "moving /opt/ltsp/${new_imagename}/${extracted_filename} to /etc/ltsp/images/"
111
112echo "moving /tmp/extracted_image/opt/ltsp/${extracted_image} to /opt/ltsp/${new_imagename}"  >> /tmp/importlog.txt
113echo "moving /opt/ltsp/${new_imagename}/${extracted_filename} to /etc/ltsp/images/"  >> /tmp/importlog.txt
114
115
116mv /tmp/extracted_image/opt/ltsp/${extracted_image}  /opt/ltsp/${new_imagename}
117mv /opt/ltsp/${new_imagename}/${extracted_filename}  /etc/ltsp/images/
118
119# Update kernels and regenerate image
120echo "[lmd Import] Updating kernels into image" >> /tmp/importlog.txt
121ltsp-update-kernels ${new_imagename}
122
123echo "[lmd Import] Updating keys" >> /tmp/importlog.txt
124ltsp-update-sshkeys
125
126echo "[lmd Import] Update image" >> /tmp/importlog.txt
127ltsp-update-image ${new_imagename} | zenity --progress --pulsate --text "${MSG_CREATE_SQUASHFS}" $ZEN_QUESTION
128# WTF !!! lmd-server.install/usr/sbin/lmd-import-img.sh
129
130if [ $? -ne 0 ] ; then
131echo "[lmd Import] Some error has success... updating image..." >> /tmp/importlog.txt
132zenity --error --text "${MSG_CANCELLED}" $ZEN_ERROR
133exit -1
134fi
135
136# Setting image into bootMenu
137echo "[lmd Import] Pushing to boot list" >> /tmp/importlog.txt
138n4d-client -c LlxBootManager -m pushToBootList -u ${USER} -p ${PASS} -a ltp_label${new_imagename}
139 
140# Restarting NBD
141echo "[lmd Import] Restarting NBD" >> /tmp/importlog.txt
142invoke-rc.d nbd-server restart
143
144echo "[lmd Import] All worked fine" >> /tmp/importlog.txt
145zenity --info --text "${MSG_SUCCESS}" $ZEN_ERROR
146exit 0
Note: See TracBrowser for help on using the repository browser.