Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to run Pieman from any directory #265

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions bootstrap/15-networking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/30-fixes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/40-deskop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

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
4 changes: 2 additions & 2 deletions bootstrap/50-firstboot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -34,7 +34,7 @@ if is_alpine; then
echo "rm -f /etc/local.d/90-firstboot.start" >> "${ETC}"/local.d/90-firstboot.start
elif is_debian_based; then
install_exec "${FIRSTBOOT}" "${ETC}"/rc.firstboot
install_exec files/etc/rc.local "${ETC}"/rc.local
install_exec "${PIEMAN_DIR}"/files/etc/rc.local "${ETC}"/rc.local

# /etc/rc.firstboot has to destroy itself and its traces after first run.
cat <<EOT >> "${ETC}"/rc.firstboot
Expand Down
4 changes: 2 additions & 2 deletions essentials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ IMAGE_MENDER_ARTIFACT=3
# Returns:
# None
activate_venv_if_exists() {
if [[ -d venv ]] && [[ -f venv/bin/python ]]; then
if [[ -d "${PIEMAN_DIR}"/venv ]] && [[ -f "${PIEMAN_DIR}"/venv/bin/python ]]; then
info "activating the venv virtual environment"
# shellcheck disable=SC1091
source ./venv/bin/activate
source "${PIEMAN_DIR}"/venv/bin/activate
fi
}

Expand Down
4 changes: 2 additions & 2 deletions helpers/others.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ add_option_to_pm_options() {
# Returns:
# None
create_keyring() {
for key in keys/"${PIECES[0]}"/*; do
for key in "${PIEMAN_DIR}"/keys/"${PIECES[0]}"/*; do
gpg --no-default-keyring --keyring="${KEYRING}" --import "${key}"
done
}
Expand All @@ -96,7 +96,7 @@ create_keyring() {
# Returns:
# None
mark_keys_as_trusted() {
for key in keys/"${PIECES[0]}"/*; do
for key in "${PIEMAN_DIR}"/keys/"${PIECES[0]}"/*; do
local key_name=""

key_name=$(basename "${key}")
Expand Down
25 changes: 15 additions & 10 deletions pieman.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (C) 2017 Evgeny Golyshev <eugulixes@gmail.com>
# Copyright (C) 2017-2020 Evgeny Golyshev <eugulixes@gmail.com>
#
# 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
Expand All @@ -19,7 +19,11 @@ if [ "$(id -u)" -ne "0" ]; then
exit 1
fi

. ./essentials.sh
PIEMAN_DIR=${PIEMAN_DIR:=$( dirname "$(readlink -f "$0")" )}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PIEMAN_DIR="$( dirname "$(readlink -f "$0")" )

export PIEMAN_DIR

# shellcheck source=./essentials.sh
. "${PIEMAN_DIR}"/essentials.sh

set -eE

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -166,19 +168,21 @@ 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"

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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -260,7 +265,7 @@ for param in ${params}; do
eval ${param}=true
done

run_scripts "bootstrap"
run_scripts "${PIEMAN_DIR}/bootstrap"

umount_required_filesystems

Expand Down