Skip to content

Commit

Permalink
refactor: introduce helper script, moved functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvinSchiller committed Apr 14, 2024
1 parent eb120f4 commit 888279f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 30 deletions.
17 changes: 17 additions & 0 deletions scripts/helperscripts/inc.helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Reads a textfile and pipes all lines as args to the given command.
# Does filter out comments.
# Arguments:
# 1 : textfile to read
# 2... : command to receive args (e.g. 'echo', 'apt-get -y install', ...)
call_with_args_from_file () {
local package_file="$1"
shift

sed 's|#.*||g' ${package_file} | xargs "$@"
}

# escape relevant chars for strings used in 'sed' commands. implies delimiter char '|'
escape_for_sed() {
local escaped=$(echo "$1" | sed -e 's/[\&'\''|]/\\&/g')
echo "$escaped"
}
13 changes: 1 addition & 12 deletions scripts/helperscripts/setup_autohotspot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@ if [[ "$#" -lt 2 || ( "${AUTOHOTSPOTconfig}" != "NO" && "${AUTOHOTSPOTconfig}" !
exit 1
fi

# Reads a textfile and pipes all lines as args to the given command.
# Does filter out comments.
# Arguments:
# 1 : textfile to read
# 2... : command to receive args (e.g. 'echo', 'apt-get -y install', ...)
call_with_args_from_file () {
local package_file="$1"
shift

sed 's/#.*//g' ${package_file} | xargs "$@"
}

_get_last_ip_segment() {
local ip="$1"
echo $ip | cut -d'.' -f1-3
Expand Down Expand Up @@ -80,6 +68,7 @@ wifi_interface=wlan0
ip_without_last_segment=$(_get_last_ip_segment $AUTOHOTSPOTip)
autohotspot_profile="Phoniebox_Hotspot"

source "${JUKEBOX_HOME_DIR}"/scripts/helperscripts/inc.helper.sh
source "${JUKEBOX_HOME_DIR}"/scripts/helperscripts/inc.networkHelper.sh

_install_autohotspot_dhcpcd() {
Expand Down
19 changes: 1 addition & 18 deletions scripts/installscripts/install-jukebox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@ escape_for_shell() {
echo "$escaped"
}

# escape relevant chars for strings used in 'sed' commands. implies delimiter char '|'
escape_for_sed() {
local escaped=$(echo "$1" | sed -e 's/[\&'\''|]/\\&/g')
echo "$escaped"
}

checkPrerequisite() {
#currently the user 'pi' is mandatory
#https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/1785
Expand Down Expand Up @@ -837,18 +831,6 @@ web_server_config() {
sudo chmod 440 "${sudoers_wwwdata}"
}

# Reads a textfile and pipes all lines as args to the given command.
# Does filter out comments.
# Arguments:
# 1 : textfile to read
# 2... : command to receive args (e.g. 'echo', 'apt-get -y install', ...)
call_with_args_from_file () {
local package_file="$1"
shift

sed 's|#.*||g' ${package_file} | xargs "$@"
}

install_main() {
local jukebox_dir="$1"
local apt_get="sudo apt-get -qq --yes"
Expand Down Expand Up @@ -929,6 +911,7 @@ install_main() {
cd "${HOME_DIR}"
git clone ${GIT_URL} --branch "${GIT_BRANCH}"

source "${jukebox_dir}"/scripts/helperscripts/inc.helper.sh
source "${jukebox_dir}"/scripts/helperscripts/inc.networkHelper.sh


Expand Down

0 comments on commit 888279f

Please sign in to comment.