1+ #! /bin/sh
2+
3+ # $INSTALLATION_PATH
4+ # SOURCE
5+
6+ set -e
7+
8+ if [ " $( id -u) " -ne 0 ]; then
9+ echo " Installation requires root privileges. Please execute this script as root (sudo)."
10+ exit 1
11+ fi
12+
13+ INSTALLATION_PATH=" ${INSTALLATION_PATH%/ } "
14+
15+ if [ -z " $INSTALLATION_PATH " ]; then
16+ INSTALLATION_PATH=" /bin"
17+ fi
18+
19+ determineDistro ()
20+ {
21+ . /etc/os-release
22+ DISTRO=$ID
23+ }
24+
25+ determineDistro
26+
27+ if [ -z " $SOURCE " ]; then
28+ if [ " $DISTRO " = " alpine" ]; then
29+ SOURCE=" https://github.com/draconware-dev/LineCount/releases/download/__VERSION__/linecount-__VERSION__-linux-alpine-amd64.tar.xz"
30+ else
31+ SOURCE=" https://github.com/draconware-dev/LineCount/releases/download/__VERSION__/linecount-__VERSION__-linux-amd64.tar.xz"
32+ fi
33+ fi
34+
35+ downloadProgram ()
36+ {
37+ if command -v wget > /dev/null 2>&1 ; then
38+ echo " Downloading $fileName ..."
39+ wget -q --show-progress -O $fileName " $SOURCE "
40+ return 0
41+ else
42+ if command -v curl > /dev/null 2>&1 ; then
43+ curl -o $fileName " $SOURCE "
44+ return 0
45+ fi
46+ fi
47+
48+ return 1
49+ }
50+
51+ hasInstalledWebClient=0
52+
53+ installWebClient ()
54+ {
55+ case " $DISTRO " in
56+ " ubuntu" | " debian" )
57+ echo " Temporarily installing wget..."
58+ apt-get update
59+ apt-get install -y wget
60+ ;;
61+ " centos" | " rhel" | " fedora" )
62+ echo " Temporarily installing wget..."
63+ yum install -y wget
64+ dnf install -y wget
65+ ;;
66+ " arch" | " manjaro" )
67+ echo " Temporarily installing wget..."
68+ pacman -Syu --noconfirm wget
69+ ;;
70+ " alpine" )
71+ echo " Temporarily installing wget..."
72+ apk add --no-cache wget
73+ ;;
74+ * )
75+ echo " Failed to install wget. Please install wget or curl manually as they constitute a requirement for the installation process."
76+ exit 2
77+ ;;
78+ esac
79+
80+ hasInstalledWebClient=1
81+ }
82+
83+ uninstallWebClient ()
84+ {
85+ case " $DISTRO " in
86+ " ubuntu" | " debian" )
87+ echo " Uninstalling wget..."
88+ apt-get remove --purge -y wget
89+ apt-get autoremove -y
90+ ;;
91+ " centos" | " rhel" | " fedora" )
92+ echo " Uninstalling wget..."
93+ yum remove -y wget
94+ dnf remove -y wget
95+ ;;
96+ " arch" | " manjaro" )
97+ echo " Uninstalling wget..."
98+ pacman -Rns --noconfirm wget
99+ ;;
100+ " alpine" )
101+ echo " Uninstalling wget..."
102+ apk del wget
103+ ;;
104+ * )
105+ ;;
106+ esac
107+ }
108+
109+ fileName=$( basename " $SOURCE " )
110+
111+ downloadProgram
112+
113+ if [ $? -ne 0 ]; then
114+ installWebClient
115+ downloadProgram
116+ fi
117+
118+ if [ $hasInstalledWebClient -ne 0 ]; then
119+ uninstallWebClient
120+ fi
121+
122+ mkdir -p " $INSTALLATION_PATH "
123+ mkdir -p .linecount
124+ tar -xf $fileName -C " .linecount"
125+ cp .linecount/linecount " $INSTALLATION_PATH /linecount"
126+ chmod +x " $INSTALLATION_PATH /linecount"
127+
128+ rm -rf .linecount
129+ rm -f " $fileName "
130+
131+ echo " Installation complete."
0 commit comments