#!/bin/bash
#=======================================================#
#
# rep0
# v8.0b
#
# created by c0re
# licensed under CC (CreativeCommons)
# http://creativecommons.org/licenses/by-nc-sa/3.0/
#
#=======================================================#
if [ $(id -u) -ne 0 ]; then #check4root
echo -e "na[FATAL ERROR!] you MUST run me as root!"
read -sp "..sorry.."
echo -e "n"
exit 1
fi
echo -e "--created by c0re ($(echo 'c0re@psypanda.org' | tr q m))--"
#set them as variables
DIR1=/home/c0re/cydia/apps ; export DIR1
DIR2=/home/c0re/cydia/upload ; export DIR2
DIR3=/home/c0re/cydia/upload/debs ; export DIR3
DIR6=main/binary-iphoneos-arm
#check for needed dirs
if [ ! -d ~/cydia ]; then
mkdir -p $DIR1 $DIR3
echo "ALL FOLDERS NOT EXITSTED >> created" >> $HOME/rep0.log
else
if [ ! -d $DIR1 ]; then
mkdir $DIR1
echo "no $DIR1 folder existed >> created" >> $HOME/rep0.log; fi
if [ ! -d $DIR2 ]; then
mkdir -p $DIR2
echo "no $DIR2 folder existed >> created" >> $HOME/rep0.log; fi
if [ ! -d $DIR3 ]; then
mkdir $DIR3
echo "no $DIR3 folder existed >> created" >> $HOME/rep0.log; fi
fi
while [ answer != "e" ]; do #menu
clear
echo -e "[Hello $USER] what can I do for you?n"
echo " 1 clear all old .deb's
2 build all .debs in one klick
3 build the Package-List
4 sign the Release file with GPGkey
5 upload everything to an FTP Server"
echo -e "n[OTHER OPTIONS]n"
echo " gpg create a gpg key
e exit"
echo -e "n--------------------------------------------------------------n"
read -p " Sir ? " answer
case "$answer" in
1|rem|rm|RM|REM)
echo -e "n..removing all old files now!n"
find $DIR2 ( -name "*.bz2" -o -name "Packages" ) -print0 | xargs -0 rm -Rf
find $DIR2 -name "Release.gpg" -print0 | xargs -0 rm -Rf
for file in $DIR3/*.deb; do
if [ ! "$file" = "$DIR3/*.deb" ]; then
rm -Rf $file #remove old .debs
else
echo -e "na[WARNING!] no .deb's in $DIR3"
echo -e "..so nothing removed!n"
fi
done
read -sp "[DONE!] ..deleted all old files I could find!"
;;
2|deb|DEB)
find $DIR1 ( -name "postinst" -o -name "postrm" ) -exec chmod 0755 {} +
find $DIR1 ( -name "preinst" -o -name "prerm" ) -exec chmod 0755 {} +
find $DIR1 ( -name "extrainst_" -o -name "control" ) -exec chmod 0755 {} +
find $DIR1 -type d -name "DEBIAN" -exec chmod 0755 {} +
find $DIR1 -type f -name "*~" -print0 | xargs -0 rm -Rf #dont pack 'files~'
echo -e "n..building all packages now!n"
for file in $DIR1/*; do
if [ ! "$file" = "$DIR1/*" ]; then
dpkg-deb -b $file #pack 'em
else
echo -e "na[ERROR!] no folders in $DIR1"
read -sp "so nothing moved!"
fi
done
sleep 1
echo -e "n..moving them to upload foldern"
for filez in $DIR1/*.deb; do
if [ ! "$filez" = "$DIR1/*.deb" ]; then
echo "moving $filez to $DIR3"
mv $filez $DIR3 #move 'em
else
echo -e "na[ERROR!] no .deb's in $DIR1"
read -sp "..so nothing moved"
fi
done
read -sp "[DONE!] ..packed' and moved all files I could find!"
;;
3|list|LIST)
createdpkg()
{
echo -e "..building the Packagelistn"
cd $DIR2
dpkg-scanpackages -m . /dev/null >Packages #create Packagelist
sleep 1
if [ -f $DIR2/Packages ]; then
echo -e "n...compressing it...n"
bzip2 -k -f $DIR2/Packages #compress&move
read -sp "[DONE!] ..Packagelist created & compressed!"
else
echo -e "na[ERROR!] Packageliste was NOT created!"
read -sp "..so nothing compressed!"
sleep 1
fi
}
echo
if [ -f /usr/bin/dpkg-scanpackages ] && [ -f /etc/perl/dpkg-gettext.pl ]; then
createdpkg #all good
else
if [ ! -f /usr/bin/dpkg-scanpackages ]; then
echo -e "na[ERROR!] essential file 'dpkg-scanpackages' not found!"
read -p " ..try to download it?.. [Y/N] " choice_1
case "$choice_1" in
yes|YES|y|Y)
aptitude -y install dpkg-dev
echo -e "n..retrying now...n"
sleep 1
createdpkg #retry now..
;;
no|NO|n|N)
echo -e "n ..please download dpkg-scanpackages manually and place it in /usr/bin/"
echo "..exiting now!"
sleep 2
exit 1
;;
*)
echo -e "nsorry, but "$choice_1" is not a valid answer to my question!"
read -sp "..please try again!"
;;
esac
else
if [ ! -f /etc/perl/dpkg-gettext.pl ]; then
echo -e "na[ERROR!] essential file 'dpkg-gettext.pl' not found!"
read -p " ..try to download it?.. [Y/N] " choice_2
case "$choice_2" in
yes|YES|y|Y)
download=http://downloads.psypanda.org/dpkg-gettext.gz
secTEMP=$(mktemp -d) #open secTEMP
wget $download -o $secTEMP
gunzip $secTEMP/dpkg-gettext.gz
if [ -f $secTEMP/dpkg-gettext.pl ]; then
cp $secTEMP/dpkg-gettext.pl /etc/perl
chmod 0777 /etc/perl/dpkg-gettext.pl
else
echo -e "na[ERROR!] dpkg-gettext.pl doesn't exist in $secTEMP"
echo "..you need to download dpkg-gettext.pl manually & run me again!"
exit 1
fi
echo -e "n..retrying now...n"
sleep 1
rm -Rf $secTEMP
createdpkg #retry now..
;;
no|NO|n|N)
echo -e "na ..please download dpkg-gettext.pl manually and place it in /etc/perl/"
echo "..exiting now!"
sleep 2
exit 1
;;
*)
echo -e "nsorry, but "$choice_2" is not a valid answer to my question!"
read -sp "..please try again!"
;;
esac
fi
fi
fi
;;
4|sign|SIGN)
echo -e "n=======================================================
a [WARNING!] MAKE SURE YOU KNOW WHAT YOUR DOING!
======================================================="
read -sp "..otherwise please press CTRL+C to cancel now!!"
echo -e "nwriting MD5Sums to Release file.."
if [ ! -f $DIR2/Packages ] || [ ! -f $DIR2/Packages.bz2 ]; then
echo -e "a[ERROR!] you havent created a Package file!"
read -sp "..please create a Packagelist first!"
echo -e "n"
exit 1
else
if [ -f $DIR2/Release ]; then
sums_1=$(md5sum "$DIR2/Packages" | cut -c1-32) #md5sum=32chars
sums_2=$(md5sum "$DIR2/Packages.bz2" | cut -c1-32)
sbytes_1=$(stat -c%s "$DIR2/Packages")
sbytes_2=$(stat -c%s "$DIR2/Packages.bz2")
echo "MD5Sum:" >> $DIR2/Release
echo " $sums_1 $sbytes_1 $DIR6/Packages" >> $DIR2/Release
echo " $sums_2 $sbytes_2 $DIR6/Packages.bz2" >> $DIR2/Release
echo "" >> $DIR2/Release #essential newline
else
echo -e "na[ERROR!] there is no Release file in $DIR2"
read -sp "..so nothing wrote to it!"
echo -e "n..please create a Release file first and then run me again!"
sleep 2
exit 1
fi
fi
if [ -f $DIR2/Release ]; then
echo -e "nI assume you already created your GPG-key..n"
sleep 1
gpg -abs -o $DIR2/Release.gpg $DIR2/Release
echo -e "n"
read -sp "[DONE!] Packagelist signed successfull!"
else
echo -e "na[ERROR!] There is no Release file in $DIR2"
echo "..so nothing signed!"
fi
;;
5|ftp|FTP)
ftpupload()
{
#==========EDIT BELOW==========#
SERVER=
USERNAME=
PASSWORD=
REMOTEDIR=
#=========STOP EDITING=========#
FTP="/usr/bin/ncftpput"
for FILE in $DIR2/*; do
if [ ! "$FILE" = "$DIR2/*" ]; then
$FTP -m -R -u $USERNAME -p $PASSWORD $SERVER $REMOTEDIR $FILE
else
echo -e "na[ERROR!] no folders in $DIR2"
read -sp "so nothing uploaded!"
fi
read -sp "[DONE!] all files in folder $DIR2 uploaded!"
done
}
if [ -f /usr/bin/ncftpput ]; then
ftpupload
else
echo -e "na[ERROR!] ncftpput not installed!"
read -p "..do you want me to download it? [Y/N] " choice_6
case "$choice_6" in
yes|YES|y|Y)
aptitude -y install ncftp
echo -e "n..retrying now...n"
ftpupload #try now..
;;
no|NO|n|N)
echo -e "n ..please download ncftpput manually!"
echo "..exiting now!"
sleep 2
exit 1
;;
*)
echo -e "nsorry, but "$choice_6" is not a valid answer to my question!"
read -sp "..please try again!"
;;
esac
fi
;;
e|exit|E|EXIT)
exit 0;;
gpg|GPG)
echo -e "n=======================================================
a [WARNING!] MAKE SURE YOU KNOW WHAT YOUR DOING!
======================================================="
read -sp "..otherwise please press CTRL+C to cancel now!!"
echo -e "nCreating a GPGkey | ($(echo 'http://www.gnupg.org/' | tr q m))"
read -p " ..do you want to create one?.. [Y/N] " choice_3
case "$choice_3" in
yes|YES|y|Y)
echo -e "n..this step may take a little bit longer..n"
sleep 1
gpg --gen-key #create GPGkey
echo -e "n..GPG key created!"
read -p "do you want to create a pubkey of this GPGkey? [Y/N] " choice_4
case "$choice_4" in
yes|YES|y|Y)
echo -e "n..befor we start I need to know the name you choosed for your GPGkey"
echo -e "an[WARNING!] make sure you write the name case sensitive!!n"
read -p "what is the name of your GPGkey? " youNAME
read -p "you selected "$youNAME" - is this correct? [Y/N] " choice_5
case "$choice_5" in
yes|YES|y|Y)
echo -e "nOK - lets start..."
gpg --armor --output $youNAME.pub --export '$youNAME'
cp ./$youNAME.pub ~/cydia
read -sp "[DONE!] your pubkey is copied to $HOME/cydia"
;;
no|NO|n|N)
echo -e "n..I need to restart to give you another try - thx! -.-"
sleep 3
exit 1
;;
*)
echo -e "nsorry, but "$choice_5" is not a valid answer to my question!"
read -sp "..please try again!"
;;
esac
;;
no|NO|n|N)
echo -e "nOK - you need to manually make a pubkey using:"
read -sp " gpg --armor --output KEYNAME.pub --export '-YOURNAMEHERE-'"
;;
*)
echo -e "nsorry, but "$choice_4" is not a valid answer to my question!"
read -sp "..please try again!"
;;
esac
;;
no|NO|n|N)
echo -e "n ..create your own GPG key using 'gpg --gen-key'"
echo "..exiting now!"
sleep 3
exit 1
;;
*)
echo -e "nsorry, but "$choice_3" is not a valid answer to my question!"
read -sp "..please try again!"
;;
esac
;;
*)
echo -e "na[OOOPS!] Sorry $USER ["$answer"] is not valid!"
read -sp "..please try again!"
;;
esac
done #gn8