-
Notifications
You must be signed in to change notification settings - Fork 22
/
fakeapp.sh
executable file
·69 lines (56 loc) · 1.45 KB
/
fakeapp.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
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# @Author: Ethan
# @Date: 2016-05-27 10:34:38
# @Last Modified by: Ethan
# @Last Modified time: 2016-07-02 19:50:28
working_tmp=$(mktemp -t fakeapp -d);
fakesample_tgz=$working_tmp/fakesample.tgz;
trap 'rm -rf $working_tmp' EXIT SIGHUP SIGINT SIGQUIT;
appname="$1";
[ -z "$appname" ] && {
echo "Usage: fakeapp APPNAME";
echo "ERROR: APPNAME required!";
exit 1;
};
[ -d "$appname" ] && {
echo "WARNING: $appname exists, do you want to continue?"
read -p "(Y)es or (N)o: " confirm_option;
[ "$confirm_option" != "Y" ] && {
echo "Cancelled."
exit 0;
}
rm -rf $appname;
}
prepare_packed_files () {
echo "> Unpacking fakesample.tgz";
base64 -D -o $fakesample_tgz <<< "$fakesample_package";
tar xzvf $fakesample_tgz -C $working_tmp;
return 0;
}
replace_files () {
echo "> Rename fakesample files"
while read fakefile; do
local fakename=$(basename $fakefile);
[ -f $fakefile ] && {
echo "- replacing $fakename";
sed -i.bak "s/fakesample/$appname/g" $fakefile 2>/dev/null;
rm -rf $fakefile.bak;
};
[[ "$(basename $fakefile)" == *fakesample* ]] && {
echo "- rename $fakename";
mv -v $fakefile $(dirname "$fakefile")/${fakename/fakesample/$appname};
};
done <<< "$(find $working_tmp/fakesample | sort -r)";
return 0;
}
migrate_target () {
echo "> Moving target"
mv $working_tmp/$appname ./;
}
main () {
prepare_packed_files;
replace_files;
migrate_target;
echo "Fake app [$appname] created."
}
# generated data below