wifi-pineapple-cloner/tools/copier.sh

86 lines
1.9 KiB
Bash
Raw Permalink Normal View History

2023-11-10 04:06:00 +00:00
#!/bin/bash
# by DSR! from https://github.com/xchwarze/wifi-pineapple-cloner
FILE_LIST="$1"
FROM_FOLDER="$2"
TO_FOLDER="$3"
2023-11-10 15:31:47 +00:00
DISABLE_CLEAN="$4"
2023-11-10 04:06:00 +00:00
COUNTER=0
2023-11-10 15:31:47 +00:00
2023-11-10 04:06:00 +00:00
if [[ ! -f "$FILE_LIST" || ! -d "$FROM_FOLDER" || "$TO_FOLDER" == "" ]]; then
2023-11-10 15:31:47 +00:00
echo "Run with \"copier.sh [FILE_LIST] [FROM_FOLDER] [TO_FOLDER] [DISABLE_CLEAN]\""
echo " FILE_LIST -> flavor file list"
echo " FROM_FOLDER -> path to base fs"
echo " TO_FOLDER -> path to new fs"
echo " DISABLE_CLEAN -> disable clean of new fs folder"
2023-11-10 04:06:00 +00:00
exit 1
fi
FILE_LIST="$(realpath $FILE_LIST)"
FROM_FOLDER="$(realpath $FROM_FOLDER)"
TO_FOLDER="$(realpath $TO_FOLDER)"
2023-11-10 22:30:21 +00:00
echo " Filelist2Copy - by DSR!"
2023-11-10 04:06:00 +00:00
echo "******************************"
echo ""
2023-11-10 22:30:21 +00:00
echo " [*] Start copy loop"
2023-11-10 15:31:47 +00:00
2023-11-10 22:30:21 +00:00
if [ -z "$DISABLE_CLEAN" ]; then
echo " [*] Clean 'new fs' folder"
2023-11-10 15:31:47 +00:00
rm -rf "$TO_FOLDER"
fi
2023-11-10 22:30:21 +00:00
if [ ! -d "$TO_FOLDER" ]; then
echo " [*] Create 'new fs' folder"
mkdir "$TO_FOLDER"
fi
2023-11-10 04:06:00 +00:00
for FILE in $(cat "$FILE_LIST")
do
if [[ "${FILE:0:1}" != '/' ]]; then
continue
fi
# fix name chars
FILE=$(echo $FILE | sed $'s/\r//')
# check exist
if [[ ! -f "$FROM_FOLDER$FILE" ]] && [[ ! -d "$FROM_FOLDER$FILE" ]]; then
2023-11-10 22:30:21 +00:00
echo " [!] File does not exist: ${FROM_FOLDER}${FILE}"
2023-11-10 04:06:00 +00:00
continue
fi
# check file type
#TYPE_CHECK=$(file "$FROM_FOLDER$FILE" | grep "ELF")
#if [[ $TYPE_CHECK != "" ]]; then
# echo "[+] ELF: $FILE"
# continue
#fi
let COUNTER++
FOLDER=$(dirname $FILE)
mkdir -p "$TO_FOLDER$FOLDER"
# if folder...
if [[ -d "$FROM_FOLDER$FILE" ]]; then
cp -R "$FROM_FOLDER$FILE" "$TO_FOLDER$FILE"
else
cp -P "$FROM_FOLDER$FILE" "$TO_FOLDER$FILE"
fi
done
if [ $COUNTER -eq 0 ]; then
2023-11-10 22:30:21 +00:00
echo " [!] No files were copied. Verify that the paths are correct."
2023-11-10 04:06:00 +00:00
exit 1
fi
2023-11-10 22:30:21 +00:00
echo " [+] Files copied: $COUNTER"
2023-11-10 04:06:00 +00:00
echo ""