-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathase_rem
More file actions
executable file
·81 lines (69 loc) · 1.54 KB
/
ase_rem
File metadata and controls
executable file
·81 lines (69 loc) · 1.54 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
help(){
echo "Usage:"
echo " ase_sim [OPTIONS] [--]"
echo " ase_sim -a|--all"
echo "Options:"
echo -e " -a --add \t Remove all programs"
}
list_rem(){
find "$ASEDIR/programs/" -mindepth 1 -maxdepth 1 > ./tmp.txt
if [[ $(cat ./tmp.txt | wc -l) -eq 0 ]]; then
echo "no remaining programs"
rm ./tmp.txt
exit 0
fi
echo "remaining programs:"
while read -r line; do
echo -e "${line##*/}"
done < ./tmp.txt
rm ./tmp.txt
}
# getting options
if [[ -n $1 && ! "$1" =~ ^- && ! "$1" == "--" ]]; then
echo "Wrong option"
exit 1
fi
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do jump=1; case $1 in
-a | --all )
[ -d "$ASEDIR/results" ] && rm -rf $ASEDIR/results/*
[ -d "$ASEDIR/programs" ] && rm -rf $ASEDIR/programs/*
list_rem
exit 0
;;
* )
echo "Wrong option"
help
exit 1
esac; shift $jump; done
if [[ "$1" == '--' ]]; then shift; fi
# declare array
declare -a programs
# extract dirs of all programs
find "$ASEDIR/programs/" -mindepth 1 -maxdepth 1 > ./tmp.txt
if [[ $(cat ./tmp.txt | wc -l) -eq 0 ]]; then
echo "There is nothing to delete"
rm ./tmp.txt
exit 1
fi
# loop to populate the array
ind=0
while read -r line; do
programs[$ind]="$line"
echo -e "$ind) \t ${line##*/}"
((ind++))
done < ./tmp.txt
# read from ans
echo -n "Choose program to delete: "
read -r ans
dim=${#programs[@]}
if [[ ! $ans =~ ^[0-9]*$ || $ans -ge $dim ]]; then
echo "Wrong number"
rm ./tmp.txt
exit 1
fi
# delete selected dir
program_folder="${programs[$ans]}"
rm -rf $program_folder
rm -rf "$ASEDIR/results/${program_folder##*/}"
list_rem