-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
56 lines (41 loc) · 1.51 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
##Author: Louis Stefanski
##Date: 2/9/2023
#A script to create an executable file, run it, then clean up after itself
#The only files left after execution are the following:
# copy.asm -> a copy of the file given to ensure it is safe
# fileName -> the executable, uncomment last line if you do not want the
# executable file to stay after this program terminates
#get file name
echo $'\nEnter file name: '
read fileName
echo -e "\e"
#ensure the fileName is not a .asm or .o
#if it is the script exits prompting the user to not use said extension
if [[ "$fileName" == *.asm ]] || [[ "$fileName" == *.o ]]
then
echo -e "\e[31m\nInvalid input, please do not include .asm or .o\e[0m"...
echo -e "\e[31m\nExiting now...\e[0m"
exit 1
fi
#create a copy of the asm file
cp ${fileName}'.asm' ./'copy.asm'
{ #try to remove the skel file if it exists, NOTE: This could be removed as its function is redundant.
#removal would not have a significant impact on preformance, and it prevents any erroneous errors
rm $fileName
} || { #if it does not exist
echo "Failed to remove executable file..."
}
#create driver.c
echo "int main() {int ret_status; ret_status = asm_main(); return ret_status;}" > driver.c
echo -e "\e[31m\nImplicit Delcaration Error should be ignored...\n\n\e[0m"
#create object file and compile
nasm -f elf64 ${fileName}'.asm'
gcc -no-pie -o ${fileName} ${fileName}'.o' driver.c
#remove object file
rm ${fileName}'.o'
#run the file
./${fileName}
#remove driver.c
rm driver.c
#remove the executable file
#rm $fileName