Skip to content

Commit 7eba38e

Browse files
author
Hunter T
committed
Update example code
1 parent 40b5fb8 commit 7eba38e

File tree

2 files changed

+44
-40
lines changed

2 files changed

+44
-40
lines changed

Examples/example-1.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ nadekobot/output/data/xp_template.json"
110110

111111
# Revision number of this script.
112112
# Refer to the 'README' note at the beginning of this file for more information.
113-
export _LINUXAIO_REVISION="34"
113+
export _LINUXAIO_REVISION=36
114114
# The URL to the raw code of a script that is specified by the other scripts.
115115
export _RAW_URL="https://raw.githubusercontent.com/$installer_repo/$installer_branch"
116116

@@ -125,9 +125,8 @@ export _RAW_URL="https://raw.githubusercontent.com/$installer_repo/$installer_br
125125

126126
echo "Downloading the latest installer..."
127127
curl -O "$_RAW_URL"/installer_prep.sh
128-
sudo chmod +x installer_prep.sh \
129-
&& ./installer_prep.sh \
130-
|| exit "$?" # Uses the exit code passed by 'installer_prep.sh'.
128+
sudo chmod +x installer_prep.sh && ./installer_prep.sh
129+
exit "$?" # Uses the exit code passed by 'installer_prep.sh'.
131130

132131

133132
#### End of [ Main ]

Examples/example-2.md

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The code below is from an installer project that can be refered to at this link:
44

