diff --git a/README.md b/README.md
index 388bd2c7..0d38dc3f 100644
--- a/README.md
+++ b/README.md
@@ -311,9 +311,9 @@ Restricts Pieman to only creating a chroot environment based on the operating sy
Specifies the locale.
-##### PIEMAN_DIR="$(pwd)"
+##### PIEMAN_DIR="$( dirname "$(readlink -f "$0")" )"
-Specifies the directory into which Pieman is installed.
+Specifies the directory into which Pieman is installed. See [this](https://stackoverflow.com/a/1482133) answer on StackOverflow to know how the default value works.
##### PREPARE_ONLY_TOOLSET=false
diff --git a/bootstrap/15-networking.sh b/bootstrap/15-networking.sh
index 9c07be24..8dfbde18 100644
--- a/bootstrap/15-networking.sh
+++ b/bootstrap/15-networking.sh
@@ -55,10 +55,10 @@ elif is_debian_based; then
fi
fi
-install_readonly files/etc/hostname.template "${ETC}"/hostname
+install_readonly "${PIEMAN_DIR}"/files/etc/hostname.template "${ETC}"/hostname
sed -i "s/{HOSTNAME}/${HOST_NAME}/" "${ETC}/hostname"
-install_readonly files/etc/hosts.template "${ETC}"/hosts
+install_readonly "${PIEMAN_DIR}"/files/etc/hosts.template "${ETC}"/hosts
sed -i "s/{HOSTNAME}/${HOST_NAME}/" "${ETC}/hosts"
render "${PIEMAN_DIR}"/files/network/interfaces.j2 "${ETC}"/network/interfaces
@@ -72,7 +72,7 @@ if ${ENABLE_WIRELESS}; then
wget https://raw.githubusercontent.com/RPi-Distro/firmware-nonfree/86e88fbf0345da49555d0ec34c80b4fbae7d0cd3/brcm/brcmfmac43430-sdio.bin -O "${R}"/lib/firmware/brcm/brcmfmac43430-sdio.bin
wget https://raw.githubusercontent.com/RPi-Distro/firmware-nonfree/86e88fbf0345da49555d0ec34c80b4fbae7d0cd3/brcm/brcmfmac43430-sdio.txt -O "${R}"/lib/firmware/brcm/brcmfmac43430-sdio.txt
- install_readonly files/network/wpa_supplicant.conf "${ETC}"/wpa_supplicant/wpa_supplicant.conf
+ install_readonly "${PIEMAN_DIR}"/files/network/wpa_supplicant.conf "${ETC}"/wpa_supplicant/wpa_supplicant.conf
if [[ -n ${WPA_SSID} ]]; then
do_wpa_passphrase >> "${ETC}"/wpa_supplicant/wpa_supplicant.conf
@@ -87,7 +87,7 @@ if is_alpine; then
info "Adding the networking service to the default runlevel"
chroot_exec rc-update add networking default
- install_exec files/etc/local.d/11-up_eth0.start "${ETC}"/local.d/11-up_eth0.start
+ install_exec "${PIEMAN_DIR}"/files/etc/local.d/11-up_eth0.start "${ETC}"/local.d/11-up_eth0.start
# The networking service should depend on the local service since one of
# the scripts from /etc/local.d raises the network interface.
diff --git a/bootstrap/30-fixes.sh b/bootstrap/30-fixes.sh
index a5a9ba9e..04fa2571 100644
--- a/bootstrap/30-fixes.sh
+++ b/bootstrap/30-fixes.sh
@@ -16,7 +16,7 @@
if is_alpine; then
# For some reason the rw parameter in cmdline.txt is ignored, so the rootfs
# should be remounted at startup.
- install_exec files/etc/local.d/10-remount_root.start "${ETC}"/local.d/10-remount_root.start
+ install_exec "${PIEMAN_DIR}"/files/etc/local.d/10-remount_root.start "${ETC}"/local.d/10-remount_root.start
# Since the system is already installed, the message may confuse users.
sed -i '/You can setup the system/,+1d' "${ETC}/motd"
diff --git a/bootstrap/40-deskop.sh b/bootstrap/40-deskop.sh
index fcc5522b..088f4c4c 100644
--- a/bootstrap/40-deskop.sh
+++ b/bootstrap/40-deskop.sh
@@ -14,9 +14,9 @@
# along with this program. If not, see .
if ${XFCE4}; then
- install_exec files/desktop/06xfce4.desktop "${R}"/usr/share/xsessions/06xfce4.desktop
+ install_exec "${PIEMAN_DIR}"/files/desktop/06xfce4.desktop "${R}"/usr/share/xsessions/06xfce4.desktop
fi
if ${XFCE4}; then
- install_exec files/desktop/lxdm.conf "${R}"/etc/lxdm.conf
+ install_exec "${PIEMAN_DIR}"/files/desktop/lxdm.conf "${R}"/etc/lxdm.conf
fi
\ No newline at end of file
diff --git a/bootstrap/50-firstboot.sh b/bootstrap/50-firstboot.sh
index c13ee0e7..94e6813d 100644
--- a/bootstrap/50-firstboot.sh
+++ b/bootstrap/50-firstboot.sh
@@ -25,7 +25,7 @@ info "Preparing ${FIRSTBOOT}"
touch "${FIRSTBOOT}"
chmod +x "${FIRSTBOOT}"
-for script in files/firstboot/*.sh; do
+for script in "${PIEMAN_DIR}"/files/firstboot/*.sh; do
cat "${script}" >> "${FIRSTBOOT}"
done
diff --git a/pieman.sh b/pieman.sh
index f4c4201a..d05a3968 100755
--- a/pieman.sh
+++ b/pieman.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-# Copyright (C) 2017 Evgeny Golyshev
+# Copyright (C) 2017-2020 Evgeny Golyshev
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -19,7 +19,11 @@ if [ "$(id -u)" -ne "0" ]; then
exit 1
fi
-. ./essentials.sh
+PIEMAN_DIR=${PIEMAN_DIR:=$( dirname "$(readlink -f "$0")" )}
+export PIEMAN_DIR
+
+# shellcheck source=./essentials.sh
+. "${PIEMAN_DIR}"/essentials.sh
set -eE
@@ -102,8 +106,6 @@ def_var OS "raspbian-buster-armhf"
def_protected_var PASSWORD "secret"
-def_var PIEMAN_DIR "$(pwd)"
-
def_bool_var PREPARE_ONLY_TOOLSET false
def_var PYTHON "python3"
@@ -166,7 +168,7 @@ def_private_var REDIS_IS_AVAILABLE true
def_private_var TOOLSET_FULL_PATH "${TOOLSET_DIR}/${TOOLSET_CODENAME}"
-def_private_var SOURCE_DIR "devices/${DEVICE}/${OS}"
+def_private_var SOURCE_DIR "${PIEMAN_DIR}/devices/${DEVICE}/${OS}"
def_private_var YML_FILE "${SOURCE_DIR}/pieman.yml"
@@ -174,11 +176,13 @@ activate_venv_if_exists
check_dependencies
-run_scripts "helpers"
+run_scripts "${PIEMAN_DIR}/helpers"
-. ./mutually_exclusive_params.sh
+# shellcheck source=./mutually_exclusive_params.sh
+. "${PIEMAN_DIR}"/mutually_exclusive_params.sh
-. ./depend_on.sh
+# shellcheck source=./depend_on.sh
+. "${PIEMAN_DIR}"/depend_on.sh
if [[ -n ${WPA_PSK} ]]; then
check_if_wpa_psk_is_valid
@@ -214,7 +218,8 @@ info "checking toolset ${TOOLSET_CODENAME}"
if [ ! -d "${TOOLSET_FULL_PATH}" ]; then
info "building toolset ${TOOLSET_CODENAME} since it does not exist"
fi
-. toolset.sh
+# shellcheck source=./toolset.sh
+. "${PIEMAN_DIR}"/toolset.sh
# shellcheck source=./pieman/pieman/build_status_codes
. "${PIEMAN_DIR}"/pieman/pieman/build_status_codes
@@ -260,7 +265,7 @@ for param in ${params}; do
eval ${param}=true
done
-run_scripts "bootstrap"
+run_scripts "${PIEMAN_DIR}/bootstrap"
umount_required_filesystems