Created
January 4, 2019 19:17
-
-
Save BruceGitHub/6f6e02552c846d3fee8cd8cef204baab to your computer and use it in GitHub Desktop.
Scritp for matrioska challenge (beta)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
workpath=$(pwd) | |
rm -r -f temp | |
echo $workpath | |
function goToWorkPath() { | |
cd $workpath | |
} | |
function save() { | |
goToWorkPath | |
mkdir copy | |
cp $1 copy | |
cd copy | |
filenameAsHas=$(md5 -q $1) | |
mv $1 $filenameAsHas | |
} | |
function move_temp_dir() { | |
goToWorkPath | |
mkdir temp | |
mv $1 temp | |
cd temp | |
mv * $2 | |
} | |
function prepare_for_restart() { | |
mv * file.hack | |
mv file.hack ../ | |
} | |
while : | |
do | |
let "var=var+1" | |
let "last=last+1" | |
if [ $last -gt 100 ] | |
then | |
last=0 | |
fi | |
find . -name "*.hack" -print | while read filename; do | |
file $filename | |
cd $workpath | |
rm -r -f temp | |
echo $var | |
echo $filename | |
if file $filename | grep -q "ASCII cpio archive (pre-SVR4 or odc)"; then | |
save $filename | |
move_temp_dir $filename "file_cpio" | |
cpio -i -F file_cpio | |
rm file_cpio | |
prepare_for_restart | |
elif file $filename | grep -q "MAR archive data"; then | |
save $filename | |
move_temp_dir $filename "mar.zip" | |
open -W -j mar.zip | |
rm mar.zip | |
prepare_for_restart | |
elif file $filename | grep -q "gzip"; then | |
save $filename | |
move_temp_dir $filename "file.gz" | |
gzip -d file.gz | |
rm file.gz | |
prepare_for_restart | |
elif file $filename | grep -q "7-zip"; then | |
save $filename | |
move_temp_dir $filename "file.zip" | |
7z e "file.zip" | |
rm "file.zip" | |
prepare_for_restart | |
elif file $filename | grep -q "Zip archive"; then | |
save $filename | |
move_temp_dir $filename "file.zip" | |
unzip -j -d tmp "file.zip"; | |
rm "file.zip" | |
cp tmp/* . && rm -R tmp | |
prepare_for_restart | |
elif file $filename | grep -q "bzip2"; then | |
save $filename | |
move_temp_dir $filename "file.zip" | |
bzip2 -d "file.zip"; | |
rm "file.zip" | |
mv *.out file_$var.hack | |
prepare_for_restart | |
elif file $filename | grep -q "DOS"; then | |
echo "END" | |
echo "END" | |
echo "END" | |
echo "END" | |
echo "END" | |
echo "END" | |
echo "END" | |
echo "END" | |
echo "END" | |
save $filename | |
move_temp_dir $filename "file.zip" | |
fi | |
done | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment