-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconfig.nims
126 lines (106 loc) · 4.48 KB
/
config.nims
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
import strformat
import strutils
import os
proc compile(release: bool) =
var args: seq[string]
args.add(&"--cincludes:{thisDir()}/src/extern/headers")
args.add(&"--path:{thisDir()}/src/extern/libraries")
args.add(&"--passC:-f")
args.add(&"--mm:arc")
args.add(&"--threads:on")
args.add(&"--panics:on")
if release:
args.add(&"--checks:off")
args.add(&"--verbosity:0")
args.add(&"-d:danger")
args.add(&"--opt:speed")
args.add(&"-d:strip")
args.add(&"--outdir:{thisDir()}/bin")
args.add(&"{thisDir()}/src/catnap.nim")
exec("nim c " & args.join(" "))
proc configure() =
var configpath = ""
# Use XDG_CONFIG_HOME only if it is defined. Else use ~/.confg
let XDG_CONFIG_HOME = getEnv("XDG_CONFIG_HOME")
if XDG_CONFIG_HOME == "":
configpath = getEnv("HOME") & "/.config/catnap/"
else:
configpath = XDG_CONFIG_HOME & "/catnap/"
echo "Creating " & configpath
if dirExists(configpath):
echo "Configuration directory already exists, skipping..."
else:
mkdir(configpath)
echo "Creating " & configpath & "config.toml"
if fileExists(configpath & "config.toml"):
echo "Configuration file already exists, skipping..."
else:
cpFile(thisDir() & "/config/config.toml", configpath & "config.toml")
echo "Creating " & configpath & "distros.toml"
if fileExists(configpath & "distros.toml"):
echo "Distro art file already exists, skipping..."
else:
cpFile(thisDir() & "/config/distros.toml", configpath & "distros.toml")
task clean, "Cleans existing build":
echo "\e[36;1mCleaning\e[0;0m existing build"
rmFile("{thisDir()}/bin/catnap")
task release, "Builds the project in release mode":
cleanTask()
echo "\e[36;1mBuilding\e[0;0m in release mode"
exec &"./scripts/git-commit-id.sh"
compile(true)
task debug, "Builds the project in debug mode":
cleanTask()
echo "\e[36;1mBuilding\e[0;0m in debug mode"
exec &"./scripts/git-commit-id.sh"
compile(false)
task install_cfg, "Installs the config files":
echo "\e[36;1mInstalling\e[0;0m config files"
configure()
task install_bin, "Installs the bin file and man page:":
echo "\e[36;1mInstalling\e[0;0m bin file"
echo &"Copying {thisDir()}/bin/catnap to /usr/local/bin"
if defined(linux):
exec &"sudo install -Dm755 {thisDir()}/bin/catnap /usr/local/bin/catnap"
else:
exec &"sudo mkdir -p /usr/local/bin && sudo install -m755 {thisDir()}/bin/catnap /usr/local/bin/catnap"
let
man_1_path = "/usr/share/man/man1/catnap.1.gz"
local_1_path = &"{thisDir()}/docs/catnap.1"
man_5_path = "/usr/share/man/man5/catnap.5.gz"
local_5_path = &"{thisDir()}/docs/catnap.5"
# Install man page only if it
echo &"\e[36;1mInstalling\e[0;0m man page"
# Create .gz file
exec &"gzip -kf {local_1_path}"
exec &"gzip -kf {local_5_path}"
# If man page dose not exist or there is a new version, install the new man page
if not fileExists(man_1_path) or readFile(local_1_path & ".gz") != readFile(man_1_path):
echo &"Copying {local_1_path} to /usr/share/man/man1"
if defined(linux):
exec &"sudo install -Dm755 {local_1_path}.gz /usr/share/man/man1/catnap.1.gz"
else:
exec &"sudo mkdir -p /usr/local/share/man/man1 && sudo install -m755 {local_1_path}.gz /usr/local/share/man/man1/catnap.1.gz"
else:
echo &"Copying {local_1_path} to /usr/share/man/man1 - SKIPPED"
if not fileExists(man_5_path) or readFile(local_5_path & ".gz") != readFile(man_5_path):
echo &"Copying {local_5_path} to /usr/share/man/man5"
if defined(linux):
exec &"sudo install -Dm755 {local_5_path}.gz /usr/share/man/man5/catnap.5.gz"
else:
exec &"sudo mkdir -p /usr/local/share/man/man5 && sudo install -m755 {local_5_path}.gz /usr/local/share/man/man5/catnap.5.gz"
else:
echo &"Copying {local_5_path} to /usr/share/man/man5 - SKIPPED"
task uninstall, "Uninstalls the bin file and man page:":
echo "\e[36;1mUninstalling\e[0;0m bin file"
exec &"sudo rm /usr/local/bin/catnap"
echo "\e[36;1mUninstalling\e[0;0m man page"
exec &"sudo rm /usr/share/man/man1/catnap.1.gz"
exec &"sudo rm /usr/share/man/man5/catnap.5.gz"
task install, "'release', 'install_linux' and 'install_cfg'":
releaseTask()
install_cfgTask()
install_binTask()
task setup, "'release' and 'install_cfg'":
releaseTask()
install_cfgTask()