Commit 1cec1bd6 authored by Claude's avatar Claude 🌴

Merge branch 'prepare_v1.1.0' into 'master'

Prepare v1.1.0

See merge request raspbian/prepare-raspbian-sd!14
parents 293e4ae8 bb1ddfb2
......@@ -3,6 +3,6 @@
*~
/.project
/.settings/
/MYSSH.config
/NOT_IN_GIT/
/SOURCE_ME-test.sh
DISABLED.*
[submodule "config-api"]
path = config-api
url = https://git.cclaude.rocks/bash-apis/config-api.git
[submodule "apis/bash-common-api"]
path = apis/bash-common-api
url = https://git.cclaude.rocks/bash-apis/bash-common-api.git
This diff is collapsed.
......@@ -10,10 +10,10 @@ More details:
* Download image version (optional)
* Initialize SD
* Customize SD
* Set memory split (currently fix to 16)
* Prepare [bcm workspace](https://git.cclaude.rocks/system/bcm-runtime)
* Enable ssh
* Add public keys to `PI_USER_HOME/.ssh/authorized_keys`.
* Set memory split (currently fix to 16)
* Prepare [bcm workspace](https://git.cclaude.rocks/system/bcm-runtime)
* Enable ssh
* Add public keys to `PI_USER_HOME/.ssh/authorized_keys`.
How to clone this repository
......@@ -28,6 +28,7 @@ git submodule init
git submodule update
```
Then run `prepare-raspbian-sd-install`
How to update this repository
============================
......@@ -43,52 +44,69 @@ git submodule update # Update git submodule (if needed)
git status # Show current status
```
Then run `prepare-raspbian-sd-install` again.
Prerequisites
-------------
Others tools (theses tools are already present on Mint and probably on most other Linux)
Installation
------------
Just run :
```bash
sudo apt update && sudo apt install whiptail curl wget -y
# cd PREPARE_RASPBIAN_SD_DIRECTORY
sudo bash prepare-raspbian-sd-install
```
You need a fresh Raspbian image. You can [download image from Raspbian website](https://www.raspberrypi.org/downloads/raspbian/) or use `download-raspbian-image.sh` provided script.
To remove the applications, use:
```bash
sudo bash /usr/local/share/prepare-raspbian-sd/prepare-raspbian-sd-remove
```
Configuration
-------------
Optionally you can add followed lines into your `~/.bashrc`
Optionally you can customize **Prepare Raspbian SD**.
### download-raspbian-image.sh
You have two options to customize default download directory, witch is location where images will be store.
First you can use `prepare-raspbian-sd-config`:
```bash
export RASPBIAN_DEFAULT_DOWNLOAD_IMAGE_DIRECTORY='/path/to/download/directory'
prepare-raspbian-sd-config RASPBIAN_DEFAULT_DOWNLOAD_IMAGE_DIRECTORY "${HOME}/Documents/raspbian-images"
prepare-raspbian-sd-config RASPBIAN_DEFAULT_IMG '/path/to/2018-10-09-raspbian-stretch-lite.img'
prepare-raspbian-sd-config RASPBIAN_DEFAULT_BACKUP_DIRECTORY "${HOME}/Documents"
prepare-raspbian-sd-config RASPBIAN_SSH_CONFIG '/path/to/your-ssh-need.config'
```
### prepare-raspbian-sd.sh
Or you can add followed lines into your `~/.bashrc`:
```bash
export RASPBIAN_DEFAULT_DOWNLOAD_IMAGE_DIRECTORY='/path/to/download/directory'
export RASPBIAN_DEFAULT_IMG='/path/to/2018-10-09-raspbian-stretch-lite.img'
export RASPBIAN_DEFAULT_BACKUP_DIRECTORY="${HOME}/Documents"
export RASPBIAN_SSH_CONFIG='/path/to/your-ssh-need.config'
```
* If `RASPBIAN_DEFAULT_DOWNLOAD_IMAGE_DIRECTORY` not define, commands use your `Download` directory.
* If `RASPBIAN_DEFAULT_BACKUP_DIRECTORY` not define, commands your `Documents` directory.
### Summary
| Variable name | Usage description |
|---------------------------------------------|-------------------------------------------|
| `RASPBIAN_DEFAULT_DOWNLOAD_IMAGE_DIRECTORY` | Required to be able to use `--download` option of **download-raspbian-image.sh** and to use `--put-last-image` option of **prepare-raspbian-sd.sh**. |
| `RASPBIAN_DEFAULT_DOWNLOAD_IMAGE_DIRECTORY` | Nice to have to use `--download` option of **prepare-raspbian-sd-download-image** and to use `--put-last-image` option of **prepare-raspbian-sd**. |
| `RASPBIAN_DEFAULT_IMG` | Required to be able to use `--put-default-image`. Variable must contain full path to your `raspbian-stretch-lite.img` local file. |
| `RASPBIAN_DEFAULT_BACKUP_DIRECTORY` | Required to be able to use `--full-clone`. Variable must contain full path of an existing directory where your SD backups will be stored. |
| `RASPBIAN_SSH_CONFIG` | Required to be able to use `--configure`. Variable must contain full path to a `custom-ssh.config` file. |
### Content of file define by `RASPBIAN_SSH_CONFIG`
This file is compatible with configuration file `SSH.config` describe in [bcm-runtime](https://git.cclaude.rocks/system/bcm-runtime) project.
But the only relevant entry for **prepare-raspbian-sd.sh** is `SSH_AUTHORIZED_KEYS`.
But the only relevant entry for **prepare-raspbian-sd** is `SSH_AUTHORIZED_KEYS`.
* `SSH_AUTHORIZED_KEYS` : each line should contain one public keys you want to add to file `~/.ssh/authorized_keys`.
......@@ -121,7 +139,7 @@ SD must be plug in your computer but **not mounted**.
Download if needed last Raspbian image, then initialize SD using this image.
```bash
prepare-raspbian-sd.sh --put-last-image
prepare-raspbian-sd --put-last-image
```
### Customize SD
......@@ -131,7 +149,7 @@ SD must be plug in your computer and **mounted**.
Then to customize SD. At the end of process card is sync and unmounted.
```bash
prepare-raspbian-sd.sh --configure
prepare-raspbian-sd --configure
```
......
Subproject commit 4a5d5e03510315b38b560041c78b73dd64be21c9
#!/bin/bash -e
# shellcheck disable=SC2034
#
# prepare-raspbian-sd:apis/install-commons.sh
#
#
# Accoring to: http://www.pathname.com/fhs/pub/fhs-2.3.html
#
# Put everything into: /usr/local/share/freebox-tools,
# Ensure /usr/local/share/freebox-tools/*.sh are executables and readonly,
# Add links into: /usr/bin
#
declare -r DATA_DIR='/usr/local/share/prepare-raspbian-sd'
declare -r BIN_DIR='/usr/bin'
declare -r INSTALL_LINKS='
prepare-raspbian-sd-download-image
prepare-raspbian-sd
prepare-raspbian-sd-config
'
declare -r INSTALL_EXE='
bin/prepare-raspbian-sd-download-image
bin/prepare-raspbian-sd
bin/prepare-raspbian-sd-config
prepare-raspbian-sd-install
prepare-raspbian-sd-remove
'
declare -r INSTALL_OTHER='
LICENSE
README.md
apis/bash-common-api/README.md
apis/bash-common-api/bash-common-api.sh
apis/bash-common-api/message-api.sh
apis/install-commons.sh
apis/prepare-raspbian-config-api.sh
'
#!/bin/bash -e
# shellcheck disable=SC2034
#
# prepare-raspbian-sd:apis/prepare-raspbian-config-api.sh
#
declare -gr PREPARE_RASPBIAN_CONFIG="${HOME}/.config/prepare-raspbian-sd"
function prepare_raspbian_config_set {
local varname="$1"
local var_value="$2"
if [ ! -d "${PREPARE_RASPBIAN_CONFIG}" ] ; then
mkdir -vp "${PREPARE_RASPBIAN_CONFIG}"
fi
exit_if_directory_not_exists "${PREPARE_RASPBIAN_CONFIG}"
if [ -n "${var_value}" ] ; then
echo "${var_value}" >"${PREPARE_RASPBIAN_CONFIG}/${varname}" || exit 1
echoinfo "'${varname}' is set to '${var_value}'"
else
rm "${var_value}" || exit 1
echoinfo "'${varname}' is removed."
fi
}
function prepare_raspbian_initialise_if_needed {
local varname="$1"
local default_value="$2"
if ! is_variable_define_and_not_empty_safe "${varname}" ; then
if [ -f "${PREPARE_RASPBIAN_CONFIG}/${varname}" ] ; then
read -r "${varname}" <"${PREPARE_RASPBIAN_CONFIG}/${varname}"
fi
if ! is_variable_define_and_not_empty_safe "${varname}" ; then
if [ -n "${default_value}" ] ; then
echowarn "${varname} is not define" >&2
declare "${varname}"="${default_value}"
echowarn "Use ${varname}=${!varname}" >&2
fi
fi
if is_variable_define_and_not_empty_safe "${varname}" ; then
declare -gr "${varname}"
# shellcheck disable=SC2163
export "${varname}"
fi
fi
}
#!/bin/bash
# shellcheck disable=SC1090
#
# prepare-raspbian-sd: bin/prepare-raspbian-sd.sh
# prepare-raspbian-sd:bin/prepare-raspbian-sd
#
set -u
set -o pipefail
......@@ -9,16 +9,17 @@ set -o pipefail
PROJECT_HOME="$(dirname "$( realpath "$(dirname "$0")" )" )"
declare -gr PROJECT_HOME
CONFIG_API_HOME="${PROJECT_HOME}/config-api"
declare -gr CONFIG_API_HOME
if [ "$( type -t echofatal )" != 'function' ] ; then
source "${CONFIG_API_HOME}/message-api.sh" || exit 1
fi
if [ "$( type -t is_variable_define_and_not_empty_safe )" != 'function' ] ; then
source "${CONFIG_API_HOME}/config-tools-api.sh" || exit 1
if [ -d "${PROJECT_HOME}/apis" ] ; then
declare -r APIS_HOME="${PROJECT_HOME}/apis"
else
declare -r APIS_HOME='/usr/local/share/prepare-raspbian-sd/apis'
fi
declare -r BASH_COMMON_API="${APIS_HOME}/bash-common-api"
source "${BASH_COMMON_API}/bash-common-api.sh" || exit 1
source "${APIS_HOME}/prepare-raspbian-config-api.sh" || exit 1
declare -gr FILES_TO_VERIFY_ON_BOOT_PARTITION='
config.txt
kernel.img
......@@ -105,7 +106,7 @@ function print_variable {
function get_last_img_version {
# shellcheck disable=SC2086
"${PROJECT_HOME}/bin/download-raspbian-image.sh" --unzip --download-to "${download_to}" ${desktop} |
"${PROJECT_HOME}/bin/prepare-raspbian-sd-download-image" --unzip --download-to "${download_to}" ${desktop} |
grep 'LAST_IMG_FILE:' |
cut -d ':' -f2
}
......@@ -564,5 +565,10 @@ function main {
esac
}
prepare_raspbian_initialise_if_needed RASPBIAN_DEFAULT_DOWNLOAD_IMAGE_DIRECTORY "$( xdg-user-dir DOWNLOAD )"
prepare_raspbian_initialise_if_needed RASPBIAN_DEFAULT_IMG ''
prepare_raspbian_initialise_if_needed RASPBIAN_DEFAULT_BACKUP_DIRECTORY "$( xdg-user-dir DOCUMENTS )"
prepare_raspbian_initialise_if_needed RASPBIAN_SSH_CONFIG ''
main "$@"
#!/bin/bash
# shellcheck disable=SC1090
#
# prepare-raspbian-sd:bin/prepare-raspbian-sd-config
#
set -u
set -o pipefail
PROJECT_HOME="$(dirname "$( realpath "$(dirname "$0")" )" )"
declare -gr PROJECT_HOME
if [ -d "${PROJECT_HOME}/apis" ] ; then
declare -r APIS_HOME="${PROJECT_HOME}/apis"
else
declare -r APIS_HOME='/usr/local/share/prepare-raspbian-sd/apis'
fi
declare -r BASH_COMMON_API="${APIS_HOME}/bash-common-api"
source "${BASH_COMMON_API}/bash-common-api.sh" || exit 1
source "${APIS_HOME}/prepare-raspbian-config-api.sh" || exit 1
function main {
local varname="$1"
local varvalue="$2"
case "${varname}" in
'RASPBIAN_DEFAULT_DOWNLOAD_IMAGE_DIRECTORY')
prepare_raspbian_config_set RASPBIAN_DEFAULT_DOWNLOAD_IMAGE_DIRECTORY "${varvalue}"
;;
'RASPBIAN_DEFAULT_IMG')
prepare_raspbian_config_set RASPBIAN_DEFAULT_IMG "${varvalue}"
;;
'RASPBIAN_DEFAULT_BACKUP_DIRECTORY')
prepare_raspbian_config_set RASPBIAN_DEFAULT_BACKUP_DIRECTORY "${varvalue}"
;;
'RASPBIAN_SSH_CONFIG')
prepare_raspbian_config_set RASPBIAN_SSH_CONFIG "${varvalue}"
;;
*)
echofatal "What is '${varname}' ?"
exit 1
esac
}
main "$@"
#!/bin/bash
# shellcheck disable=SC1090
#
# prepare-raspbian-sd: bin/download-raspbian-image.sh
# prepare-raspbian-sd:bin/prepare-raspbian-sd-download-image
#
set -u
set -o pipefail
......@@ -9,16 +8,19 @@ set -o pipefail
PROJECT_HOME="$(dirname "$( realpath "$(dirname "$0")" )" )"
declare -gr PROJECT_HOME
CONFIG_API_HOME="${PROJECT_HOME}/config-api"
declare -gr CONFIG_API_HOME
if [ "$( type -t echofatal )" != 'function' ] ; then
source "${CONFIG_API_HOME}/message-api.sh" || exit 1
fi
if [ "$( type -t is_variable_define_and_not_empty_safe )" != 'function' ] ; then
source "${CONFIG_API_HOME}/config-tools-api.sh" || exit 1
if [ -d "${PROJECT_HOME}/apis" ] ; then
declare -r APIS_HOME="${PROJECT_HOME}/apis"
else
declare -r APIS_HOME='/usr/local/share/prepare-raspbian-sd/apis'
fi
declare -r BASH_COMMON_API="${APIS_HOME}/bash-common-api"
# shellcheck disable=SC1090
source "${BASH_COMMON_API}/bash-common-api.sh" || exit 1
# shellcheck disable=SC1090
source "${APIS_HOME}/prepare-raspbian-config-api.sh" || exit 1
declare -g ZIP_CHECKED='false'
function usage {
......@@ -238,4 +240,5 @@ LAST_IMG_FILE:${EXPECTED_IMG_FILE}
EOF
}
prepare_raspbian_initialise_if_needed RASPBIAN_DEFAULT_DOWNLOAD_IMAGE_DIRECTORY "$( xdg-user-dir DOWNLOAD )"
main "$@"
Subproject commit 642b9303be5ef1ed88957f2825a6466ebaa4aef6
#!/bin/bash -e
#
# freebox-tools:prepare-raspbian-sd-install
#
set -u
set -o pipefail
PROJECT_HOME="$( dirname "$( realpath "$0" )" )"
declare -r PROJECT_HOME
# shellcheck disable=SC1090
source "${PROJECT_HOME}/apis/install-commons.sh" || exit 1
function set_chmod_for_list {
local mode="$1"
local files="$2"
local file=
while read -r file ; do
if [ -n "${file}" ] ; then
chmod -v "${mode}" "${DATA_DIR}/${file}" || exit 1
fi
done <<<"${files}"
}
function set_links {
local files="$1"
local file=
local realfile=
local linkfile=
while read -r file ; do
if [ -n "${file}" ] ; then
realfile="${DATA_DIR}/bin/${file}"
linkfile="${BIN_DIR}/${file}"
if [ -L "${linkfile}" ] ; then
if [ "$( realpath "${linkfile}" )" = "${realfile}" ] ; then
rm -v "${linkfile}"
fi
fi
ln -sv "${realfile}" "${linkfile}" || exit 1
fi
done <<<"${files}"
}
function main {
if [ "${EUID}" -ne 0 ] ; then
echo 'This script must be run as root.' >&2
exit 1
fi
if [ -n "$(which apt-get)" ] ; then
apt-get install -y whiptail curl wget || exit 1
elif [ -n "$(which yum)" ] ; then
yum install -y whiptail curl wget || exit 1
fi
if [ -f "${DATA_DIR}/prepare-raspbian-sd-remove" ] ; then
bash "${DATA_DIR}/prepare-raspbian-sd-remove"
fi
mkdir -pv "${DATA_DIR}" || exit 1
rsync -av --exclude=".*" "${PROJECT_HOME}/"* "${DATA_DIR}" || exit 1
chown -Rv root:root "${DATA_DIR}" || exit 1
set_chmod_for_list 555 "${INSTALL_EXE}"
set_chmod_for_list 444 "${INSTALL_OTHER}"
set_links "${INSTALL_LINKS}"
echo "$( realpath "$0" ) done."
}
main "$@"
#!/bin/bash -e
#
# freebox-tools:prepare-raspbian-sd-remove
#
set -u
set -o pipefail
PROJECT_HOME="$( dirname "$( realpath "$0" )" )"
declare -r PROJECT_HOME
# shellcheck disable=SC1090
source "${PROJECT_HOME}/apis/install-commons.sh" || exit 1
function remove_links {
local files="$1"
local file=
local realfile=
local linkfile=
while read -r file ; do
if [ -n "${file}" ] ; then
realfile="${DATA_DIR}/bin/${file}"
linkfile="${BIN_DIR}/${file}"
if [ -L "${linkfile}" ] ; then
if [ "$( readlink "${linkfile}" )" = "${realfile}" ] ; then
rm -v "${linkfile}"
fi
fi
fi
done <<<"${files}"
}
function main {
local scriptpath=
scriptpath="$( realpath "$0" )"
if [ "${EUID}" -ne 0 ] ; then
echo 'This script must be run as root.' >&2
exit 1
fi
remove_links "${INSTALL_LINKS}"
rm -fvr "${DATA_DIR}" || exit 1
echo "${scriptpath} done."
}
main "$@"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment