-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpc_make.sh
executable file
·146 lines (135 loc) · 4.84 KB
/
rpc_make.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
142
143
144
145
#!/bin/sh
# rpc_make.sh, a Linux build/install tool for rpCalc.
# rpCalc, a calculator using reverse polish notation.
# Copyright (c) 2024, Douglas W. Bell.
# Free software, GPL v2 or later.
depends_error () {
echo
echo "Error installing dependencies." 1>&2
echo
echo "Please install the following packages manually:"
echo " Clang"
echo " CMake"
echo " curl"
echo " git"
echo " GTK development headers"
echo " Ninja build"
echo " pkg-config"
echo " XZ development headers"
echo
exit 1
}
misc_error () {
echo
echo "${1:-"Unknown Error"}" 1>&2
echo
exit 1
}
if [ "$(getconf LONG_BIT)" != "64" ]; then
misc_error "rpCalc only runs on a 64-bit OS"
fi
case "$1" in
"depends")
if [ "$(id -u)" != "0" ]; then
misc_error "'depends' must be run as sudo or root"
fi
if [ -x "$(command -v apt-get)" ]; then
echo "Detected 'apt-get' (Debian-based system)"
echo
apt-get -y install clang cmake curl git libgtk-3-dev ninja-build \
pkgconf liblzma-dev || depends_error
elif [ -x "$(command -v dnf)" ]; then
echo "Detected 'dnf' (Fedora-based system)"
echo
dnf -y install clang cmake curl git gtk3-devel ninja-build \
pkgconf xz-devel || depends_error
elif [ -x "$(command -v pacman)" ]; then
echo "Detected 'pacman' (Arch-based system)"
echo
pacman -S --needed --noconfirm clang cmake curl git gtk3 ninja \
pkgconf xz || depends_error
else
echo "Could not find a supported package manager"
depends_error
fi
;;
"build")
if [ "$(id -u)" = "0" ]; then
misc_error "'build' should not be run as sudo or root"
fi
echo "Downloading Flutter..."
flutter_site="https://storage.googleapis.com"
flutter_path="/flutter_infra_release/releases/stable/linux/"
flutter_file="flutter_linux_3.24.4-stable.tar.xz"
curl -O $flutter_site$flutter_path$flutter_file \
|| misc_error "Error: Could not download Flutter"
echo
echo "Extracting Flutter..."
tar -xf $flutter_file \
|| misc_error "Error: Could not extract Flutter archive"
echo "Extract done"
echo
export PATH="$PATH:`pwd`/flutter/bin"
flutter build linux --release || misc_error "Error - build failed"
echo
echo "rpCalc build successful"
;;
"install")
if [ "$(id -u)" != "0" ]; then
misc_error "'install' must be run as sudo or root"
fi
if [ ! -d "`pwd`/build/linux/x64/release/bundle" ]; then
misc_error "'build' must be successfully run prior to 'install'"
fi
echo "Copying Files..."
if [ ! -d "/opt" ]; then
mkdir -m 755 /opt \
|| misc_error "Could not create '/opt/rpcalc' directory"
fi
mkdir -p -m 755 /opt/rpcalc \
|| misc_error "Could not create '/opt/rpcalc' directory"
cp -pr `pwd`/build/linux/x64/release/bundle/* /opt/rpcalc/. \
|| misc_error "Could not copy files to '/opt/rpcalc' directory"
cp -p `pwd`/rpcalc.desktop `pwd`/rpcalc_icon_64.png /opt/rpcalc/.
echo "Copy done"
echo
echo "Creating symlinks..."
ln -sf /opt/rpcalc/rpcalc /usr/local/bin/. \
&& ln -sf /opt/rpcalc/rpcalc.desktop \
/usr/local/share/applications/. \
|| misc_error "Could not create symlinks"
echo "Symlinks created"
case ":$PATH:" in
*:/usr/local/bin:*) ;;
*) echo
echo "Note that /usr/local/bin is not in your \$PATH variable."
echo "Consider adding it or creating symlinks elsewhwere."
echo
;;
esac
;;
"uninstall")
if [ "$(id -u)" != "0" ]; then
misc_error "'uninstall' must be run as sudo or root"
fi
rm -rf /opt/rpcalc && echo "Removed /opt/rpcalc/" \
|| echo "Failed to remove /opt/rpcalc/"
rm /usr/local/bin/rpcalc \
&& echo "Removed /usr/local/bin/rpcalc (link)" \
|| echo "Failed to remove /usr/local/bin/rpcalc (link)"
rm /usr/local/share/applications/rpcalc.desktop \
&& echo "Removed rpcalc.desktop (link)" \
|| echo "Failed to remove rpcalc.desktop (link)"
;;
*)
opt_list="'depends', 'build', 'install' or 'uninstall'"
echo "Must have $opt_list as the first argument" 1>&2
echo
echo "Typical usage:"
echo " $ sudo ./rpc_make.sh depends"
echo " $ ./rpc_make.sh build"
echo " $ sudo ./rpc_make.sh install"
echo
exit 1
;;
esac