-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
141 lines (117 loc) · 3.6 KB
/
install.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/sh
PROJECT_OWNER="GaZaTu"
PROJECT_REPO="im-emoji-picker"
PROJECT_NAME="I'm Emoji Picker"
RELEASE="latest"
FRAMEWORK=""
while getopts ":r:f:" flag
do
case $flag in
r) RELEASE="$OPTARG";;
f) FRAMEWORK="$OPTARG";;
esac
done
if [ -z "$FRAMEWORK" ];
then
if command -v ibus > /dev/null;
then
FRAMEWORK="ibus"
fi
if command -v fcitx5 > /dev/null;
then
FRAMEWORK="fcitx5"
fi
fi
if [ -z "$FRAMEWORK" ];
then
echo "no input method framework found/specified (example: \"sh install.sh -f fcitx5\")"
exit 1
fi
echo "Installing \"$PROJECT_NAME\" release: \"$RELEASE\"..."
DISTRO_ID=$(grep "^ID=" "/etc/os-release" | sed "s/ID=//" | sed "s/\"//g")
DISTRO_VERSION_ID=$(grep "^VERSION_ID=" "/etc/os-release" | sed "s/VERSION_ID=//" | sed "s/\"//g")
PACKAGE_MANAGER=$(
case "$DISTRO_ID" in
"ubuntu"* | "debian"*) echo "apt";;
"opensuse"*) echo "zypper";;
"fedora"*) echo "dnf";;
esac
)
PACKAGE_MANAGER_INSTALL_COMMAND=$(
case "$PACKAGE_MANAGER" in
"apt") echo "install -y";;
"zypper") echo "install -y --allow-unsigned-rpm";;
"dnf") echo "install -y --nogpgcheck";;
esac
)
if ! command -v jq > /dev/null;
then
if [ -z "$PACKAGE_MANAGER" ];
then
echo "jq not found, and no known package manager found to install it either"
exit 1
fi
echo ""
echo "jq not found, installing through package manager..."
echo "> sudo $PACKAGE_MANAGER $PACKAGE_MANAGER_INSTALL_COMMAND jq"
sudo $PACKAGE_MANAGER $PACKAGE_MANAGER_INSTALL_COMMAND jq
fi
echo ""
echo "Check github for release artifacts..."
RELEASE_ID=$(echo $RELEASE | sed "s/\//-/")
RELEASE_JSON="/tmp/$PROJECT_REPO-$RELEASE_ID.json"
wget -nv "https://api.github.com/repos/$PROJECT_OWNER/$PROJECT_REPO/releases/$RELEASE" -O "$RELEASE_JSON"
echo ""
echo "Find artifact for $DISTRO_ID $DISTRO_VERSION_ID"
URL=$(jq -r ".assets | .[] | .browser_download_url | select(. | (test(\"$DISTRO_ID\") and test(\"$DISTRO_VERSION_ID\") and test(\"$FRAMEWORK\")))" "$RELEASE_JSON")
ARTIFACT_IS_APPIMAGE=false
# if [ -z "$URL" ];
# then
# echo "Matching artifact not found; Find .AppImage instead"
# URL=$(jq -r ".assets | .[] | .browser_download_url | select(. | (test(\".AppImage\")))" "$RELEASE_JSON")
# ARTIFACT_IS_APPIMAGE=true
# fi
if [ -z "$URL" ];
then
echo "No artifact found; either something went wrong or your system is not supported"
exit 1
fi
ARTIFACT_NAME=$(basename "$URL")
ARTIFACT_PATH="/tmp/$ARTIFACT_NAME"
# EXECUTABLE_NAME="emoji-picker"
# APPIMAGE_NAME="$EXECUTABLE_NAME.AppImage"
# APPIMAGE_INSTALL_PATH="/usr/bin/$APPIMAGE_NAME"
echo ""
echo "Downloading artifact..."
wget -q --show-progress "$URL" -O "$ARTIFACT_PATH"
if $ARTIFACT_IS_APPIMAGE
then
echo "ARTIFACT_IS_APPIMAGE should be 0"
# if command -v $EXECUTABLE_NAME > /dev/null;
# then
# echo ""
# echo "Abort: do not override $EXECUTABLE_NAME with .AppImage"
# exit 2
# fi
# EXECUTABLE_NAME="$APPIMAGE_NAME"
# echo ""
# echo "Move artifact and make it executable"
# echo "> sudo cp $ARTIFACT_PATH $APPIMAGE_INSTALL_PATH"
# sudo cp "$ARTIFACT_PATH" "$APPIMAGE_INSTALL_PATH"
# echo "> sudo chmod +x $APPIMAGE_INSTALL_PATH"
# sudo chmod +x "$APPIMAGE_INSTALL_PATH"
else
# if command -v $APPIMAGE_NAME > /dev/null;
# then
# echo ""
# echo "Remove existing .AppImage"
# echo "> sudo rm $APPIMAGE_INSTALL_PATH"
# sudo rm "$APPIMAGE_INSTALL_PATH"
# fi
echo ""
echo "Install artifact using package manager"
echo "> sudo $PACKAGE_MANAGER $PACKAGE_MANAGER_INSTALL_COMMAND $ARTIFACT_PATH"
sudo $PACKAGE_MANAGER $PACKAGE_MANAGER_INSTALL_COMMAND "$ARTIFACT_PATH"
fi
echo ""
echo "\"$PROJECT_NAME\" installed! 🎉"