iPhone and Linux

Thursday, December 3, 2009

Script for deleting iPhone language packs

This script is outdated, please see the script here. Also, don't use the version of this script found on sinful iphone forums by Monsieurtalbot. He made a few ugly edits to the echo commands and claimed to have written the script. When called out, he then claimed to have rewritten it and fixed a bug that made Terminal crash, but a simple look at the code shows no rewrite. It's the same (outdated) script except uglier due to poorly formatted echos.

#! /bin/sh
# Feb 9 2010
echo
# test for root
if [ `id -u` != 0 ]; then echo "Oops, you need to be root to run this script"; exit 0; fi

echo "Let's delete a few thousand language packs.
You will have several chances to back out
before anything is deleted but if you want
to stop at any time hit ctrl c. On the
iPhone keyboard, control is a black dot
that is found on the far right when you
tap 123 then # =."
echo
echo "If you want to see how it runs without
making any changes, just answer no when it
asks you which languages to delete."
echo
echo "Press enter to begin."
read

echo "Please contact me at ijdmas at gmail dotcom
if this script asks you to delete a language
but doesn't list that language. It will
look like this:
\"Do you want to delete:? y or n?\""
echo
echo "This is due to someone using the long name
for a language which Ive not seen yet.
Example, if Vulcan used to be vu.lproj
and someone starts using Vulcan.lproj,
it will cause that problem. If it
happens, it is safe to answer no and
continue."
echo
echo "Press enter to begin."
read

# create temp files
touch .langlist_fubaya .keeplist_fubaya .deletelist_fubaya .alllist_fubaya

# update database, locate all lproj, and grep directories minus English
echo "Searching for language packs. Please wait..."
updatedb && locate lproj | grep -E lproj$ | grep -v -i English | grep -v -i \/en > .alllist_fubaya

# get a list of all languages
cat .alllist_fubaya | while read file; do basename "$file"; done | grep -E lproj$ | sort | uniq > .langlist_fubaya
echo ---------------- >> langpack.log
echo langlist >> langpack.log
cat .langlist_fubaya >> langpack.log

