Skip to content
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

fix: unpacker script #145

Merged
merged 1 commit into from
Sep 11, 2023
Merged
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
25 changes: 12 additions & 13 deletions ctf/misc/cpio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ EOF
}

is_exist() {
if [ ! "$2" "$1" ]; then
if ! "$2" "$1"; then
echo "Could not find $1"
exit 255
fi
Expand All @@ -38,34 +38,34 @@ is_exist() {
compile_mac() {
CTR=0
while true; do
if [ $(basename $PWD) != "like-dbg" ] || [ ! -f "$(pwd)/.dockerfile_base" ]; then
if [ "$(basename "$PWD")" != "like-dbg" ] || [ ! -f "$(pwd)/.dockerfile_base" ]; then
pushd .. >/dev/null
((CTR++))
else
break
fi

done
if [ ! $(docker images | grep -o "like_mac_compiler") ]; then
if ! "$(docker images | grep -qo "like_mac_compiler")"; then
docker build -t "like_mac_compiler" -f .dockerfile_compiler_mac .
fi
while [ $CTR -ne 0 ]; do
popd >/dev/null
((CTR--))
done
rsync -u $2 $1/root/ >/dev/null
out="/io/bin/$(basename $2)"
rsync -u "$2" "$1/root/" >/dev/null
out="/io/bin/$(basename "$2")"
out=${out%.*}
docker run --rm -v "$(pwd)/$1":/io "like_mac_compiler" musl-gcc /io/root/$(basename $2) -static -o "$out"
docker run --rm -v "$(pwd)/$1":/io "like_mac_compiler" musl-gcc "/io/root/$(basename "$2")" -static -o "$out"
}

pack() {
is_exist "$1" "-d"

if [ -n "$3" ]; then
is_exist "$3" "-f"
if [ $(uname -s) == "Darwin" ]; then
compile_mac $1 $3
if [ "$(uname -s)" == "Darwin" ]; then
compile_mac "$1" "$3"
else
MUSL=$(which musl-gcc)
is_exist "$MUSL" "-f"
Expand All @@ -90,14 +90,14 @@ pack() {
}

unpack() {
if [ -z $(hash cpioi &>/dev/null) ]; then
if ! hash cpio 2>/dev/null; then
echo "Couldn't find 'cpio' utility... Exiting!"
exit 255
fi
mkdir initramfs
pushd . >/dev/null && pushd initramfs >/dev/null
cp ../"$1" .
LOCAL_ROOTFS="$(pwd)/$(basename $1)"
LOCAL_ROOTFS="$(pwd)/$(basename "$1")"

if [ "$2" -eq 1 ]; then

Expand All @@ -107,9 +107,9 @@ unpack() {
fi

rm "$LOCAL_ROOTFS"
LUSER=$(logname 2>/dev/null || echo $SUDO_USER)
LUSER=$(logname 2>/dev/null || echo "$SUDO_USER")
popd >/dev/null
chown -R $LUSER: initramfs
chown -R "$LUSER": initramfs
}

if [ $# -eq 0 ]; then
Expand Down Expand Up @@ -148,7 +148,6 @@ while true; do
;;
-*)
usage
exit 255
;;
*)
# No more options
Expand Down