# !/bin/bash # Fix Cydia repository errors # v1.6.6 - 4th August 2010 (Contact author: @Secretss_ on Twitter) # # Thanks go to MadHouse and Helpmy360isEMO. #########################################################################################00# if [ "$(id -u)" != "0" ]; then echo -e "\nThis script must be run as root user.\n" exit fi if [ ! -e /usr/bin/wget ] || [ ! -e /usr/bin/plutil ] || [ ! -e /usr/bin/awk ] || [ ! -e /bin/grep ] || [ ! -e /usr/bin/gettext ]; then echo -n "Installing necessary tools... " if [ ! -e /usr/bin/apt-get ]; then echo -e "\nUnable to automatically install tools,\nplease install APT 0.7 Strict from Cydia.\n" exit fi if [ ! -e /usr/bin/plutil ]; then apt-get -qq install com.ericasadun.utilities > /dev/null 2>&1 if [ ! -e /usr/bin/plutil ]; then echo -e "\nUnable to install tools.\nAre you connected to the Internet?" exit fi fi if [ ! -e /usr/bin/awk ]; then apt-get -qq install gawk > /dev/null 2>&1 if [ ! -e /usr/bin/awk ]; then echo -e "\nUnable to install tools.\nAre you connected to the Internet?" exit fi fi if [ ! -e /bin/grep ]; then apt-get -qq install grep > /dev/null 2>&1 if [ ! -e /bin/grep ]; then echo -e "\nUnable to install tools.\nAre you connected to the Internet?" exit fi fi if [ ! -e /usr//bin/gettext ]; then apt-get -qq install gettext > /dev/null 2>&1 if [ ! -e /bin/grep ]; then echo -e "\nUnable to install tools.\nAre you connected to the Internet?" exit fi fi if [ ! -e /usr/bin/wget ]; then apt-get -qq install wget > /dev/null 2>&1 if [ ! -e /usr/bin/wget ]; then echo -e "\nUnable to install tools.\nAre you connected to the Internet?" exit fi fi echo -e "Done.\n" fi #########################################################################################0F# function help { echo -e "Usage: cyfix repourl\n\t-to remove repository" echo -e "Usage: cyfix -l\n\t-to list all installed repos" echo -e "Usage: cyfix -d\n\t-to remove selected repos" echo -e "Usage: cyfix -u\n\t-to update Cyfix" echo -e "Usage: cyfix -h\n\t-to display this text" echo -e "v1.6.6 Written by Secretss\nContact Secretss[C4iD] on Rizon IRC server\nor @Secretss_ on Twitter.\n" } function repocheck() { if [ "$#" = "1" ] && [ ! "$reponums" ]; then repo=$1 if [ "$repo" = "$(cat /tmp/repolist1.log | grep -m 1 "$repo" | awk '{print $2}')" ]; then if [ "$(cat /tmp/repolist1.log | grep "$repo" | awk '{print $1}')" -gt "$point" ]; then status=default default1=yes else default1=no fi else status=dne echo -e "\nRepository not found. Did you type it right?\n" exit fi else array=($reponums) k=0 for i in $(seq 0 $((${#array[*]}-1))); do number=$(echo "${array[$i]}" | grep -E [0-9]) if [ ! "$number" ]; then echo -e "\nPlease input integers only.\n" exit elif [ "${array[$i]}" -gt "$num" ]; then echo -e "\nInvalid selection.\n" exit elif [ "${array[$i]}" -gt "$point" ]; then default2=yes defaultrepo[$k]=${array[$i]} let k+=1 fi done if [ "$default2" != "yes" ]; then default2=no fi fi } function listrepo { rm -f /tmp/repolist.log rm -f /tmp/repolist1.log echo "deb http://apt.saurik.com/ tangelo-3.7 main" > /etc/apt/sources.list.d/saurik.list for item in $(ls /etc/apt/sources.list.d/); do echo $(cat /etc/apt/sources.list.d/$item | grep "http://" | awk '{print $2}') >> /tmp/repolist.log done if [ $(grep -c deb /etc/apt/sources.list.d/cydia.list) -gt 1 ]; then line=$(cat /tmp/repolist.log | grep " ") cat /tmp/repolist.log | grep -v "$line" > /tmp/repolist.log echo "$line" > /tmp/repolist1.log cat /tmp/repolist1.log | sed -e "s: :\nUSER :g" > /tmp/repolist1.log echo -e "USER $(cat /tmp/repolist1.log)" >> /tmp/repolist.log rm -f /tmp/repolist1.log elif [ "$(grep -c deb /etc/apt/sources.list.d/cydia.list)" = "1" ]; then userrepo=$(cat /etc/apt/sources.list.d/cydia.list | grep "http://" | awk '{print $2}') cat /tmp/repolist.log | grep -v $userrepo > /tmp/repolist.log echo -e "USER $userrepo\n$(cat /tmp/repolist.log)" > /tmp/repolist.log fi cat /tmp/repolist.log | sed -e "s:http\://::g" > /tmp/repolist.log point=$(grep -c USER /tmp/repolist.log) for i in $(seq 1 $point); do echo -e "$i $(echo -n $(cat /tmp/repolist.log | grep -m 1 "USER" | awk '{print $2}') | head -c -1)" cat /tmp/repolist.log | sed '-e/USER .*/{;s/USER .*//;:a' '-en;ba' '-e}' > /tmp/repolist.log done > /tmp/repolist1.log let num=$point+1 while read line; do if [ ${#line} -gt 2 ]; then echo -e "$num $(echo -n $line | head -c -1)" let num+=1 fi done > /tmp/repolist1.log if [ "$(cat /tmp/repolist1.log)" = "1 " ]; then echo -e "No repositories found." notfound=true else echo -e "$(cat /tmp/repolist1.log)" fi let num-=1 echo } function processrepourl() { repo=$1 if [ $(echo -n $repo | tail -c -1) == "/" ]; then repo=$(echo -n $repo | head -c -1) fi if [ "${repo:0:7}" = "http://" ]; then repo=$(echo $repo | sed -e 's:http\://::g') fi expand=$(echo $repo | sed 's/\(.\)/\1 /g') array1=($expand) expand='' j=0 for i in $(seq 0 $((${#array1[*]} - 1))); do b[$j]=${array1[$i]} c[$i]=${array1[$i]} if [ ${array1[$i]} == "/" ]; then b[$j]="\\" c[$i]="_" let j+=1 b[$j]="/" fi let j+=1 array1[$i]='' done reponame=$(echo ${b[*]} | tr -d ' ') filename=$(echo ${c[*]} | tr -d ' ') file1=$(echo $filename _._Packages | tr -d ' ') file2=$(echo $filename _._Release | tr -d ' ') file3=$(echo $filename _._Packages.IndexDiff | tr -d ' ') file4=$(echo $filename _._Release.gpg | tr -d ' ') file5=$(echo $filename _._en | tr -d ' ') file6=$(grep -l $repo /etc/apt/sources.list.d/*.list) for i in $(seq 0 $((${#b[*]} - 1))); do b[$i]='' done for i in $(seq 0 $((${#c[*]} - 1))); do c[$i]='' done repocheck "$repo" } function removerepo() { repo=$1 processrepourl $repo cd /var/lib/apt/lists ls > cyfix.log files=$(grep $filename cyfix.log) for word in $files; do rm -f $word done rm -f cyfix.log cd /var/lib/apt/lists/partial ls > cyfix.log files=$(grep $filename cyfix.log) for word in $files; do rm -f $word done rm -f cyfix.log cd /etc/apt/sources.list.d cat cydia.list | grep -v $repo > cydia1.list mv -f cydia.list /var/mobile/cydia.list.backup mv -f cydia1.list cydia.list if [ "$default1" = "no" ]; then cd /var/lib/cydia plutil -convert xml1 metadata.plist > /dev/null 2>&1 start="deb:http:\/\/$reponame\/:.\/<\/key>" stop="<\/dict>" echo -e "$(cat metadata.plist | sed -e "/$start/,/$stop/ s/.*//")" > metadata1.plist mv -f metadata1.plist metadata.plist elif [ "$default1" = "yes" ]; then cd /etc/apt/sources.list.d if [ -f $file6 ] && [ "$file6" != "/etc/apt/sources.list.d/cydia.list" ]; then rm -f "$file6" fi fi echo -e "Removed $repo." } function removerepos { reponums='' echo "Executing repository removal... " for reponum in ${array[*]}; do repo=$(cat /tmp/repolist1.log | grep -m 1 "$reponum " | awk '{print $2}') removerepo $repo done } #########################################################################################01# if [ $# -lt 1 ] || [ "$1" = "-h" ]; then help exit elif [ $# -gt 1 ]; then echo -e "Only one repository at a time please." exit fi if [ "$1" = "-u" ]; then cd /usr/bin before=$(md5sum cyfix) echo -e "\nChecking for updates." wget -N -q http://dl.dropbox.com/u/1838452/cyfix chmod 755 cyfix if [ "$before" != "$(md5sum cyfix)" ]; then echo -e "Cyfix has been successfully updated.\n" else echo -e "No updates available.\n" fi exit fi if [ "$1" = "-l" ]; then listrepo exit fi if [ "$1" = "-d" ]; then listrepo if [ "$notfound" = "true" ]; then exit fi echo -e "Please enter the numbers corresponding to\nthe repositories you want to remove.\nSeparate your numbers by a space:" read reponums if [ ! "$reponums" ]; then echo No input detected. exit fi echo -e "\nWARNING:\nPlease make sure Cydia is not running.\n" echo -n "Processing repositories... " repocheck $reponums if [ "$default2" = "yes" ]; then echo -e "\nDefault repository/ies detected:\n${defaultrepo[*]}\nProceed with removal? (Y/N):" read prompt2 if [ "$(echo $prompt2 | tr A-Z a-z)" = "$(echo Y | tr A-Z a-z)" ]; then removerepos else echo -e "Have a nice day, then.\n" exit fi else echo Done. removerepos fi echo -e "Done.\n\nListing remaining repositories:" listrepo exit fi if [ "$#" = "1" ]; then repo=$1 listrepo > /dev/null 2>&1 echo -e "\nWARNING:\nPlease make sure Cydia is not running.\n" echo -n "Processing repository... " processrepourl "$repo" if [ "$default1" = "yes" ]; then echo -e "\nThis is a default Cydia repository,\nare you sure you want to remove it? (Y/N):" read prompt1 if [ "$(echo $prompt1 | tr A-Z a-z)" = "$(echo Y | tr A-Z a-z)" ]; then echo -n "Executing repository removal... " removerepo "$repo" else echo -e "Have a nice day, then.\n" exit fi else echo Done. echo -n "Executing repository removal... " removerepo "$repo" fi echo -e "Done.\n" fi exit