-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
drfree
164 lines (162 loc) · 4.39 KB
/
drfree
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#
# drfree - function to make it easy for me to move around in my projects
# usage: drfree <action> <project>
# where <action> is one of "build", "clone", "cd", "delete"
# and <project> is the name of a project or one of the shortcuts
# "images", "instagram", "mirror", "roon", "scenes", "scripts", or "telegram"
#
# Dot this file in to your .bashrc or other shell startup
# e.g. in $HOME/.bashrc add the following lines:
#
# if [ -f /usr/local/share/bash/drfree ]; then
# . /usr/local/share/bash/drfree
# fi
drfree() {
if [ "$#" -ne 2 ]
then
echo '
usage: drfree <action> <project>
where <action> is one of "build", "clone", "cd", or "delete"
and <project> is the name of a project or one of the shortcuts
"images", "instagram", "mirror", "roon", "scenes", "scripts", or "telegram"
'
else
# The default build script is named "mkpkg"
# If a project has a front-end build script named anything different
# then set BUILD="whatever" below in that project's case statement
# The BUILD keyword "MM" is used to signify a MagicMirror build which will
# do a "git pull" and then "npm install" in the project directory.
BUILD="mkpkg"
case "$2" in
gdrive|drive)
PROJECT="DriveCommandLine"
;;
images)
PROJECT="MirrorImages"
;;
instagram)
PROJECT="MMM-InstagramView"
BUILD="MM"
;;
macscan*|macaddress*)
PROJECT="MMM-MacAddressScan"
BUILD="MM"
;;
mirror)
PROJECT="MirrorCommand"
;;
roon)
PROJECT="RoonCommandLine"
;;
scenes)
PROJECT="MMM-Scenes"
BUILD="MM"
;;
scripts)
PROJECT="DoctorFreeScripts"
;;
telegram)
PROJECT="MMM-TelegramCommands"
BUILD="MM"
;;
youtube*|webview*)
PROJECT="MMM-YouTubeWebView"
BUILD="MM"
;;
*)
PROJECT="$2"
;;
esac
case "$1" in
build)
if [ -d ${HOME}/src/${PROJECT} ]
then
cd ${HOME}/src/${PROJECT}
git pull
else
[ -d ${HOME}/src ] || mkdir ${HOME}/src
cd ${HOME}/src
git clone https://gitlab.com/doctorfree/${PROJECT}.git
cd ${PROJECT}
fi
if [ -x ./${BUILD} ]
then
./${BUILD}
else
if [ "${BUILD}" == "MM" ]
then
git pull
npm_inst=`type -p npm`
if [ "${npm_inst}" ]
then
npm install
else
echo "Could not locate npm in PATH"
echo "Skipping 'npm install' in ${PROJECT}"
fi
else
echo "Missing or non-executable ${BUILD} in ${PROJECT} project"
fi
fi
;;
clone)
[ -d ${HOME}/src ] || mkdir ${HOME}/src
cd ${HOME}/src
if [ -d ${PROJECT}/.git ]
then
cd ${PROJECT}
echo "Pulling in existing project directory ${PROJECT}"
git pull
else
if [ -x ./clone-${PROJECT}.sh ]
then
./clone-${PROJECT}.sh
else
git clone https://gitlab.com/doctorfree/${PROJECT}.git
fi
cd ${PROJECT}
fi
;;
cd)
if [ -d ${HOME}/src/${PROJECT} ]
then
cd ${HOME}/src/${PROJECT}
else
[ -d ${HOME}/src ] || mkdir ${HOME}/src
cd ${HOME}/src
git clone https://gitlab.com/doctorfree/${PROJECT}.git
cd ${PROJECT}
fi
;;
delete)
if [ -d ${HOME}/src/${PROJECT} ]
then
delete=
while true
do
read -p "Delete ${HOME}/src/${PROJECT} ? ('Y'/'N'): " yn
case $yn in
[Yy]*)
delete=1
break
;;
[Nn]*)
delete=
break
;;
* )
echo "Please answer yes or no."
;;
esac
done
[ "${delete}" ] && rm -rf ${HOME}/src/${PROJECT}
else
echo "No directory ${HOME}/src/${PROJECT}"
fi
;;
*)
echo "Unknown action: $1"
;;
esac
fi
}