Merge functions back into openwrtBuild and refactor input
This commit is contained in:
55
functions
55
functions
@@ -1,55 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
#####################
|
|
||||||
##### DEFAULTS ######
|
|
||||||
#####################
|
|
||||||
|
|
||||||
declare -x _packages=(
|
|
||||||
"luci" "luci-theme-material" "luci-app-ddns" \
|
|
||||||
"wireguard" "luci-app-wireguard" "luci-app-vpn-policy-routing" \
|
|
||||||
"-dnsmasq" "dnsmasq-full" \
|
|
||||||
"luci-app-upnp" \
|
|
||||||
"nano" "htop")
|
|
||||||
declare -x _builddir
|
|
||||||
_builddir="$(pwd)"
|
|
||||||
declare -x _filesroot="$_builddir/files/"
|
|
||||||
declare -x _ssh_backup="root@192.168.2.1"
|
|
||||||
declare -x _backedup=(
|
|
||||||
'/etc/config/*' \
|
|
||||||
'/etc/dropbear/*')
|
|
||||||
declare -x _debug="false"
|
|
||||||
|
|
||||||
#####################
|
|
||||||
##### FUNCTIONS #####
|
|
||||||
#####################
|
|
||||||
|
|
||||||
runDebug () { [[ "$_debug" == "true" ]] && echo "Running: " "$@" ; }
|
|
||||||
|
|
||||||
|
|
||||||
sshBackup () {
|
|
||||||
|
|
||||||
runDebug "${FUNCNAME[0]}"
|
|
||||||
|
|
||||||
for fd in "${_backedup[@]}"; do
|
|
||||||
_dir="${fd%/*}/"
|
|
||||||
[[ ! -d "$_filesroot$_dir" ]] && mkdir -p "$_filesroot/$_dir"
|
|
||||||
if ! scp -rp "$_ssh_backup:$fd" "$_filesroot/$_dir"; then
|
|
||||||
echo "Did not successfully backup files from --ssh-backup"
|
|
||||||
echo "Exiting now to prevent data loss!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
getOS () {
|
|
||||||
|
|
||||||
runDebug "${FUNCNAME[0]}"
|
|
||||||
|
|
||||||
if [[ -f /etc/os-release ]]; then
|
|
||||||
source /etc/os-release
|
|
||||||
else
|
|
||||||
echo "Cannot detect OS!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
104
openwrtBuild
104
openwrtBuild
@@ -1,21 +1,36 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
source ./functions
|
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
##### DEFAULTS ######
|
##### DEFAULTS ######
|
||||||
#####################
|
#####################
|
||||||
|
|
||||||
|
setDefaults() {
|
||||||
|
|
||||||
|
runDebug "${FUNCNAME[0]}"
|
||||||
|
|
||||||
|
[[ -z $_debug ]] && _debug="true" # Set to true to enable debugging by default
|
||||||
|
[[ -z $_builddir ]] && _builddir="$PWD"
|
||||||
|
[[ -z $_filesroot ]] && _filesroot="$_builddir/files/"
|
||||||
|
|
||||||
|
# Global default packages for all profiles
|
||||||
|
declare -a _packages=("luci" "nano" "htop" "tcpdump" "diffutils")
|
||||||
|
|
||||||
|
# If no profile is specified, use the TP-Link Archer C7 v2
|
||||||
|
[[ -z $_profile ]] && _profile="tplink_archer-c7-v2"
|
||||||
|
|
||||||
|
# PROFILES
|
||||||
# TP-Link Archer C7 v2
|
# TP-Link Archer C7 v2
|
||||||
_version="19.07.2"
|
if [[ "$_profile" == "tplink_archer-c7-v2" ]]; then
|
||||||
_target="ath79/generic"
|
[[ -z $_version ]] && _version="19.07.2"
|
||||||
_profile="tplink_archer-c7-v2"
|
[[ -z $_target ]] && _target="ath79/generic"
|
||||||
|
|
||||||
# Raspberry Pi 4
|
# Raspberry Pi 4
|
||||||
#_version="snapshot"
|
elif [[ "$_profile" == "rpi-4" ]]; then
|
||||||
#_target="brcm2708/bcm2711"
|
[[ -z $_version ]] && _version="snapshot"
|
||||||
#_profile="rpi-4"
|
[[ -z $_target ]] && _target="bcm27xx/bcm2711"
|
||||||
|
packages+=("kmod-usb-net-asix-ax88179" "luci-app-upnp" "luci-app-wireguard" \
|
||||||
_debug="false" # Turn debugging on by default (useful for testing)
|
"luci-app-vpn-policy-routing" "-dnsmasq" "dnsmasq-full")
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
##### FUNCTIONS #####
|
##### FUNCTIONS #####
|
||||||
@@ -30,13 +45,9 @@ buildOpenWRT [[OPTION] [VALUE]]...
|
|||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
--version, -v OPENWRT_VERSION
|
--version, -v OPENWRT_VERSION
|
||||||
Default: 19.07.02
|
|
||||||
--target, -t TARGET
|
--target, -t TARGET
|
||||||
Default: ath79/generic
|
|
||||||
--profile, -p PROFILE
|
--profile, -p PROFILE
|
||||||
Default: tplink_archer-c7-v2
|
|
||||||
--builddir, -b PATH
|
--builddir, -b PATH
|
||||||
Default: Current working directory
|
|
||||||
--ssh-backup SSH path
|
--ssh-backup SSH path
|
||||||
Example: root@192.168.1.1
|
Example: root@192.168.1.1
|
||||||
--debug, -d
|
--debug, -d
|
||||||
@@ -91,20 +102,26 @@ parseInput () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mkDirs () {
|
runDebug () { [[ "$_debug" == "true" ]] && echo "Running: " "$@" ; }
|
||||||
|
|
||||||
runDebug "${FUNCNAME[0]}"
|
|
||||||
|
|
||||||
[[ ! -d "$_builddir/output/sources" ]] && mkdir -p "$_builddir/output/sources"
|
|
||||||
[[ ! -d "$_filesroot" ]] && mkdir -p "$_filesroot"
|
|
||||||
[[ ! -d "$_builddir/bin" ]] && mkdir -p "$_builddir/bin"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
installPrerequisites () {
|
installPrerequisites () {
|
||||||
|
|
||||||
runDebug "${FUNCNAME[0]}"
|
runDebug "${FUNCNAME[0]}"
|
||||||
|
|
||||||
|
getOS () {
|
||||||
|
|
||||||
|
runDebug "${FUNCNAME[0]}"
|
||||||
|
|
||||||
|
if [[ -f /etc/os-release ]]; then
|
||||||
|
source /etc/os-release
|
||||||
|
else
|
||||||
|
echo "Cannot detect OS!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
getOS
|
||||||
|
|
||||||
if [[ "$ID" == "fedora" ]]; then
|
if [[ "$ID" == "fedora" ]]; then
|
||||||
if ! sudo dnf -y install @c-development @development-tools @development-libs zlib-static elfutils-libelf-devel gawk unzip file wget python3 python2 > /dev/null 2>&1; then
|
if ! sudo dnf -y install @c-development @development-tools @development-libs zlib-static elfutils-libelf-devel gawk unzip file wget python3 python2 > /dev/null 2>&1; then
|
||||||
echo "Warning: Problem installing prerequisites"
|
echo "Warning: Problem installing prerequisites"
|
||||||
@@ -131,9 +148,12 @@ acquireImageBuilder () {
|
|||||||
_url="https://downloads.openwrt.org/releases/$_version/targets/$_target/$_filename"
|
_url="https://downloads.openwrt.org/releases/$_version/targets/$_target/$_filename"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f "$_builddir/output/sources/$_filename" ]]; then
|
# Make sources directory if it does not exist
|
||||||
echo "Downloading $_url to $_builddir/output/sources"
|
[[ ! -d "$_builddir/sources" ]] && mkdir -p "$_builddir/sources"
|
||||||
if ! wget -q -P "$_builddir/output/sources" "$_url"; then
|
|
||||||
|
if [[ ! -f "$_builddir/sources/$_filename" ]]; then
|
||||||
|
echo "Downloading $_url to $_builddir/sources"
|
||||||
|
if ! wget -q -P "$_builddir/sources" "$_url"; then
|
||||||
echo "Could not download Image Builder"
|
echo "Could not download Image Builder"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -147,8 +167,8 @@ extractImageBuilder () {
|
|||||||
|
|
||||||
runDebug "${FUNCNAME[0]}"
|
runDebug "${FUNCNAME[0]}"
|
||||||
|
|
||||||
if [[ -f "$_builddir/output/sources/$_filename" ]]; then
|
if [[ -f "$_builddir/sources/$_filename" ]]; then
|
||||||
if ! tar -xf "$_builddir/output/sources/$_filename" -C "$_builddir/output/sources/"; then
|
if ! tar -xf "$_builddir/sources/$_filename" -C "$_builddir/sources/"; then
|
||||||
echo "Extraction failed"
|
echo "Extraction failed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -161,12 +181,16 @@ makeImage () {
|
|||||||
runDebug "${FUNCNAME[0]}"
|
runDebug "${FUNCNAME[0]}"
|
||||||
|
|
||||||
# move to extracted source directory
|
# move to extracted source directory
|
||||||
if ! pushd "$_builddir/output/sources/${_filename%.tar.xz}" > /dev/null 2>&1; then
|
if ! pushd "$_builddir/sources/${_filename%.tar.xz}" > /dev/null 2>&1; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Make bin dir
|
||||||
|
[[ ! -d "$_builddir/bin" ]] && mkdir -p "$_builddir/bin"
|
||||||
|
|
||||||
# build image
|
# build image
|
||||||
if ! make -j4 image BIN_DIR="$_builddir/bin" PROFILE="$_profile" PACKAGES="${_packages[*]}" FILES="$_filesroot"; then
|
if ! make -j4 image BIN_DIR="$_builddir/bin/$_profile/" PROFILE="$_profile" \
|
||||||
|
PACKAGES="${_packages[*]}" FILES="$_filesroot"; then
|
||||||
echo "Make image failed!"
|
echo "Make image failed!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -176,6 +200,26 @@ makeImage () {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#sshBackup () {
|
||||||
|
#
|
||||||
|
# runDebug "${FUNCNAME[0]}"
|
||||||
|
#
|
||||||
|
# # Make files directory if it does not exist
|
||||||
|
# [[ ! -d "$_filesroot" ]] && mkdir -p "$_filesroot"
|
||||||
|
#
|
||||||
|
# for fd in "${_backedup[@]}"; do
|
||||||
|
# _dir="${fd%/*}/"
|
||||||
|
# [[ ! -d "$_filesroot$_dir" ]] && mkdir -p "$_filesroot/$_dir"
|
||||||
|
# if ! scp -rp "$_ssh_backup:$fd" "$_filesroot/$_dir"; then
|
||||||
|
# echo "Did not successfully backup files from --ssh-backup"
|
||||||
|
# echo "Exiting now to prevent data loss!"
|
||||||
|
# exit 1
|
||||||
|
# fi
|
||||||
|
# done
|
||||||
|
#}
|
||||||
|
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
#flashImage () {
|
#flashImage () {
|
||||||
#
|
#
|
||||||
@@ -195,7 +239,7 @@ makeImage () {
|
|||||||
__main () {
|
__main () {
|
||||||
|
|
||||||
parseInput "$@"
|
parseInput "$@"
|
||||||
mkDirs
|
setDefaults
|
||||||
getOS
|
getOS
|
||||||
installPrerequisites
|
installPrerequisites
|
||||||
acquireImageBuilder
|
acquireImageBuilder
|
||||||
|
|||||||
Reference in New Issue
Block a user