This commit is contained in:
helixarch 2014-12-27 10:54:55 +02:00
parent ddb3b6bff2
commit 7fcff6b01f
2 changed files with 106 additions and 60 deletions

View File

@ -27,7 +27,7 @@ A script for converting .deb packages into Arch Linux packages, focused on accur
**Q: How do I use debtap?** **Q: How do I use debtap?**
**A:** The syntax is quite simple actually: `debtap package_filename` **A:** The syntax is quite simple actually: `debtap [option] package_filename`
For example: `debtap world-of-goo-demo_1.0_i386.deb` For example: `debtap world-of-goo-demo_1.0_i386.deb`
Any recommendations or questions for debtap are welcomed! Any recommendations or questions for debtap are welcomed!

164
debtap
View File

@ -10,40 +10,76 @@ bold=`tput bold`
normal=`tput sgr0` normal=`tput sgr0`
# Help and error messages # Help and error messages
if [[ "$1" == "-h" ]] || [[ "$1" == "--h" ]] || [[ "$1" == "-help" ]] || [[ "$1" == "--help" ]]; then if [[ "$1" == "-q" ]] || [[ "$1" == "--q" ]] || [[ "$1" == "-quiet" ]] || [[ "$1" == "--quiet" ]] || [[ "$1" == "-Q" ]] || [[ "$1" == "--Q" ]] || [[ "$1" == "-Quiet" ]] || [[ "$1" == "--Quiet" ]]; then
echo "Syntax: debtap package_filename"; exit 0 if [[ "$2" == "-h" ]] || [[ "$2" == "--h" ]] || [[ "$2" == "-help" ]] || [[ "$2" == "--help" ]]; then
elif [[ "$1" == "" ]]; then echo -e "Syntax: debtap [option] package_filename\n\nOptions:\n\n -h --h -help --help Prints this help message\n -q --q -quiet --quiet Bypass all questions, except for editing metadata file(s)\n -Q --Q -Quiet --Quiet Bypass all questions (not recommended)"; exit 0
echo -e "${red}Error: You haven't specified a deb package${NC}\nSyntax: debtap package_filename"; exit 1 elif [[ "$2" == "" ]]; then
elif [[ $(ls "$1" &> /dev/null; echo $?) != 0 ]]; then echo -e "${red}Error: You haven't specified a deb package${NC}\nSyntax: debtap [option] package_filename\n\nOptions:\n\n -h --h -help --help Prints this help message\n -q --q -quiet --quiet Bypass all questions, except for editing metadata file(s)\n -Q --Q -Quiet --Quiet Bypass all questions (not recommended)"; exit 1
echo -e "${red}Error: No such file or directory${NC}"; exit 1 elif [[ $(ls "$2" &> /dev/null; echo $?) != 0 ]]; then
elif [[ $(file -b "$1" | grep -q "Debian binary package"; echo $?) != 0 ]]; then echo -e "${red}Error: No such file or directory or invalid option${NC}"; exit 1
echo -e "${red}Error: You haven't specified a valid deb package${NC}"; exit 1 elif [[ $(file -b "$2" | grep -q "Debian binary package"; echo $?) != 0 ]]; then
elif [[ $(ping -c 1 www.google.com &> /dev/null; echo $?) != 0 ]]; then echo -e "${red}Error: You haven't specified a valid deb package${NC}"; exit 1
fi
else
if [[ "$1" == "-h" ]] || [[ "$1" == "--h" ]] || [[ "$1" == "-help" ]] || [[ "$1" == "--help" ]]; then
echo -e "Syntax: debtap [option] package_filename\n\nOptions:\n\n -h --h -help --help Prints this help message\n -q --q -quiet --quiet Bypass all questions, except for editing metadata file(s)\n -Q --Q -Quiet --Quiet Bypass all questions (not recommended)"; exit 0
elif [[ "$1" == "" ]]; then
echo -e "${red}Error: You haven't specified a deb package${NC}\nSyntax: debtap [option] package_filename\n\nOptions:\n\n -h --h -help --help Prints this help message\n -q --q -quiet --quiet Bypass all questions, except for editing metadata file(s)\n -Q --Q -Quiet --Quiet Bypass all questions (not recommended)"; exit 1
elif [[ $(ls "$1" &> /dev/null; echo $?) != 0 ]]; then
echo -e "${red}Error: No such file or directory or invalid option${NC}"; exit 1
elif [[ $(file -b "$1" | grep -q "Debian binary package"; echo $?) != 0 ]]; then
echo -e "${red}Error: You haven't specified a valid deb package${NC}"; exit 1
fi
fi
if [[ $(ping -c 1 www.google.com &> /dev/null; echo $?) != 0 ]]; then
echo -e "${red}Error: You have no internet access, which is necessary for this script to work${NC}"; exit 1 echo -e "${red}Error: You have no internet access, which is necessary for this script to work${NC}"; exit 1
elif [[ $(ls /var/cache/pkgfile/*.files | wc -l) == 0 ]]; then elif [[ $(ls /var/cache/pkgfile/*.files 2> /dev/null | wc -l) == 0 ]]; then
echo -e "${red}Error: You must run at least once \"pkgfile -u\" with root privileges (preferably recently), before running this script${NC}"; exit 1 echo -e "${red}Error: You must run at least once \"pkgfile -u\" with root privileges (preferably recently), before running this script${NC}"; exit 1
fi fi
# Defining and creating working directory # Defining and creating working directory
working_directory="`ls "$1" | tr '[:upper:]' '[:lower:]' | sed s'/\.deb//'`-working-directory" if [[ "$1" == "-q" ]] || [[ "$1" == "--q" ]] || [[ "$1" == "-quiet" ]] || [[ "$1" == "--quiet" ]] || [[ "$1" == "-Q" ]] || [[ "$1" == "--Q" ]] || [[ "$1" == "-Quiet" ]] || [[ "$1" == "--Quiet" ]]; then
working_directory="`ls "$2" | tr '[:upper:]' '[:lower:]' | sed s'/\.deb//'`-working-directory"
else
working_directory="`ls "$1" | tr '[:upper:]' '[:lower:]' | sed s'/\.deb//'`-working-directory"
fi
mkdir "$working_directory" mkdir "$working_directory"
cd "$working_directory" cd "$working_directory"
# Extracting package data and metadata in working directory # Extracting package data and metadata in working directory
echo -e "${lightgreen}==>${NC} ${bold}Extracting package data...${normal}" echo -e "${lightgreen}==>${NC} ${bold}Extracting package data...${normal}"
ar p ../"$1" control.tar.gz | tar xz if [[ "$1" == "-q" ]] || [[ "$1" == "--q" ]] || [[ "$1" == "-quiet" ]] || [[ "$1" == "--quiet" ]] || [[ "$1" == "-Q" ]] || [[ "$1" == "--Q" ]] || [[ "$1" == "-Quiet" ]] || [[ "$1" == "--Quiet" ]]; then
ar p ../"$2" control.tar.gz | tar xz
else
ar p ../"$1" control.tar.gz | tar xz
fi
rm -rf $(ls * | grep -v 'control\|conffiles') rm -rf $(ls * | grep -v 'control\|conffiles')
data_tar_check=`ar t ../"$1" | grep data` if [[ "$1" == "-q" ]] || [[ "$1" == "--q" ]] || [[ "$1" == "-quiet" ]] || [[ "$1" == "--quiet" ]] || [[ "$1" == "-Q" ]] || [[ "$1" == "--Q" ]] || [[ "$1" == "-Quiet" ]] || [[ "$1" == "--Quiet" ]]; then
if [ $data_tar_check == data.tar.gz ]; then data_tar_check=`ar t ../"$2" | grep data`
ar p ../"$1" data.tar.gz | tar xz if [ $data_tar_check == data.tar.gz ]; then
elif [ $data_tar_check == data.tar.xz ]; then ar p ../"$2" data.tar.gz | tar xz
ar p ../"$1" data.tar.xz | tar xJ elif [ $data_tar_check == data.tar.xz ]; then
elif [ $data_tar_check == data.tar.bz2 ]; then ar p ../"$2" data.tar.xz | tar xJ
ar p ../"$1" data.tar.bz2 | tar xj elif [ $data_tar_check == data.tar.bz2 ]; then
elif [ $data_tar_check == data.tar.lzma ]; then ar p ../"$2" data.tar.bz2 | tar xj
ar p ../"$1" data.tar.lzma | tar xJ elif [ $data_tar_check == data.tar.lzma ]; then
elif [ $data_tar_check == data.tar ]; then ar p ../"$2" data.tar.lzma | tar xJ
ar p ../"$1" data.tar | tar x elif [ $data_tar_check == data.tar ]; then
ar p ../"$2" data.tar | tar x
fi
else
data_tar_check=`ar t ../"$1" | grep data`
if [ $data_tar_check == data.tar.gz ]; then
ar p ../"$1" data.tar.gz | tar xz
elif [ $data_tar_check == data.tar.xz ]; then
ar p ../"$1" data.tar.xz | tar xJ
elif [ $data_tar_check == data.tar.bz2 ]; then
ar p ../"$1" data.tar.bz2 | tar xj
elif [ $data_tar_check == data.tar.lzma ]; then
ar p ../"$1" data.tar.lzma | tar xJ
elif [ $data_tar_check == data.tar ]; then
ar p ../"$1" data.tar | tar x
fi
fi fi
# Fixing possible differences in filesystem hierarchy of the extracted package data, so that it matches Arch Linux filesystem hierarchy # Fixing possible differences in filesystem hierarchy of the extracted package data, so that it matches Arch Linux filesystem hierarchy
@ -160,9 +196,13 @@ echo "url = `grep Homepage: control | gawk '{print $2}'`" | sed s'/\/$//' >> .PK
echo "builddate = `date -u "+%s"`" >> .PKGINFO echo "builddate = `date -u "+%s"`" >> .PKGINFO
# Generating packager field # Generating packager field
echo -e "\n${lightblue}::${NC} Enter Packager name:" if [[ "$1" == "-q" ]] || [[ "$1" == "--q" ]] || [[ "$1" == "-quiet" ]] || [[ "$1" == "--quiet" ]] || [[ "$1" == "-Q" ]] || [[ "$1" == "--Q" ]] || [[ "$1" == "-Quiet" ]] || [[ "$1" == "--Quiet" ]]; then
read packager_name echo "packager = Unknown Packager" >> .PKGINFO
echo "packager = $packager_name" >> .PKGINFO else
echo -e "\n${lightblue}::${NC} Enter Packager name:"
read packager_name
echo "packager = $packager_name" >> .PKGINFO
fi
# Generating arch field # Generating arch field
echo "arch = `grep Architecture: control | gawk '{print $2}' | sed -e s'/i386/i686/' -e s'/amd64/x86_64/' -e s'/all/any/'`" >> .PKGINFO echo "arch = `grep Architecture: control | gawk '{print $2}' | sed -e s'/i386/i686/' -e s'/amd64/x86_64/' -e s'/all/any/'`" >> .PKGINFO
@ -176,13 +216,17 @@ fi
echo "size =" $(expr `du -sb | tr -d " ."` - `ls -l | grep control | gawk '{print $5}'` - $conffiles_size - `ls -la | grep .PKGINFO | gawk '{print $5}'` - 4096) >> .PKGINFO echo "size =" $(expr `du -sb | tr -d " ."` - `ls -l | grep control | gawk '{print $5}'` - $conffiles_size - `ls -la | grep .PKGINFO | gawk '{print $5}'` - 4096) >> .PKGINFO
# Generating license field # Generating license field
echo -e "\n${lightblue}::${NC} Enter package license (you can enter multiple licenses comma seperated):" if [[ "$1" == "-q" ]] || [[ "$1" == "--q" ]] || [[ "$1" == "-quiet" ]] || [[ "$1" == "--quiet" ]] || [[ "$1" == "-Q" ]] || [[ "$1" == "--Q" ]] || [[ "$1" == "-Quiet" ]] || [[ "$1" == "--Quiet" ]]; then
read package_license echo "license = custom" >> .PKGINFO
for i in `echo "$package_license" | sed -e s'/ /__/g' -e s'/,/ /g'`; do else
license+=($i) echo -e "\n${lightblue}::${NC} Enter package license (you can enter multiple licenses comma seperated):"
done read package_license
for (( i=0; i<$(echo ${#license[@]}); i=i+1 )); do license[$i]=$(echo ${license[$i]} | sed s'/__/ /g'); done for i in `echo "$package_license" | sed -e s'/ /__/g' -e s'/,/ /g'`; do
printf '%s\n' "${license[@]}" | while read line; do echo "license = $line" >> .PKGINFO ; done license+=($i)
done
for (( i=0; i<$(echo ${#license[@]}); i=i+1 )); do license[$i]=$(echo ${license[$i]} | sed s'/__/ /g'); done
printf '%s\n' "${license[@]}" | while read line; do echo "license = $line" >> .PKGINFO ; done
fi
# The packages names translator function # The packages names translator function
packages-names-translator() { packages-names-translator() {
@ -3279,33 +3323,35 @@ fi
rm -rf control conffiles virtual-packages rm -rf control conffiles virtual-packages
# Prompting user for editing .PKGINFO and .INSTALL files # Prompting user for editing .PKGINFO and .INSTALL files
if [ -e .INSTALL ]; then if [[ "$1" != "-Q" ]] && [[ "$1" != "--Q" ]] && [[ "$1" != "-Quiet" ]] && [[ "$1" != "--Quiet" ]]; then
echo -en "\n${lightblue}::${NC} ${bold}If you want to edit .PKGINFO and .INSTALL files (in this order), press (1) For${normal} ${lightred}vi${NC} ${bold}(2) For${normal} ${lightred}nano${NC} ${bold}(3) For${normal} ${lightred}a custom editor${NC} ${bold}or any other key to continue: ${normal}" if [ -e .INSTALL ]; then
read -n 1 number echo -en "\n${lightblue}::${NC} ${bold}If you want to edit .PKGINFO and .INSTALL files (in this order), press (1) For${normal} ${lightred}vi${NC} ${bold}(2) For${normal} ${lightred}nano${NC} ${bold}(3) For${normal} ${lightred}a custom editor${NC} ${bold}or any other key to continue: ${normal}"
if [[ $number == 1 ]]; then read -n 1 number
vi .PKGINFO; vi .INSTALL; echo if [[ $number == 1 ]]; then
elif [[ $number == 2 ]]; then vi .PKGINFO; vi .INSTALL; echo
nano .PKGINFO; nano .INSTALL; echo elif [[ $number == 2 ]]; then
elif [[ $number == 3 ]]; then nano .PKGINFO; nano .INSTALL; echo
echo -en "\n${lightblue}::${NC} ${bold}Enter command for running custom editor: ${normal}" elif [[ $number == 3 ]]; then
read custom_editor echo -en "\n${lightblue}::${NC} ${bold}Enter command for running custom editor: ${normal}"
$custom_editor .PKGINFO; $custom_editor .INSTALL read custom_editor
$custom_editor .PKGINFO; $custom_editor .INSTALL
else
echo
fi
else else
echo echo -en "\n${lightblue}::${NC} ${bold}If you want to edit .PKGINFO file, press (1) For${normal} ${lightred}vi${NC} ${bold}(2) For${normal} ${lightred}nano${NC} ${bold}(3) For${normal} ${lightred}a custom editor${NC} ${bold}or any other key to continue: ${normal}"
fi read -n 1 number
else if [[ $number == 1 ]]; then
echo -en "\n${lightblue}::${NC} ${bold}If you want to edit .PKGINFO file, press (1) For${normal} ${lightred}vi${NC} ${bold}(2) For${normal} ${lightred}nano${NC} ${bold}(3) For${normal} ${lightred}a custom editor${NC} ${bold}or any other key to continue: ${normal}" vi .PKGINFO; echo
read -n 1 number elif [[ $number == 2 ]]; then
if [[ $number == 1 ]]; then nano .PKGINFO; echo
vi .PKGINFO; echo elif [[ $number == 3 ]]; then
elif [[ $number == 2 ]]; then echo -en "\n${lightblue}::${NC} ${bold}Enter command for running custom editor: ${normal}"
nano .PKGINFO; echo read custom_editor
elif [[ $number == 3 ]]; then $custom_editor .PKGINFO
echo -en "\n${lightblue}::${NC} ${bold}Enter command for running custom editor: ${normal}" else
read custom_editor echo
$custom_editor .PKGINFO fi
else
echo
fi fi
fi fi