forked from KittyKatt/screenFetch
-
Notifications
You must be signed in to change notification settings - Fork 2
/
split-script.sh
executable file
·70 lines (54 loc) · 1.44 KB
/
split-script.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
70
#!/bin/sh -e
dir=screenfetch-split
script=screenfetch-dev
rm -rf $dir
mkdir -p $dir
cd $dir
# split ASCII arts from the actual script
csplit -s ../$script '/@ASCII_ARTS_/' '{*}'
mv xx00 ${script}_part1
echo '#@ASCII_ARTS_BEGIN@' >> ${script}_part1
mv xx01 aa
mv xx02 ${script}_part2
# split ASCII arts into individual files
sed -i '/#@ASCII_ARTS_BEGIN@/d; s/^[ \t]*$//; /^$/d' aa
csplit -s -z aa '/;;$/'1 '{*}' && rm aa
# rename files
for f in xx* ; do
name=$(head -n1 $f | cut -d '"' -f2 | sed 's/ /_/g; s/\//_/g')
mv $f aa_$name
echo "" >> aa_$name
done
# merge.sh
cat << EOF > merge.sh
#!/bin/sh -e
script=screenfetch-dev
cp \${script}_part1 \${script}
# use "cat \`ls aa_*\`" instead of "cat aa_*" to ignore case pattern
cat \`ls aa_*\` \${script}_part2 >> \${script}
chmod a+x \${script}
EOF
chmod a+x merge.sh
# source.sh
cat << EOF > source.sh
#!/bin/sh -e
if [ x"\${1}" = x ]; then
prefix=/usr/share/screenfetch
else
prefix="\${1}"
fi
script=screenfetch-dev
cp \${script}_part1 \${script}
sed -i "s@asciiText () {@asciiText () {\n\tprefix=\"\${prefix}\"@" \${script}
for f in \`ls aa_*\`; do
printf "\t\t" >> \${script}
head -n1 \${f} | sed 's/^[ \t]*//' >> \${script}
echo "\t\t\tsource \"\\\${prefix}/\${f}\" ;;" >> \${script}
tail -n+2 \${f} | head -n-2 > \${f}.new
rm \${f} && mv \${f}.new \${f}
done
cat \${script}_part2 >> \${script}
sed -i '/@ASCII_ARTS_/d' \${script}
chmod a+x \${script}
EOF
chmod a+x source.sh