linkdata2sd  Check-in [c972a7703c]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:refactoriza y agrega modo recover. Detecta enlace roto
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:c972a7703c42119cc6577781a85dbe0f86ff85cb
User & Date: brau 2016-03-21 00:15:44
Context
2016-03-21
00:20
agrega opcion forget check-in: 928fd577fa user: brau tags: trunk
00:15
refactoriza y agrega modo recover. Detecta enlace roto check-in: c972a7703c user: brau tags: trunk
2016-03-20
12:04
prompt mas claro check-in: 3bb925e740 user: brau tags: trunk
Changes

Changes to linksd.sh.

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
...
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175
...
210
211
212
213
214
215
216
217

218
219
220
221
222
223
224
225
226
227



228
229
230

231
232
233
234


235
236















237
238
239


240
241


242
243



244
245
246
247
248
249
250
251






252
253
254
255
256
257
258
259




260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280




281

282
283




284
285











286










287
288
289
290



291
292
293










	fi
}



# dir 
ui_phone_to_sd() {
	cd $DATADIR
	usage=`du -sh "$1" | cut -f1`
	echo -n "$1 [$usage, phone] (link/delete/sh/snap): "
	read r
	case "$r" in
		link)
			vers=`now`
			mkdir "$SDDIR" 2>/dev/null
................................................................................
	fi


}

# dir
ui_sd_to_phone() {

	#directorio contenedor de versiones
	vers_dir="$SDDIR/$1"
	# Notar que dest_dir podria estar apuntando a otro directorio
	# que no este manejado por este script (por ej. la version licenciada
	# de link2sd podria estar manejando este directorio)
	# 
	dest_dir=`readlink "$DATADIR/$1"`
................................................................................
		vers=$(basename `dirname $dest_dir`)
	else
		vers=""
	fi

	cd `dirname $dest_dir`
	dir=`basename $dest_dir`

	usage=`du -sh "$dest_dir" | cut -f1`

	(cd $vers_dir && ls_vs $vers)
	echo -n "$1 [$usage, sd] (unlink/delete/sh/VERSION/snap/ren): "
	read r                                                        
	case "$r" in                                                  
		unlink)                                                 
			rm "$DATADIR/$1" ||
................................................................................
		"")
			true
			;;
		*)                                                    
			if [ -d "$vers_dir/$r" ]; then
				rm "$DATADIR/$1" ||
					error error al intentar eliminar enlace actual
				ln -s "$vers_dir/$r/$1" "$DATADIR/$1"

			else
                          msg respuesta invalida
                        fi
                        ui_sd_to_phone "$@"
	esac                                  
}







search() {
	cd $DATADIR
	

	for dir in *$1*; do
		if [ "$dir" = '*'"$1"'*' ]; then
			error no hay calces
		fi


	
		if [ `islinked "$dir"` ]; then















			ui_sd_to_phone "$dir"
		else
			ui_phone_to_sd "$dir"


		fi
	done


}




case "$1" in 
"-h")
	echo "$0 -u"
	echo '   Actualiza script'
	echo "$0 -c"
	echo '   Realiza escaneo de mantencion/verificacion'
	echo "$0 [--] [PATRON]"
	echo '   Detectar instalaciones que corresponden al patron'






	exit;;
"--")
	shift;;
