Skip to content

Commit

Permalink
refactor: introduce helper script, moved functions
Browse files Browse the repository at this point in the history
moved network setup into install_main
  • Loading branch information
AlvinSchiller committed Apr 14, 2024
1 parent 33aab76 commit 341db96
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 34 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
29 changes: 7 additions & 22 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,10 @@ 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


# some packages are only available on raspberry pi's but not on test docker containers running on x86_64 machines
if [[ $(uname -m) =~ ^armv.+$ ]]; then
call_with_args_from_file "${jukebox_dir}"/packages-raspberrypi.txt ${apt_get} ${allow_downgrades} install
Expand Down Expand Up @@ -1133,6 +1119,9 @@ install_main() {
echo "classic" > "${jukebox_dir}"/settings/edition
fi

wifi_settings "${jukebox_dir}"
autohotspot "${jukebox_dir}"

# / INSTALLATION
#####################################################
}
Expand Down Expand Up @@ -1449,10 +1438,6 @@ main() {
fi
install_main "${JUKEBOX_HOME_DIR}"

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

wifi_settings "${JUKEBOX_HOME_DIR}"
autohotspot "${JUKEBOX_HOME_DIR}"
existing_assets "${JUKEBOX_HOME_DIR}" "${JUKEBOX_BACKUP_DIR}"
folder_access "${JUKEBOX_HOME_DIR}" "pi:www-data" 775

Expand Down

0 comments on commit 341db96

Please sign in to comment.