-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-installer.sh
More file actions
executable file
·87 lines (85 loc) · 1.98 KB
/
github-installer.sh
File metadata and controls
executable file
·87 lines (85 loc) · 1.98 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
82
83
84
85
86
87
#!/bin/bash
defdir="/opt";
app="${1}";
function ask_continue() {
read -p "Continue? [y/n] " -n 1 -s response </dev/tty
if [ ! "${response}" = "y" ]; then
echo "${response}"
echo
echo "User abort. Exiting."
exit 1;
fi
echo "${response}"
echo
}
echo "Installing ${app}..."
echo
read -e -p "Select a directory to install to (a subdirectory will be created here): [${defdir}] " -i "${defdir}" installdir </dev/tty
if [ "${installdir}" = "" ]; then
installdir="${defdir}";
fi
installdir=$(realpath ${installdir})/${app}
echo -e "\n$app will be installed to \"${installdir}\""
ask_continue
git clone https://github.com/parhuzamos/${app}.git ${installdir}
exitcode=$?
if [ ! "${exitcode}" = "0" ]; then
echo
echo "Program error (${exitcode}). Exiting."
exit ${exitcode}
fi
OIFS=IFS
IFS=":"
echo
echo "Select a directory to place symlink(s):"
select linkdir in $PATH; do
break;
done </dev/tty
IFS=$OIFS
if [ "${linkdir}" = "" ]; then
echo "User abort. Exiting."
exit 1;
fi
linkdir=$(realpath $linkdir)
executables=""
count=0
for file in ${installdir}/*; do
if $(head -n 1 ${file} | grep "#\!/" >/dev/null); then
if [[ "${executables}" = "" ]]; then
executables=$file
else
executables=${executables}:$file
fi;
count=$((count+1))
fi
done
echo "Creating ${count} symlink(s) in \"${linkdir}\""
ask_continue
OIFS=IFS
IFS=":"
for executable in ${executables}; do
filename=$(basename "${executable}")
filename="${filename%.*}"
echo "Link ${executable} -> ${linkdir}/${filename}"
ln -s ${executable} ${linkdir}/${filename}
done
IFS=$OIFS
uninstall=${installdir}/uninstall.sh
echo "#!/bin/bash" >${uninstall}
echo "rm -rf ${installdir}" >>${uninstall}
OIFS=IFS
IFS=":"
for executable in ${executables}; do
filename=$(basename "${executable}")
filename="${filename%.*}"
echo "rm ${linkdir}/${filename}" >>${uninstall}
done;
IFS=$OIFS
chmod +x ${uninstall}
echo
echo
echo "Installation successfull."
echo "To uninstall execute the just created \"uninstall.sh\": "
echo " ${uninstall}"
echo
echo "Done."