/
parnas.sh
executable file
·84 lines (68 loc) · 2.48 KB
/
parnas.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
#!/usr/bin/env bash
APP_NAME=Parnas
LATEST_BUILD_INFO=$(curl -s https://api.github.com/repos/sndl/parnas/releases/latest)
CHANGELOG_URL='https://github.com/sndl/parnas/blob/master/CHANGELOG.md'
PARNAS_HOME=$HOME/.local/share/parnas
FIRST_ARG=$1
check_prerequisites () {
local required_utils="java curl jq"
for util in ${required_utils}
do
which ${util} > /dev/null
if [[ $? -eq 1 ]]; then
echo "\"$util\" has to be installed to use the wrapper"
exit 1
fi
done
}
check_config () {
[[ ! -d ${PARNAS_HOME} ]] && mkdir -p ${PARNAS_HOME}
[[ ! -f ${PARNAS_HOME}/version ]] && touch ${PARNAS_HOME}/version
}
check_for_updates () {
local cur_ver=$(cat ${PARNAS_HOME}/version)
local latest_ver=$(echo ${LATEST_BUILD_INFO} | jq -r '.name')
local jar_name=${PARNAS_HOME}/${APP_NAME}.jar
if [[ ${latest_ver} == "" || ${latest_ver} == "null" ]]; then
echo "WARNING: Couldn't connect to GitHub to check for updates."
return
fi
if [[ ${cur_ver} == "" || ${cur_ver} != ${latest_ver} || ! -f ${jar_name} || (${FIRST_ARG} == "check-updates" && ${cur_ver} != ${latest_ver}) ]]; then
if [[ ${latest_ver} == $(cat ${PARNAS_HOME}/skip-update 2> /dev/null) && ${FIRST_ARG} != "check-updates" ]]
then
echo "You are using ${APP_NAME} ${cur_ver}, newever version ($(cat ${PARNAS_HOME}/skip-update)) is available but was skipped."
return
fi
echo "New version of ${APP_NAME} is available - ${latest_ver}"
echo "CHANGELOG: $CHANGELOG_URL"
echo "Would you like to update? (yes/no):"
read confirmation
if [[ ${confirmation} == "yes" ]]; then
echo "Updating..."
curl $(echo ${LATEST_BUILD_INFO} | jq -r '.assets[].browser_download_url') -L -s -o ${jar_name} && echo ${latest_ver} > ${PARNAS_HOME}/version
echo "Updated!"
else
echo "${latest_ver}" > ${PARNAS_HOME}/skip-update
echo "Update to ${latest_ver} skipped."
echo "You can always check for updates by running \"${APP_NAME} check-updates\""
fi
else
echo "You are using latest version of ${APP_NAME} - ${cur_ver}"
fi
if [[ ${FIRST_ARG} == "check-updates" ]]
then
echo "Exiting..."
exit 0
fi
}
execute () {
java -jar ${PARNAS_HOME}/${APP_NAME}.jar "$@"
}
main () {
check_prerequisites
check_config
check_for_updates
execute "$@"
}
main "$@"
exit 0