Skip to content

Avoid downloading blob to symlink/hardlink dir of ./download #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
cd "$(dirname "$0")"
cd "$(dirname "$0")" || exit

SOURCE="http://mirrors.ustc.edu.cn/gnu/libc"
GLIBC_DIR="/glibc"
Expand All @@ -17,7 +17,7 @@ fi


die() {
echo >&2 $1
echo >&2 "$1"
exit 1
}

Expand All @@ -28,11 +28,11 @@ usage() {

download(){
local filename=$1
if [ ! -f srcs/$filename ]; then
if [ ! -f srcs/"$filename" ]; then
wget "$SOURCE/$filename" -O "srcs/$filename"
else
echo "[?] srcs/$filename already exists. remove it to re-download. continue ? (y/[n])"
read opt
read -r opt
if [ "$opt" = "y" ] || [ "$opt" = "Y" ]; then
:
else
Expand All @@ -44,21 +44,21 @@ download(){
extract(){
local filepath=$1
local output_dir=$2
if [ ! -f $filepath ]; then
if [ ! -f "$filepath" ]; then
die "[-] Invalid filepath: $filepath"
fi
if [ ! -d $output_dir ]; then
if [ ! -d "$output_dir" ]; then
echo "[*] Making directory $output_dir"
mkdir -p $output_dir
cp $filepath $output_dir/src.tar.gz
pushd $output_dir 1>/dev/null
mkdir -p "$output_dir"
cp "$filepath" "$output_dir"/src.tar.gz
pushd "$output_dir" 1>/dev/null || exit
tar xf src.tar.gz
mv */* ./
mv ./*/* ./
rm src.tar.gz
popd 1>/dev/null
popd 1>/dev/null || exit
else
echo "[?] Seems that source code exists in $output_dir. continue ? (y/[n])"
read opt
read -r opt
if [ "$opt" = "y" ] || [ "$opt" = "Y" ]; then
:
else
Expand All @@ -71,28 +71,28 @@ build(){
local arch=$1
local src_dir=$2
local output_dir=$3
if [ ! -d $src_dir ]; then
if [ ! -d "$src_dir" ]; then
die "[-] Invalid src_dir: $src_dir"
fi
if [ ! -d $output_dir ]; then
if [ ! -d "$output_dir" ]; then
echo "[*] Making directory $output_dir"
mkdir -p $output_dir
mkdir -p "$output_dir"
fi
pushd $src_dir 1>/dev/null
pushd "$src_dir" 1>/dev/null || exit
mkdir build
cd build
if [ $arch = 'amd64' ]; then
../configure --prefix=$output_dir --disable-werror --enable-debug=yes
elif [ $arch = 'i686' ]; then
../configure --prefix=$output_dir --disable-werror --enable-debug=yes --host=i686-linux-gnu --build=i686-linux-gnu CC="gcc -m32" CXX="g++ -m32"
cd build || exit
if [ "$arch" = 'amd64' ]; then
../configure --prefix="$output_dir" --disable-werror --enable-debug=yes
elif [ "$arch" = 'i686' ]; then
../configure --prefix="$output_dir" --disable-werror --enable-debug=yes --host=i686-linux-gnu --build=i686-linux-gnu CC="gcc -m32" CXX="g++ -m32"
else
die "[-] Invalid arch: $arch"
fi
make
make install
cd ../
rm -rf build
popd 1>/dev/null
popd 1>/dev/null || exit
}


Expand All @@ -109,10 +109,10 @@ ARCH=$2
SRC="glibc-$GLIBC_VERSION.tar.gz"

echo "[*] downloading $SRC"
download $SRC
download "$SRC"
SRC_DIR=$GLIBC_DIR/$GLIBC_VERSION/source
echo "[*] extracting to $SRC_DIR"
extract "srcs/$SRC" $SRC_DIR
extract "srcs/$SRC" "$SRC_DIR"
echo "[*] building..."
build $ARCH $SRC_DIR $GLIBC_DIR/$GLIBC_VERSION/$ARCH/
build "$ARCH" "$SRC_DIR" $GLIBC_DIR/"$GLIBC_VERSION"/"$ARCH"/
echo "[+] build finished. check $GLIBC_DIR/$GLIBC_VERSION/$ARCH/"
19 changes: 11 additions & 8 deletions download
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash
cd "$(dirname "$0")"
set -e
ROOTDIR=$(dirname "$(realpath "$0")")
cd "$ROOTDIR"

if [ ! -d "libs" ]; then
mkdir libs
fi
Expand All @@ -16,7 +19,7 @@ LIBC_PREFIX="libc6_"
LIBC_DBG_PREFIX="libc6-dbg_"

die() {
echo >&2 $1
echo >&2 "$1"
exit 1
}

Expand All @@ -38,22 +41,22 @@ download_single() {
local url="$SOURCE/$deb_name"
echo " -> Location: $url"
echo " -> Downloading libc binary package"
wget "$url" 2>/dev/null -O debs/$deb_name || die "Failed to download package from $url"
wget "$url" 2>/dev/null -O debs/"$deb_name" || die "Failed to download package from $url"
echo " -> Extracting libc binary package"

mkdir libs/$id
./extract debs/$deb_name libs/$id
mkdir libs/"$id"
./extract debs/"$deb_name" libs/"$id"
echo " -> Package saved to libs/$id"

# download debug info package
local url="$SOURCE/$dbg_name"
echo " -> Location: $url"
echo " -> Downloading libc debug package"
wget "$url" 2>/dev/null -O debs/$dbg_name || die "Failed to download package from $url"
wget "$url" 2>/dev/null -O debs/"$dbg_name" || die "Failed to download package from $url"
echo " -> Extracting libc debug package"

mkdir libs/$id/.debug
./extract debs/$dbg_name libs/$id/.debug
mkdir libs/"$id"/.debug
./extract debs/"$dbg_name" libs/"$id"/.debug
echo " -> Package saved to libs/$id/.debug"
}

Expand Down
19 changes: 11 additions & 8 deletions download_old
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash
cd "$(dirname "$0")"
set -e
ROOTDIR=$(dirname "$(realpath "$0")")
cd "$ROOTDIR"

if [ ! -d "libs" ]; then
mkdir libs
fi
Expand All @@ -14,7 +17,7 @@ LIBC_PREFIX="libc6_"
LIBC_DBG_PREFIX="libc6-dbg_"

die() {
echo >&2 $1
echo >&2 "$1"
exit 1
}

Expand All @@ -36,22 +39,22 @@ download_single() {
local url="$SOURCE/$deb_name"
echo " -> Location: $url"
echo " -> Downloading libc binary package"
wget "$url" 2>/dev/null -O debs/$deb_name || die "Failed to download package from $url"
wget "$url" 2>/dev/null -O debs/"$deb_name" || die "Failed to download package from $url"
echo " -> Extracting libc binary package"

mkdir libs/$id
./extract debs/$deb_name libs/$id
mkdir libs/"$id"
./extract debs/"$deb_name" libs/"$id"
echo " -> Package saved to libs/$id"

# download debug info package
local url="$SOURCE/$dbg_name"
echo " -> Location: $url"
echo " -> Downloading libc debug package"
wget "$url" 2>/dev/null -O debs/$dbg_name || die "Failed to download package from $url"
wget "$url" 2>/dev/null -O debs/"$dbg_name" || die "Failed to download package from $url"
echo " -> Extracting libc debug package"

mkdir libs/$id/.debug
./extract debs/$dbg_name libs/$id/.debug
mkdir libs/"$id"/.debug
./extract debs/"$dbg_name" libs/"$id"/.debug
echo " -> Package saved to libs/$id/.debug"
}

Expand Down
34 changes: 16 additions & 18 deletions extract
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
cd "$(dirname "$0")"
cd "$(dirname "$0")" || exit

die() {
echo >&2 $1
echo >&2 "$1"
exit 1
}

Expand All @@ -12,37 +12,35 @@ usage() {
}

extract() {
local deb=`readlink -f $1`
local deb=$(readlink -f "$1")
local out=$2
if [ ! -d "$out" ]; then
mkdir $out
mkdir "$out"
fi
local tmp=`mktemp -d`
local tmp=$(mktemp -d)

cd $tmp
ar xv $deb || die "ar failed"
cd "$tmp" || exit
ar xv "$deb" || die "ar failed"
if [ -f "data.tar.zst" ];then
tar -I zstd -xf data.tar.* || die "tar failed"
else
tar xf data.tar.* || die "tar failed"
fi
cd -

cp -rP $tmp/lib/*/* $out 2>/dev/null \
|| cp -rP $tmp/lib32/* $out 2>/dev/null \
|| cp -rP $tmp/usr/lib/*/* $out 2>/dev/null \
|| cp -rP $tmp/usr/lib/debug/lib/*/* $out 2>/dev/null \
|| cp -rP $tmp/usr/lib/debug/lib32/* $out 2>/dev/null \
|| cp -rP $tmp/usr/lib/debug/.build-id $out 2>/dev/null \
cd - || exit

cp -rP "$tmp"/lib/*/* "$out" 2>/dev/null \
|| cp -rP "$tmp"/lib32/* "$out" 2>/dev/null \
|| cp -rP "$tmp"/usr/lib/*/* "$out" 2>/dev/null \
|| cp -rP "$tmp"/usr/lib/debug/lib/*/* "$out" 2>/dev/null \
|| cp -rP "$tmp"/usr/lib/debug/lib32/* "$out" 2>/dev/null \
|| cp -rP "$tmp"/usr/lib/debug/.build-id "$out" 2>/dev/null \
|| die "Failed to save. Check it manually $tmp"

rm -rf $tmp
rm -rf "$tmp"
}

if [[ $# -ne 2 ]]; then
usage
fi

extract "$1" "$2"