# display true names beside the language codes
# ask user if they want to keep them or not, put keepers in ".keeplist_fubaya" file
echo ---------------- >> langpack.log
for i in $(cat .langlist_fubaya) ; do
q=$(cat $0 | grep -i "\# $i" | tr -d \#)
[ -n "$q" ] && echo "Delete:$q? y or n?" || echo "Delete: $i (unrecognized)? y or n?"
read choice

# make sure "y" or "n" was entered, else keep repeating the question
while [[ $choice != 'y' ]] && [[ $choice != 'n' ]]
do
[ -n "$q" ] && echo "Delete:$q?" y or n? || echo "Delete: $i (unrecognized)?" y or n?
read choice
done

echo "delete:$i: $choice" >> langpack.log
[ $choice = "n" ] && echo $i >> .keeplist_fubaya
echo
done
echo ---------------- >> langpack.log
echo keeplist >> langpack.log
cat .keeplist_fubaya >> langpack.log

# put master list into delete list, filtering out keepers
cat .alllist_fubaya | grep -v -f ./.keeplist_fubaya > .deletelist_fubaya
# show final list of lang packs and confirm the user wants to delete them
echo
echo "Please wait while I compile a list of languages to delete. You will be asked for confirmation before anything is deleted"
echo ---------------- >> langpack.log
echo deletelist >> langpack.log
cat .deletelist_fubaya >> langpack.log
echo
echo -------------------------------------
cat .deletelist_fubaya | while read file; do basename "$file"; done | grep -E lproj$ | sort | uniq | tr '\n' ' '
echo
echo -------------------------------------
echo "This is your last chance. Are you sure you want to delete the language packs listed? Type y or n"

read choice
if [ $choice = "y" ]
then
# do the deed
echo ---------------- >> langpack.log
echo "final confirmation: $choice" >> langpack.log
echo ---------------- >> langpack.log
echo "Please wait while I delete the chosen language packs..." && while read file; do rm -rf "$file"; done < .deletelist_fubaya

# how many did we delete?
num=$(cat .deletelist_fubaya | wc -l)
# clean up temp files
rm .langlist_fubaya .keeplist_fubaya .deletelist_fubaya .alllist_fubaya

echo
echo "$num language pack directories have been
deleted. A log file has been created at
`pwd`/langpack.log. Please hang on to
that until you are sure there are no
problems. My contact information is at
the top of the log file. The only other
thing left is me, this script located at
`pwd`/`basename $0`. Do you want me to
delete myself? y or n?"

read choice
[ $choice = "y" ] && echo "Deleting myself..." && sleep 1.5 && echo "blarg.. I'm dead" && exec rm $0
echo "Phwew, Thank you! I'm too young to die. I'll be here at `pwd`/`basename $0` if you need me."

else # if user selected "n" to deleting the language packs
rm .langlist_fubaya .keeplist_fubaya .deletelist_fubaya .alllist_fubaya
echo "Ok, I won't delete anything. If you made a mistake, just run me again."
fi

# Arabic.lproj
# Chinese.lproj
# Croatian.lproj
# Czech.lproj
# Danish.lproj
# Dutch.lproj
# Finnish.lproj
# French.lproj
# German.lproj
# Greek.lproj
# Hebrew.lproj
# Indonesian.lproj
# Italian.lproj
# Japanese.lproj
# Korean.lproj
# Malay.lproj
# Norwegian.lproj
# Polish.lproj
# Portuguese.lproj
# Romanian.lproj
# Russian.lproj
# Slovak.lproj
# Spanish.lproj
# Swedish.lproj
# Thai.lproj
# Turkish.lproj
# Ukrainian.lproj
# ar.lproj (Arabic)
# cs.lproj (Czech)
# cs_CZ.lproj (Czech)
# da.lproj (Danish)
# da_DK.lproj (Danish)
# de.lproj (German)
# de_DE.lproj (German)
# el.lproj (Greek)
# el_GR.lproj (Greek)
# es.lproj (Spanish)
# es_419.lproj (Spanish)
# es_ES.lproj (Spanish)
# fi.lproj (Finnish)
# fi_FI.lproj (Finnish)
# fr.lproj (French)
# fr_CA.lproj (French)
# fr_FR.lproj (French)
# he.lproj (Hebrew)
# hr.lproj (Croatian)
# hr_HR.lproj (Croatian)
# hu.lproj (Hungary)
# id.lproj (Indonesian)
# it.lproj (Italian)
# it_IT.lproj (Italian)
# ja.lproj (Japanese)
# ko.lproj (Korean)
# ms.lproj (Malay)
# nl.lproj (Dutch)
# nl_NL.lproj (Dutch)
# no.lproj (Norwegian)
# no_NO.lproj (Norwegian)
# pl.lproj (Polish)
# pl_PL.lproj (Polish)
# pt.lproj (Portuguese)
# pt_PT.lproj (Portuguese)
# ro.lproj (Romanian)
# ro_RO.lproj (Romanian)
# ru.lproj (Russian)
# ru_RU.lproj (Russian)
# rus.lproj (Russian)
# sk.lproj (Slovak)
# sk_SK.lproj (Slovak)
# sp.lproj (Spanish)
# sp_es.lproj (Spanish)
# sv.lproj (Swedish)
# sv_SE.lproj (Swedish)
# th.lproj (Thai)
# tr.lproj (Turkish)
# tr_TR.lproj (Turkish)
# uk.lproj (Ukranian)
# zh-Hans.lproj (Chinese)
# zh-Hant.lproj (Chinese)
# zh_CN.lproj (Chinese)
# zh_HK.lproj (Chinese)
# zh_TW.lproj (Chinese)
# end of script

Blog Archive