forked from allwincnc/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_cfg.sh
executable file
·133 lines (98 loc) · 3.38 KB
/
install_cfg.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
#!/bin/bash
source tools.sh
# var list
NAME="ARISC configs for the LinuxCNC"
SRC_DIR="linuxcnc/cfg"
DST_DIR="${HOME}/linuxcnc/configs"
ALL_DIRS=("3A_test" "3T_test")
ALL_FILES=("config.hal" "config.ini" "tool.tbl")
DSK_TPL="link.desktop"
DSK_DIR="${HOME}/Desktop"
DSK_CFG_DIR_LINK="${DSK_DIR}/configs"
# greetings
log ""
log "--- Installing **$NAME** -------"
# check folders
if [[ ! -d "${SRC_DIR}" ]]; then
log "!!ERROR!!: Can't find the **./${SRC_DIR}** folder [**${0}:${LINENO}**]."
exit 1
fi
if [[ ! -d "${HOME}/linuxcnc" ]]; then
mkdir "${HOME}/linuxcnc"
fi
if [[ ! -d "${HOME}/linuxcnc" ]]; then
log "!!ERROR!!: Can't create the **${HOME}/linuxcnc** folder [**${0}:${LINENO}**]."
exit 1
fi
if [[ ! -d "${DST_DIR}" ]]; then
mkdir "${DST_DIR}"
fi
if [[ ! -d "${DST_DIR}" ]]; then
log "!!ERROR!!: Can't create the **~/${DST_DIR}** folder [**${0}:${LINENO}**]."
exit 1
fi
if [[ ! -d "${DSK_DIR}" ]]; then
DSK_DIR="${XDG_DESKTOP_DIR}"
fi
# check/copy/process config folders/files
DSK_TPL_FILE="${SRC_DIR}/${DSK_TPL}"
for config in ${ALL_DIRS[*]}; do
SRC_CFG_DIR="${SRC_DIR}/${config}"
DST_CFG_DIR="${DST_DIR}/${config}"
# check folders
if [[ ! -d "${SRC_CFG_DIR}" ]]; then
log "!!ERROR!!: Can't find the **$SRC_CFG_DIR** folder [**${0}:${LINENO}**]."
exit 1
fi
if [[ ! -d "${DST_CFG_DIR}" ]]; then
mkdir "${DST_CFG_DIR}"
fi
if [[ ! -d "${DST_CFG_DIR}" ]]; then
log "!!ERROR!!: Can't create the **$DST_CFG_DIR** folder [**${0}:${LINENO}**]."
exit 1
fi
# check/copy/process config files
for file in ${ALL_FILES[*]}; do
SRC_CFG_FILE="${SRC_CFG_DIR}/${file}"
DST_CFG_FILE="${DST_CFG_DIR}/${file}"
if [[ ! -f "${SRC_CFG_FILE}" ]]; then
log "!!ERROR!!: Can't find the **$SRC_CFG_FILE** file [**${0}:${LINENO}**]."
exit 1
fi
# copy file
cp -f "${SRC_CFG_FILE}" "${DST_CFG_FILE}"
if [[ ! -f "${DST_CFG_FILE}" ]]; then
log "!!ERROR!!: Can't create the **$DST_CFG_FILE** file [**${0}:${LINENO}**]."
exit 1
fi
# process file
sed -i -e "s/__TARGET__/linuxcnc/" "${DST_CFG_FILE}"
sed -i -e "s/__CONFIG__/${config}/" "${DST_CFG_FILE}"
sed -i -e "s/__USER__/$(whoami)/" "${DST_CFG_FILE}"
done
# make a desktop link for this config
if [[ "${DSK_DIR}" && -f "${DSK_TPL_FILE}" ]]; then
DSK_LINK_FILE="${DSK_DIR}/${config}.desktop"
# copy link template
cp -f "${DSK_TPL_FILE}" "${DSK_LINK_FILE}"
if [[ ! -f "${DSK_LINK_FILE}" ]]; then
log "!!ERROR!!: Can't create the **$DSK_LINK_FILE** file [**${0}:${LINENO}**]."
exit 1
fi
chmod +x "${DSK_LINK_FILE}"
# process link file
sed -i -e "s/__TARGET__/linuxcnc/" "${DSK_LINK_FILE}"
sed -i -e "s/__CONFIG__/${config}/" "${DSK_LINK_FILE}"
sed -i -e "s/__USER__/$(whoami)/" "${DSK_LINK_FILE}"
fi
done
# create a desktop link to the configs folder
if [[ ! -L "${DSK_CFG_DIR_LINK}" ]]; then
ln -s -f "${DST_DIR}" "${DSK_CFG_DIR_LINK}"
fi
if [[ ! -L "${DSK_CFG_DIR_LINK}" ]]; then
log "!!ERROR!!: Can't create the **$DSK_CFG_DIR_LINK** link [**${0}:${LINENO}**]."
fi
# success
log "--- **$NAME** ++successfully installed++ -------"
log ""