forked from kvaps/fake-systemd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
systemctl-installer
executable file
·120 lines (102 loc) · 3.04 KB
/
systemctl-installer
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
#!/bin/sh
#
# @file systemctl-installer
# @version v1.0
# @description systemctl installer
# @author gmt4 <gmt4 at github.com> (c) Copyright 2022 GPLv2+
# @url github.com/gmt4/systemctl
#
PROGNAME=${0##*/}
PROGVERSION="v1.0"
PROGAUTHOR=gmt4
PROGURL="https://github.com/gmt4/fake-systemd"
set -euf
SHELL="${SHELL:-/bin/sh}"
PREFIX="${PREFIX:-/usr/local}"
BINDIR="${BINDIR:-$PREFIX/bin}"
SCRIPT="systemctl extras/systemctl-installer"
systemctl_fetch()
{
mkdir -p "$BINDIR"
echo "Fetching systemctl from $PROGURL"
for script in $SCRIPT;
do
file="$BINDIR/${script##*/}"
url="$PROGURL/raw/master/$script"
echo "Fetch $file"
curl -fsSL -o "$file" "$url"
chmod u+x "$file"
done
}
systemctl_link()
{
mkdir -p "$BINDIR"
for script in $SCRIPT;
do
ln -svfn "$(pwd)/$script" "$BINDIR";
done
}
systemctl_install()
{
echo "Installing $PROGNAME ..."
mkdir -p "$BINDIR"
for script in $SCRIPT;
do
install -Dvm755 "$(pwd)/$script" "$BINDIR";
done
}
systemctl_uninstall()
{
echo "Un-installing $PROGNAME ..."
for script in $SCRIPT;
do
rm -v "$BINDIR/${script##*/}";
done
}
systemctl_check_update()
{
master=$(curl -fsSL "$PROGURL/raw/master/extras/$PROGNAME" |
awk '/^PROGVERSION=/ { gsub("PROGVERSION=",""); gsub("\\x22",""); print}'
)
if [ "$PROGVERSION" = "$master" ]
then
echo "$PROGNAME: Not-Found new version at $PROGURL (latest: $master)"
else
echo "$PROGNAME: Found new version at $PROGURL (latest: $master)"
fi
}
usage()
{
echo "usage: $PROGNAME args # @version $PROGVERSION (c) $PROGAUTHOR $PROGURL"
echo " check-update : Check for updates"
echo " fetch-user : Fetch to BINDIR=$HOME/bin"
echo " link-user : Symlink to BINDIR=$HOME/bin"
echo " install-user : Install to BINDIR=$HOME/bin"
echo " install-sys : Install to BINDIR=$PREFIX/bin"
echo " uninstall-sys : Uninstall from BINDIR=$PREFIX/bin"
echo " uninstall-user : Uninstall from BINDIR=$HOME/bin}"
echo "*tips: If unsure where to start, start with: $PROGNAME link-user"
exit
}
main()
{
if [ $# -lt 1 ]; then usage; fi
# hack to force SHELL back to posix-sh in macOS
case "$SHELL" in *'zsh') SHELL="/bin/sh";; esac
case "$1" in
check-update) shift; systemctl_check_update;;
fetch) shift; systemctl_fetch "$@";;
link) shift; systemctl_link "$@";;
install) shift; systemctl_install "$@";;
uninstall) shift; systemctl_uninstall "$@";;
fetch-user) shift; PREFIX=$HOME $SHELL "$0" fetch;;
fetch-sys) shift; PREFIX=/usr/local $SHELL "$0" fetch;;
link-user) shift; PREFIX=$HOME $SHELL "$0" link;;
install-user) shift; PREFIX=$HOME $SHELL "$0" install;;
install-sys) shift; PREFIX=/usr/local $SHELL "$0" install;;
uninstall-user) shift; PREFIX=$HOME $SHELL "$0" uninstall;;
uninstall-sys) shift; PREFIX=/usr/local $SHELL "$0" uninstall;;
*) usage;;
esac
}
main "$@"