mirror of
https://github.com/helixarch/debtap
synced 2024-11-22 10:20:25 +01:00
refactor: use mktemp for temporary directories
This commit is contained in:
parent
99991fa9c9
commit
378125b68d
60
debtap
60
debtap
|
@ -163,9 +163,8 @@ tar_extract_cmd() {
|
||||||
|
|
||||||
# Defining package with full path & defining and creating working directory
|
# Defining package with full path & defining and creating working directory
|
||||||
package_with_full_path="`readlink -f "${@: -1}"`"
|
package_with_full_path="`readlink -f "${@: -1}"`"
|
||||||
working_directory="`pwd`/`basename "${@: -1}" | tr '[:upper:]' '[:lower:]' | sed s'/\.deb$//'`-working-directory"
|
working_directory=$(mktemp -d -p "`pwd`" "`basename "${@: -1}" | tr '[:upper:]' '[:lower:]' | sed s'/\.deb$//'`".XXXXXXXXXX)
|
||||||
rm -rf "$working_directory" 2> /dev/null
|
trap 'rm -rf "$working_directory"' EXIT
|
||||||
mkdir "$working_directory" 2> /dev/null
|
|
||||||
if [[ $(echo $?) != 0 ]]; then
|
if [[ $(echo $?) != 0 ]]; then
|
||||||
echo -e "${red}Error: Cannot create working directory, permission denied. Exiting...${NC}"
|
echo -e "${red}Error: Cannot create working directory, permission denied. Exiting...${NC}"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -177,14 +176,12 @@ echo -e "${lightgreen}==>${NC} ${bold}Extracting package data...${normal}"
|
||||||
control_tar_check=$(ar t "$package_with_full_path" | grep -m 1 "control\.tar")
|
control_tar_check=$(ar t "$package_with_full_path" | grep -m 1 "control\.tar")
|
||||||
control_extract=$(tar_extract_cmd "$control_tar_check")
|
control_extract=$(tar_extract_cmd "$control_tar_check")
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
rm -rf "$working_directory"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
ar p "$package_with_full_path" "$control_tar_check" | $control_extract
|
ar p "$package_with_full_path" "$control_tar_check" | $control_extract
|
||||||
|
|
||||||
if [[ $pseudo == set ]] && [[ $(grep ^Architecture: control | grep -q i386; echo $?) != 0 ]]; then
|
if [[ $pseudo == set ]] && [[ $(grep ^Architecture: control | grep -q i386; echo $?) != 0 ]]; then
|
||||||
echo -e "${red}Error: Invalid package architecture. Removing extracted package data and exiting...${NC}"
|
echo -e "${red}Error: Invalid package architecture. Removing extracted package data and exiting...${NC}"
|
||||||
rm -rf "$working_directory"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -192,7 +189,6 @@ rm -rf $(ls * | grep -v 'control\|preinst\|postinst\|prerm\|postrm\|conffiles')
|
||||||
data_tar_check=$(ar t "$package_with_full_path" | grep -m 1 "data\.tar")
|
data_tar_check=$(ar t "$package_with_full_path" | grep -m 1 "data\.tar")
|
||||||
data_extract=$(tar_extract_cmd "$data_tar_check")
|
data_extract=$(tar_extract_cmd "$data_tar_check")
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
rm -rf "$working_directory"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
ar p "$package_with_full_path" "$data_tar_check" | $data_extract
|
ar p "$package_with_full_path" "$data_tar_check" | $data_extract
|
||||||
|
@ -2930,59 +2926,59 @@ if [[ $(grep -q '^Recommends:\|^Suggests:' control; echo $?) == 0 ]]; then
|
||||||
rm -rf *tempfile* optional-dependencies-initial-check-list final-check-list
|
rm -rf *tempfile* optional-dependencies-initial-check-list final-check-list
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Moving report files to /tmp/debtap (if any exist)
|
# Moving report files to debtap temporary directory (if any exist)
|
||||||
rm -rf /tmp/debtap 2> /dev/null
|
debtap_tmp=$(mktemp -d -p /tmp debtap.XXXXXXXXXX)
|
||||||
mkdir /tmp/debtap 2> /dev/null
|
|
||||||
if [[ $(echo $?) != 0 ]]; then
|
if [[ $(echo $?) != 0 ]]; then
|
||||||
echo -e "${red}Error: Cannot create /tmp/debtap, permission denied${NC}"
|
echo -e "${red}Error: Cannot create a temporary directory, permission denied${NC}"
|
||||||
fi
|
fi
|
||||||
mv *untranslated* /tmp/debtap 2> /dev/null
|
trap 'rm -rf "$working_directory" "$debtap_tmp"' EXIT
|
||||||
mv *missing-files /tmp/debtap 2> /dev/null
|
mv *untranslated* "$debtap_tmp" 2> /dev/null
|
||||||
|
mv *missing-files "$debtap_tmp" 2> /dev/null
|
||||||
|
|
||||||
# Report of (warning messages for) untranslated packages names and packages with missing files (if any exist)
|
# Report of (warning messages for) untranslated packages names and packages with missing files (if any exist)
|
||||||
if [[ -e /tmp/debtap/dependencies-untranslated-names-only ]]; then
|
if [[ -e "$debtap_tmp/dependencies-untranslated-names-only" ]]; then
|
||||||
echo -e "\n${lightred}Warning: These dependencies (depend = fields) could not be translated into Arch Linux packages names:${NC}"
|
echo -e "\n${lightred}Warning: These dependencies (depend = fields) could not be translated into Arch Linux packages names:${NC}"
|
||||||
echo `cat /tmp/debtap/dependencies-untranslated-names-only` | sed s'/ /, /g'
|
echo `cat "$debtap_tmp/dependencies-untranslated-names-only"` | sed s'/ /, /g'
|
||||||
fi
|
fi
|
||||||
if [[ -e /tmp/debtap/dependencies-missing-files ]]; then
|
if [[ -e "$debtap_tmp/dependencies-missing-files" ]]; then
|
||||||
if [[ -e /tmp/debtap/dependencies-untranslated-names-only ]]; then
|
if [[ -e "$debtap_tmp/dependencies-untranslated-names-only" ]]; then
|
||||||
echo -e "${lightred}Warning: These packages names could not be included as dependencies, because debtap has translated them into the same name with the package for conversion. This happens sometimes when you convert packages that already exist in your repositories (which is a bad idea in general). The following packages contain files that are already included in the package from your repositories (without these files your converted package may be dysfunctional):${NC}"
|
echo -e "${lightred}Warning: These packages names could not be included as dependencies, because debtap has translated them into the same name with the package for conversion. This happens sometimes when you convert packages that already exist in your repositories (which is a bad idea in general). The following packages contain files that are already included in the package from your repositories (without these files your converted package may be dysfunctional):${NC}"
|
||||||
else
|
else
|
||||||
echo -e "\n${lightred}Warning: These packages names could not be included as dependencies, because debtap has translated them into the same name with the package for conversion. This happens sometimes when you convert packages that already exist in your repositories (which is a bad idea in general). The following packages contain files that are already included in the package from your repositories (without these files your converted package may be dysfunctional):${NC}"
|
echo -e "\n${lightred}Warning: These packages names could not be included as dependencies, because debtap has translated them into the same name with the package for conversion. This happens sometimes when you convert packages that already exist in your repositories (which is a bad idea in general). The following packages contain files that are already included in the package from your repositories (without these files your converted package may be dysfunctional):${NC}"
|
||||||
fi
|
fi
|
||||||
echo `cat /tmp/debtap/dependencies-missing-files` | sed s'/ /, /g'
|
echo `cat "$debtap_tmp/dependencies-missing-files"` | sed s'/ /, /g'
|
||||||
fi
|
fi
|
||||||
if [[ -e /tmp/debtap/optional-dependencies-untranslated-names-only-1 ]]; then
|
if [[ -e "$debtap_tmp/optional-dependencies-untranslated-names-only-1" ]]; then
|
||||||
if [[ -e /tmp/debtap/dependencies-untranslated-names-only ]] || [[ -e /tmp/debtap/dependencies-missing-files ]]; then
|
if [[ -e "$debtap_tmp/dependencies-untranslated-names-only" ]] || [[ -e "$debtap_tmp/dependencies-missing-files" ]]; then
|
||||||
echo -e "${lightred}Warning: These optional dependencies (optdepend = fields) could not be translated into Arch Linux packages names:${NC}"
|
echo -e "${lightred}Warning: These optional dependencies (optdepend = fields) could not be translated into Arch Linux packages names:${NC}"
|
||||||
else
|
else
|
||||||
echo -e "\n${lightred}Warning: These optional dependencies (optdepend = fields) could not be translated into Arch Linux packages names:${NC}"
|
echo -e "\n${lightred}Warning: These optional dependencies (optdepend = fields) could not be translated into Arch Linux packages names:${NC}"
|
||||||
fi
|
fi
|
||||||
echo `cat /tmp/debtap/optional-dependencies-untranslated-names-only-1` | sed s'/ /, /g'
|
echo `cat "$debtap_tmp/optional-dependencies-untranslated-names-only-1"` | sed s'/ /, /g'
|
||||||
fi
|
fi
|
||||||
if [[ -e /tmp/debtap/replacements-untranslated-names-only ]]; then
|
if [[ -e "$debtap_tmp/replacements-untranslated-names-only" ]]; then
|
||||||
if [[ -e /tmp/debtap/dependencies-untranslated-names-only ]] || [[ -e /tmp/debtap/dependencies-missing-files ]] || [[ -e /tmp/debtap/optional-dependencies-untranslated-names-only-1 ]]; then
|
if [[ -e "$debtap_tmp/dependencies-untranslated-names-only" ]] || [[ -e "$debtap_tmp/dependencies-missing-files" ]] || [[ -e "$debtap_tmp/optional-dependencies-untranslated-names-only-1" ]]; then
|
||||||
echo -e "${lightred}Warning: These replacements (replaces = fields) could not be translated into Arch Linux packages names:${NC}"
|
echo -e "${lightred}Warning: These replacements (replaces = fields) could not be translated into Arch Linux packages names:${NC}"
|
||||||
else
|
else
|
||||||
echo -e "\n${lightred}Warning: These replacements (replaces = fields) could not be translated into Arch Linux packages names:${NC}"
|
echo -e "\n${lightred}Warning: These replacements (replaces = fields) could not be translated into Arch Linux packages names:${NC}"
|
||||||
fi
|
fi
|
||||||
echo `cat /tmp/debtap/replacements-untranslated-names-only` | sed s'/ /, /g'
|
echo `cat "$debtap_tmp/replacements-untranslated-names-only"` | sed s'/ /, /g'
|
||||||
fi
|
fi
|
||||||
if [[ -e /tmp/debtap/conflicts-untranslated-names-only ]]; then
|
if [[ -e "$debtap_tmp/conflicts-untranslated-names-only" ]]; then
|
||||||
if [[ -e /tmp/debtap/dependencies-untranslated-names-only ]] || [[ -e /tmp/debtap/dependencies-missing-files ]] || [[ -e /tmp/debtap/optional-dependencies-untranslated-names-only-1 ]] || [[ -e /tmp/debtap/replacements-untranslated-names-only ]]; then
|
if [[ -e "$debtap_tmp/dependencies-untranslated-names-only" ]] || [[ -e "$debtap_tmp/dependencies-missing-files" ]] || [[ -e "$debtap_tmp/optional-dependencies-untranslated-names-only-1" ]] || [[ -e "$debtap_tmp/replacements-untranslated-names-only" ]]; then
|
||||||
echo -e "${lightred}Warning: These conflicts (conflict = fields) could not be translated into Arch Linux packages names:${NC}"
|
echo -e "${lightred}Warning: These conflicts (conflict = fields) could not be translated into Arch Linux packages names:${NC}"
|
||||||
else
|
else
|
||||||
echo -e "\n${lightred}Warning: These conflicts (conflict = fields) could not be translated into Arch Linux packages names:${NC}"
|
echo -e "\n${lightred}Warning: These conflicts (conflict = fields) could not be translated into Arch Linux packages names:${NC}"
|
||||||
fi
|
fi
|
||||||
echo `cat /tmp/debtap/conflicts-untranslated-names-only` | sed s'/ /, /g'
|
echo `cat "$debtap_tmp/conflicts-untranslated-names-only"` | sed s'/ /, /g'
|
||||||
fi
|
fi
|
||||||
if [[ -e /tmp/debtap/provisions-untranslated-names-only ]]; then
|
if [[ -e "$debtap_tmp/provisions-untranslated-names-only" ]]; then
|
||||||
if [[ -e /tmp/debtap/dependencies-untranslated-names-only ]] || [[ -e /tmp/debtap/dependencies-missing-files ]] || [[ -e /tmp/debtap/optional-dependencies-untranslated-names-only-1 ]] || [[ -e /tmp/debtap/replacements-untranslated-names-only ]] || [[ -e /tmp/debtap/conflicts-untranslated-names-only ]]; then
|
if [[ -e "$debtap_tmp/dependencies-untranslated-names-only" ]] || [[ -e "$debtap_tmp/dependencies-missing-files" ]] || [[ -e "$debtap_tmp/optional-dependencies-untranslated-names-only-1" ]] || [[ -e "$debtap_tmp/replacements-untranslated-names-only" ]] || [[ -e "$debtap_tmp/conflicts-untranslated-names-only" ]]; then
|
||||||
echo -e "${lightred}Warning: These provisions (provides = fields) could not be translated into Arch Linux packages names:${NC}"
|
echo -e "${lightred}Warning: These provisions (provides = fields) could not be translated into Arch Linux packages names:${NC}"
|
||||||
else
|
else
|
||||||
echo -e "\n${lightred}Warning: These provisions (provides = fields) could not be translated into Arch Linux packages names:${NC}"
|
echo -e "\n${lightred}Warning: These provisions (provides = fields) could not be translated into Arch Linux packages names:${NC}"
|
||||||
fi
|
fi
|
||||||
echo `cat /tmp/debtap/provisions-untranslated-names-only` | sed s'/ /, /g'
|
echo `cat "$debtap_tmp/provisions-untranslated-names-only"` | sed s'/ /, /g'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Generating .INSTALL file (if necessary)
|
# Generating .INSTALL file (if necessary)
|
||||||
|
@ -3195,8 +3191,6 @@ fi
|
||||||
if [[ $pkgbuild != set ]] && [[ $Pkgbuild != set ]]; then
|
if [[ $pkgbuild != set ]] && [[ $Pkgbuild != set ]]; then
|
||||||
# Removing leftover files
|
# Removing leftover files
|
||||||
echo -e "${lightgreen}==>${NC} ${bold}Removing leftover files...${normal}"
|
echo -e "${lightgreen}==>${NC} ${bold}Removing leftover files...${normal}"
|
||||||
rm -rf "$working_directory"
|
|
||||||
rm -rf /tmp/debtap
|
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -3383,8 +3377,6 @@ rm -rf "../$pkgname" 2> /dev/null
|
||||||
mkdir "../$pkgname" 2> /dev/null
|
mkdir "../$pkgname" 2> /dev/null
|
||||||
if [[ $(echo $?) != 0 ]]; then
|
if [[ $(echo $?) != 0 ]]; then
|
||||||
echo -e "${red}Error: Cannot create PKGBUILD directory, permission denied. Removing leftover files and exiting...${NC}"
|
echo -e "${red}Error: Cannot create PKGBUILD directory, permission denied. Removing leftover files and exiting...${NC}"
|
||||||
rm -rf "$working_directory"
|
|
||||||
rm -rf /tmp/debtap
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
mv PKGBUILD "../$pkgname"
|
mv PKGBUILD "../$pkgname"
|
||||||
|
@ -3399,6 +3391,4 @@ fi
|
||||||
|
|
||||||
# Removing leftover files
|
# Removing leftover files
|
||||||
echo -e "${lightgreen}==>${NC} ${bold}Removing leftover files...${normal}"
|
echo -e "${lightgreen}==>${NC} ${bold}Removing leftover files...${normal}"
|
||||||
rm -rf "$working_directory"
|
|
||||||
rm -rf /tmp/debtap
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue
Block a user