"-c")
	rmdir $SDDIR/*/* 2>/dev/null
	rmdir $SDDIR/* 2>/dev/null
	rmdir $SDDIR 2>/dev/null
	exit;;




"-u")
	ssh suse@192.168.43.5 "cat /mnt/six/nocow6/linksd-wc/linksd.sh" > $PREUPDATE.dat ||
		error no se pudo descargar actualizacion
	loc=`dirname $0`
	mv $0 $loc/$PREUPDATE.old ||
		error no se pudo respaldar original
	mv $PREUPDATE.dat $0 ||
		error no se pudo reemplazar script actual
	msg "se actualizo `realpath $0` correctamente"
	exit
	;;
esac


verify_setup
df `dirname $DATADIR` `dirname $SDDIR`
#/data                  189M   155M    34M   4096
#/data/sdext2           457M   441M    16M   1024
echo

if [ "$1" ]; then




	search "$1"

else
	# de mayor a menor




	#du -s * | sort -rn | cut -f2 | xargs du -sh | less
	











	cd $DATADIR










	dirs1=`du -s * | sort -rn | cut -f2`
	
	for d in $dirs1; do
		search "`basename $d`"



	done

fi

















|







 







|







 







>
|







 







|
>







<
<
<
>
>
>
|
|
<
>
|
|
|
|
>
>
|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
<
>
>
|
<
>
>
|
|
>
>
>






|
|
>
>
>
>
>
>








>
>
>
>














|
|
<
<
<
<
|
>
>
>
>
|
>
|
<
>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
|
|
|
<
>
>
>
|
<
|
>
>
>
>
>
>
>
>
>
>
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
...
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
...
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226



227
228
229
230
231

232
233
234
235
236
237
238
239

240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256

257
258
259

260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308




309
310
311
312
313
314
315
316

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347

348
349
350
351

352
353
354
355
356
357
358
359
360
361
362
	fi
}



# dir 
ui_phone_to_sd() {
	cd "$DATADIR"
	usage=`du -sh "$1" | cut -f1`
	echo -n "$1 [$usage, phone] (link/delete/sh/snap): "
	read r
	case "$r" in
		link)
			vers=`now`
			mkdir "$SDDIR" 2>/dev/null
................................................................................
	fi


}

# dir
ui_sd_to_phone() {
	cd "$SDDIR"
	#directorio contenedor de versiones
	vers_dir="$SDDIR/$1"
	# Notar que dest_dir podria estar apuntando a otro directorio
	# que no este manejado por este script (por ej. la version licenciada
	# de link2sd podria estar manejando este directorio)
	# 
	dest_dir=`readlink "$DATADIR/$1"`
................................................................................
		vers=$(basename `dirname $dest_dir`)
	else
		vers=""
	fi

	cd `dirname $dest_dir`
	dir=`basename $dest_dir`
	# determina usage y detecta enlaces rotos
	usage=`(du -sh "$dest_dir" || echo broken) | cut -f1`

	(cd $vers_dir && ls_vs $vers)
	echo -n "$1 [$usage, sd] (unlink/delete/sh/VERSION/snap/ren): "
	read r                                                        
	case "$r" in                                                  
		unlink)                                                 
			rm "$DATADIR/$1" ||
................................................................................
		"")
			true
			;;
		*)                                                    
			if [ -d "$vers_dir/$r" ]; then
				rm "$DATADIR/$1" ||
					error error al intentar eliminar enlace actual
				ln -s "$vers_dir/$r/$1" "$DATADIR/$1" ||
					error error al intentar recrear enlace
			else
                          msg respuesta invalida
                        fi
                        ui_sd_to_phone "$@"
	esac                                  
}




ui_recover_from_sd() {
	#directorio contenedor de versiones
	cd "$SDDIR"
	vers_dir="$SDDIR/$1"
	(cd $vers_dir && ls_vs $vers)

	echo -n "$1 [recoverable] (delete/sh/VERSION): "
	read r
	case "$r" in
		sh)
			(cd "$dir" && sh)
			ui_recover_from_sd "$@"
			;;


		delete)
			deltree "$dir" ||
				error error al intentar eliminar todos los snapshots
			msg "todos los snapshots de $1 se han eliminado"
			;;
		"")
			true
			;;
		*)
			if [ -d "$vers_dir/$r" ]; then
				# por si acaso, eliminamos el link... quizas estamos
				# recuperandonos de un enlace roto
				rm "$DATADIR/$1" 2>/dev/null
				ln -s "$vers_dir/$r/$1" "$DATADIR/$1" ||
					error error al intentar recrear enlace
				ui_sd_to_phone "$@"
			else

                          msg respuesta invalida
			  ui_recover_from_sd "$@"
			fi

			;;
	esac

}


main=main_search
case "$1" in 
"-h")
	echo "$0 -u"
	echo '   Actualiza script'
	echo "$0 -c"
	echo '   Realiza escaneo de mantencion/verificacion'
	echo "$0 [[--] PATRON]"
	echo '   Detectar instalaciones que corresponden al patron (o todas)'
	echo "$0 -r [PATRON]"
	echo '   Detectar snapshots de apps sin directorio data que'
	echo '   corresponden al patron (o todas).'
	echo '   Esto puede significar que la app ha sido recien instalada,'
	echo '   ha sido desinstalada o bien fue eliminado previamente con'
	echo '   una operacion "delete"'
	exit;;
"--")
	shift;;
"-c")
	rmdir $SDDIR/*/* 2>/dev/null
	rmdir $SDDIR/* 2>/dev/null
	rmdir $SDDIR 2>/dev/null
	exit;;
"-r")
	main=main_recover
	shift
	;;
"-u")
	ssh suse@192.168.43.5 "cat /mnt/six/nocow6/linksd-wc/linksd.sh" > $PREUPDATE.dat ||
		error no se pudo descargar actualizacion
	loc=`dirname $0`
	mv $0 $loc/$PREUPDATE.old ||
		error no se pudo respaldar original
	mv $PREUPDATE.dat $0 ||
		error no se pudo reemplazar script actual
	msg "se actualizo `realpath $0` correctamente"
	exit
	;;
esac


main_search () {
  cd $DATADIR




  if [ "$1" ]; then
	for dir in *$1*; do
		if [ "$dir" = '*'"$1"'*' ]; then
			error no hay calces
		fi
		if [ `islinked "$dir"` ]; then
			ui_sd_to_phone "$dir"
		else

			ui_phone_to_sd "$dir"
		fi
	done
  else
          dirs1=`du -s * | sort -rn | cut -f2`
          
          for dir in $dirs1; do
		if [ `islinked "$dir"` ]; then
			ui_sd_to_phone "$dir"
		else
			ui_phone_to_sd "$dir"
		fi
          done
  fi
}

main_recover() {
  cd $SDDIR
  if [ "$1" ]; then
	for dir in *$1*; do
		if [ "$dir" = '*'"$1"'*' ]; then
			error no hay calces
		fi
		if [ \! -e "$DATADIR/$dir" ]; then
			ui_recover_from_sd "$dir"
		fi
	done
  else
          dirs1=`du -s * | sort -rn | cut -f2`

          for dir in $dirs1; do

          	if [ \! -e "$DATADIR/$dir" ]; then
			ui_recover_from_sd "$dir"
          	fi
          done

  fi
}


verify_setup
df `dirname $DATADIR` `dirname $SDDIR`
#/data                  189M   155M    34M   4096
#/data/sdext2           457M   441M    16M   1024
echo
$main