-
Notifications
You must be signed in to change notification settings - Fork 0
/
fyndman.sh
executable file
·120 lines (116 loc) · 3.79 KB
/
fyndman.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
function build() {
if [ ! -d "$DIRECTORY" ]; then
mkdir $MAGENTODIR;
fi
IFS=$' \t\n'
cat fileslist | while read real temppath; do
if [ -z "$MAGENTODIR" ]; then
if [ ! -d "$temppath" ]; then
echo "Creating $temppath";
mkdir -p $temppath;
fi
else
filename="${temppath##*/}"
tempdir="${temppath:0:${#temppath} - ${#filename}}"
url=$MAGENTODIR$tempdir;
if [ ! -d "$url" ]; then
echo "Creating $url";
mkdir -p $url;
fi
fi
url=$MAGENTODIR$temppath
FILES=($real)
URL=($url)
for file in "${FILES[@]}"
do
if [[ -L "$URL" ]]
then
echo "Link already exist: $URL";
else
echo "Linking $DIR/$file to $URL";
ln -s "$DIR/$file" "$URL";
fi
done
done
}
function deploy() {
IFS=$' \t\n'
cat fileslist | while read real temppath; do
if [ -z "$MAGENTODIR" ]; then
if [ ! -d "$temppath" ]; then
echo "Creating $temppath";
mkdir -p $temppath;
fi
else
filename="${temppath##*/}"
tempdir="${temppath:0:${#temppath} - ${#filename}}"
url=$MAGENTODIR$tempdir;
if [ ! -d "$url" ]; then
echo "Creating $url";
mkdir -p $url;
fi
fi
FILES=($real)
for file in "${FILES[@]}"
do
echo "Copying "$DIR/$file" to $MAGENTODIR$temppath";
cp -r "$DIR/$file" $MAGENTODIR$temppath;
done
done
echo "Removing git- and DS_Store-related files in $MAGENTODIR";
find ./$MAGENTODIR -name "*.git*" -print0 | xargs -0 rm -rf;
find ./$MAGENTODIR -name "*.DS_Store*" -print0 | xargs -0 rm -rf;
find ./$MAGENTODIR -name "feed-*.csv" -print0 | xargs -0 rm -rf;
find ./$MAGENTODIR -name "deliverynote.pdf" -print0 | xargs -0 rm -rf;
find ./$MAGENTODIR -name "tests" -print0 | xargs -0 rm -rf;
find ./$MAGENTODIR -name "vendor" -print0 | xargs -0 rm -rf;
find ./$MAGENTODIR -name ".tx" -print0 | xargs -0 rm -rf;
find ./$MAGENTODIR -name ".editorconfig" -print0 | xargs -0 rm -rf;
COMMIT="$(git rev-parse --short HEAD)";
VERSION="$(perl -nle"print $& if m{(?<=<version>)[^<]+}" src/app/code/community/Fyndiq/Fyndiq/etc/config.xml)";
# replace COMMIT hash
sed -i '' 's/XXXXXX/'$COMMIT'/g' ./$MAGENTODIR\app/code/community/Fyndiq/Fyndiq/includes/config.php;
if [ $? -eq 0 ]; then
echo "Added $COMMIT to fyndiq config file to show correct commit in module.";
if [ -z "$VERSION" ]; then
echo "Error: Version variable is empty.";
else
zip -r -X fyndiq-magento-v$VERSION-$COMMIT.zip $MAGENTODIR*;
if [ $? -eq 0 ]; then
echo "Zipped the build to fyndiq-magento-$VERSION-$COMMIT.zip";
else
echo "ERROR: failed saving zip.";
fi
fi
else
echo "Error: Error while adding commit to file.";
fi
}
if [ -z "$1" ]
then
echo "Choose what you want to do first.";
echo "---------------------------------";
echo "build [magento dir] - Dev for symlink to different files and folders.";
echo "deploy [build dir] - Copy files to correct maps for release.";
elif [ "$1" = "build" ];
then
if [ -z "$2" ]
then
MAGENTODIR="./build"
else
MAGENTODIR=$2
fi
build;
elif [ "$1" = "deploy" ];
then
if [ ! -z "$2" ]
then
MAGENTODIR=$2
deploy;
else
echo "You need to specific a dir.";
echo "Type fyndman deploy build/ as example";
fi
fi