55
```bash
66
#!/bin/bash
7+
# shellcheck disable=SC2155
78
#
89
# This script looks at the operating system, architecture, bit type, etc., to determine
910
# whether or not the system is supported by NadekoBot. Once the system is deemed as
@@ -19,26 +20,28 @@ The code below is from an installer project that can be refered to at this link:
1920

2021
# Revision number of 'linuxAIO.sh'.
2122
# Refer to the 'README' note at the beginning of 'linuxAIO.sh' for more information.
22-
current_linuxAIO_revision="34"
23+
current_linuxAIO_revision=36
2324
# Name of the master installer script.
2425
master_installer="nadeko_main_installer.sh"
2526

2627
## Modify output text color.
27-
export _YELLOW=$'\033[1;33m'
28-
export _GREEN=$'\033[0;32m'
29-
export _CYAN=$'\033[0;36m'
30-
export _RED=$'\033[1;31m'
31-
export _NC=$'\033[0m'
32-
export _GREY=$'\033[0;90m'
33-
export _CLRLN=$'\r\033[K'
28+
export _YELLOW="$(printf '\033[1;33m')"
29+
export _GREEN="$(printf '\033[0;32m')"
30+
export _CYAN="$(printf '\033[0;36m')"
31+
export _RED="$(printf '\033[1;31m')"
32+
export _NC="$(printf '\033[0m')"
33+
export _GREY="$(printf '\033[0;90m')"
34+
export _CLRLN="$(printf '\r\033[K')"
3435

3536
## PURPOSE: The '--no-hostname' flag for 'journalctl' only works with systemd 230 and
3637
## later. So if systemd is older than 230, $_NO_HOSTNAME will not be created.
3738
{
38-
journalctl_version=$(journalctl --version)
39-
journalctl_version=${journalctl_version:1:1}
39+
_SYSTEMD_VERSION_TMP=$(systemd --version)
40+
# shellcheck disable=SC2206
41+
_SYSTEMD_VERSION_TMP=($_SYSTEMD_VERSION_TMP)
42+
export _SYSTEMD_VERSION=${_SYSTEMD_VERSION_TMP[1]}
4043

41-
if ((journalctl_version >= 230)); then export _NO_HOSTNAME="--no-hostname"
44+
if ((_SYSTEMD_VERSION >= 230)); then export _NO_HOSTNAME="--no-hostname"
4245
fi
4346
} 2>/dev/null
4447

@@ -75,15 +78,15 @@ detect_sys_info() {
7578
esac
7679
}
7780

78-
# TODO: Add error checking to sed... If they fail, print the tracked variables into
79-
# a new file.
81+
# TODO: Add error checking to sed... If they fail, print the tracked variables into a
82+
# new file.
8083
linuxAIO_update() {
8184
####
8285
# Function Info: Download the latest version of 'linuxAIO.sh' if $_LINUXAIO_REVISION
8386
# and $current_linuxAIO_revision aren't of equal value.
8487
####
8588

86-
echo "${_YELLOW}You are using an older version of 'linuxAIO.sh'$_NC"
89+
echo "${_YELLOW}You are using an older version of 'linuxAIO.sh'${_NC}"
8790
echo "Downloading latest 'linuxAIO.sh'..."
8891

8992
## Only download the newest version of 'linuxAIO.sh'.
@@ -95,7 +98,7 @@ linuxAIO_update() {
9598
curl -O "$_RAW_URL"/linuxAIO.sh \
9699
&& sudo chmod +x linuxAIO.sh
97100
echo "${_CYAN}NOT applying existing configurations to the new 'linuxAIO.sh'..."
98-
echo "${_GREEN}Successfully downloaded the newest version of 'linuxAIO.sh'.$_NC"
101+
echo "${_GREEN}Successfully downloaded the newest version of 'linuxAIO.sh'.${_NC}"
99102
## Download the newest version of 'linuxAIO.sh' and apply existing changes to it.
100103
else
101104
## Save the values of the current Configuration Variables specified in
@@ -127,10 +130,10 @@ linuxAIO_update() {
127130
fi
128131

129132
echo "${_GREEN}Successfully downloaded the newest version of 'linuxAIO.sh'" \
130-
"and applied changes to the newest version of 'linuxAIO.sh'$_NC"
133+
"and applied changes to the newest version of 'linuxAIO.sh'${_NC}"
131134
fi
132135

133-
clean_up "0" "Exiting" "true"
136+
clean_up "0" "Exiting"
134137
}
135138

136139
unsupported() {
@@ -143,7 +146,7 @@ unsupported() {
143146
"for the installation, setup, and/or use of NadekoBot" >&2
144147
echo "${_YELLOW}WARNING: By continuing, you accept that unexpected behaviors" \
145148
"may occur. If you run into any errors or problems with the installation and" \
146-
"use of the NadekoBot, you are on your own.$_NC"
149+
"use of the NadekoBot, you are on your own.${_NC}"
147150
read -rp "Would you like to continue anyways? [y/N] " choice
148151

149152
choice=$(echo "$choice" | tr '[:upper:]' '[:lower:]')
@@ -159,28 +162,28 @@ clean_up() {
159162
# unless the installer is currently running.
160163
#
161164
# Parameters:
162-
# $1 - Exit status code.
163-
# $2 - Output text.
164-
# $3 - Determines if 'Cleaning up...' needs to be printed with a new-line symbol.
165+
# $1 - required
166+
# Exit status code.
167+
# $2 - required
168+
# Output text.
169+
# $3 - optional
170+
# True if 'Cleaning up...' should be printed with two new-line symbols.
165171
####
166172

167173
# Files to be removed.
168-
local installer_files=("installer_prep.sh" "file_backup.sh" "prereqs_installer.sh"
174+
local installer_files=("installer_prep.sh" "file_backup.sh" "prereqs_installer.sh"
169175
"nadeko_latest_installer.sh" "nadeko_runner.sh" "nadeko_main_installer.sh")
170176

171-
if [[ $3 = true ]]; then echo "Cleaning up..."
177+
if [[ $3 = true ]]; then echo -e "\n\nCleaning up..."
172178
else echo -e "\nCleaning up..."
173179
fi
174180

175181
cd "$_WORKING_DIR" || {
176-
echo "${_RED}Failed to move to project root directory$_NC" >&2
182+
echo "${_RED}Failed to move to project root directory${_NC}" >&2
177183
exit 1
178184
}
179185

180186
## Remove 'nadekobot_tmp' if it exists.
181-
## EXPLANATION: 'nadekobot_tmp' contains a newly downloaded version of NadekoBot. If
182-
## the installer is stopped while downloading NadekoBot, this directory
183-
## will remain on the system, if this if statement doesn't exist.
184187
if [[ -d nadekobot_tmp ]]; then rm -rf nadekobot_tmp
185188
fi
186189

@@ -214,11 +217,13 @@ _DOWNLOAD_SCRIPT() {
214217
# permissions.
215218
#
216219
# Parameters:
217-
# $1 - Name of script to download.
218-
# $2 - True if the script shouldn't output text indicating $1 is being downloaded.
220+
# $1 - required
221+
# Name of script to download.
222+
# $2 - optional
223+
# True if the script shouldn't output text indicating $1 is being downloaded.
219224
####
220225

221-
if [[ ! $2 ]]; then echo "Downloading '$1'..."
226+
if [[ $2 = true ]]; then printf "Downloading '%s'..." "$1"
222227
fi
223228
curl -O -s "$_RAW_URL"/"$1"
224229
sudo chmod +x "$1"
@@ -235,8 +240,8 @@ _DOWNLOAD_SCRIPT() {
235240

236241
# Execute when the user uses 'Ctrl + Z', 'Ctrl + C', or otherwise forcefully exits the
237242
# installer.
238-
trap 'clean_up "2" "Exiting" "true"' \
239-
SIGINT SIGTSTP SIGTERM
243+
trap 'clean_up "130" "Exiting" "true"' SIGINT
244+
trap 'clean_up "143" "Exiting" "true"' SIGTERM
240245

241246

242247
#### End of [ Error Traps ]
@@ -248,14 +253,14 @@ trap 'clean_up "2" "Exiting" "true"' \
248253
# revision number.
249254
if [[ $_LINUXAIO_REVISION && $_LINUXAIO_REVISION != "$current_linuxAIO_revision" ]]; then
250255
linuxAIO_update
251-
clean_up "0" "Exiting" "true"
256+
clean_up "0" "Exiting"
252257
fi
253258

254259
# Change the working directory to the location of the executed scrpt.
255-
cd "$(dirname "$0")" || {
260+
cd "${0%/*}" || {
256261
echo "${_RED}Failed to change working directory" >&2
257-
echo "${_CYAN}Change your working directory to that of the executed script$_NC"
258-
clean_up "1" "Exiting" "true"
262+
echo "${_CYAN}Change your working directory to that of the executed script${_NC}"
263+
clean_up "1" "Exiting"
259264
}
260265

261266
export _WORKING_DIR="$PWD"

0 commit comments

Comments
 (0)