forked from obel1x/fedora-OEMDRV
9264ca8e92
- Move setup_system.conf.dist to system_setup/config.dist/ and skel.tar.zst.dist + pack_skel.sh to system_setup/skel/; config/ now holds only gitignored local files - Fix configure.sh CONF_DIST path (was pointing at non-existent config/setup_system.conf.dist) - Fix skel/pack_skel.sh: remove vestigial source line whose path was wrong in both old and new location - Update error messages in setup_system.inc.sh and sync_client_software.sh to reference new dist file location - Move machine_uuid reading/writing into setup_system.inc.sh so all scripts have MACHINEID available; setup_system.conf.dist now uses MACHINEID conditionally with a hostname fallback - sync_client_software.sh: fix && / typo (should be && \) that broke the flatpak remote-add → install chain; add network error handling after flatpak install; cleanup upgrade logic and chown placement - Update CLAUDE.md and install.md to reflect new dist file locations Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
189 lines
7.1 KiB
Bash
Executable File
189 lines
7.1 KiB
Bash
Executable File
#!/usr/bin/env sh
|
|
# Includes for System Setup
|
|
#
|
|
# SPDX-FileCopyrightText: Daniel Pätzold
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
#
|
|
# This is not a runnig script-file. No real logic to execute. Its used for includes in other scripts.
|
|
|
|
#Check if we are root
|
|
# Deprectaed - use if Statement itself
|
|
#check_root()
|
|
#{
|
|
# if [ "$EUID" -ne 0 ]; then
|
|
# return 1
|
|
# fi
|
|
# return 0
|
|
#}
|
|
|
|
#First, get the machine_uuid wich is needed by some userspace programs.
|
|
#As all Parameters that are bound to CPU or Mainboard, are only readable by root, we need to get the values at installtime.
|
|
#On old installations without the file, we will write it whenever possible
|
|
if [ -f $( dirname "$0" )/config.d/machine_uuid.sys ]; then
|
|
export MACHINEID="$( cat $( dirname "$0" )/config.d/machine_uuid.sys )"
|
|
elif [ "$EUID" -eq 0 ]; then
|
|
dmidecode -t system | grep -i 'UUID' \
|
|
| sed 's/UUID: //' | tr '[:upper:]' '[:lower:]' \
|
|
| sed 's/[^0-9a-z]*//g' | xargs | tail -c 13 \
|
|
> "$( dirname "$0" )/config.d/machine_uuid.sys"
|
|
export MACHINEID="$( cat $( dirname "$0" )/config.d/machine_uuid.sys )"
|
|
fi
|
|
|
|
#Check for configure.conf - used for frist setup of system
|
|
if [[ -f $(dirname "$0")/../config.d/configure.conf ]]; then
|
|
echo "System in configure-mode. Will use $(dirname "$0")/../config.d/configure.conf for setup."
|
|
source $(dirname "$0")/../config.d/configure.conf
|
|
else
|
|
#Load default system setup file
|
|
if [[ ! -f $(dirname "$0")/../config/setup_system.conf ]]; then
|
|
echo "System configuration not found. Please copy system_setup/config.dist/setup_system.conf.dist to config/setup_system.conf and adjust the settings before running."
|
|
echo "Press any key to continue" && read -n 1 -s -r && exit 1
|
|
fi
|
|
source $(dirname "$0")/../config/setup_system.conf
|
|
|
|
#Parse additional client-configs
|
|
if [[ `ls -1 $(dirname "$0")/../config.d/*.conf 2>/dev/null | wc -l ` -gt 0 ]]; then
|
|
source $(dirname "$0")/../config.d/*.conf
|
|
fi
|
|
fi
|
|
|
|
#Check if the Data- Directory is encrypted
|
|
check_data_isecrypted() {
|
|
CHECKRES=$( cat /etc/mtab | grep "${DECRYPTEDDATADIR}" | grep "fuse.gocryptfs" )
|
|
if [ "${CHECKRES}." == "." ]; then
|
|
return 1 # Error: Directory is not mounted
|
|
else
|
|
return 0 # Directory is mounted
|
|
fi
|
|
}
|
|
|
|
# Functions for logging
|
|
elog_init() {
|
|
#Create a new logfile and put some text in it
|
|
echo $@ | tee ${LOGFILE}
|
|
}
|
|
elog_add() {
|
|
#Append some text to the logile
|
|
echo $@ | tee ${LOGFILE} -a
|
|
}
|
|
elog_add_command() {
|
|
#Run a command, capture output (STD and ERR) to the logfile AND output to screen
|
|
# WILL NOT SET RETTXT to make Output directly to screen
|
|
#Returns the exit value of the command in $? and in RETNO
|
|
$@ 2>&1 | tee -a ${LOGFILE}
|
|
RETNO=$?
|
|
return ${RETNO}
|
|
}
|
|
elog_add_command_subshell() {
|
|
# Special Version of above, where the command will be completely executed in a subshell and then passed to Variable RETTXT. This is needed for some commands, that may output to
|
|
# something else than STD or ERR and otherwise cannot be captured completely.
|
|
# Benefit: Really catch everything that is send to output
|
|
# Disadvantage: Output wont't display directly, but only after finshed execution
|
|
RETTXT=$( { $@ > >(tee -a ${LOGFILE}); } 2> >(tee -a ${LOGFILE}) )
|
|
RETNO=$?
|
|
echo "${RETTXT}"
|
|
return ${RETNO}
|
|
}
|
|
|
|
# Will set variable DAVTOKEN_USER and DAVTOKEN_PASS to the stored value or get a new one
|
|
get_nc_token() {
|
|
export DAVTOKEN_USER=""
|
|
export DAVTOKEN_PASS=""
|
|
|
|
if [ "$EUID" -eq 0 ]; then
|
|
echo "get_nc_token(): Called as superuser, which is denied."
|
|
return 1 # Token for Superuser makes no sense and cannot work
|
|
fi
|
|
|
|
# If Filename is given andf encryption is turned on, than first check for encrypted Directory
|
|
if [ ${IPAVAULTUSE} == "true" ] && [ ! -z ${DAVTOKENFILENAME} ]; then
|
|
check_data_isecrypted
|
|
if [ $? -ne 0 ]; then
|
|
echo "Data Directory is not encrypted. Please mount it first."
|
|
return 1
|
|
fi
|
|
fi
|
|
|
|
if [ ! -f ${DAVTOKENFILENAME} ] || [ -z ${DAVTOKENFILENAME} ]; then
|
|
echo "No token found here. Getting a new WEBDAV Token for this Device."
|
|
echo "Please logon to your Nextcloud instance via SSO/kerberos"
|
|
|
|
# Directory is ok, but no Tokenfile was found, need to generate a new one
|
|
REQJSON=$( curl -s -A "WEBDAV:${HOSTNM}" -X POST "https://${SERVERFQDN_NC}/index.php/login/v2" )
|
|
# echo "JSON is:"
|
|
# echo "${REQJSON}"
|
|
|
|
REQTOKEN=$( echo "${REQJSON}" | grep -oP '(?<="token":")[^"]+(?=")' )
|
|
REQURL=$( echo "${REQJSON}" | grep -oP '(?<="login":")[^"]+(?=")' )
|
|
/usr/bin/firefox "${REQURL}" &
|
|
|
|
for i in {1..200}
|
|
do
|
|
echo "Waiting 6 seconds"
|
|
sleep 6
|
|
echo -n "Poll Number ${i}..."
|
|
POLLJSON=$( curl -s -X POST "https://${SERVERFQDN_NC}/login/v2/poll" -d "token=${REQTOKEN}" )
|
|
if [[ "${POLLJSON}" == *"appPassword"* ]]; then
|
|
if [ ! -z ${DAVTOKENFILENAME} ]; then
|
|
echo "${POLLJSON}" > ${DAVTOKENFILENAME}
|
|
echo "Token has been written to ${DAVTOKENFILENAME}"
|
|
else
|
|
echo "Temporary token was obtained."
|
|
fi
|
|
pkill firefox
|
|
break
|
|
else
|
|
echo "failed"
|
|
fi
|
|
done
|
|
else
|
|
# Tokenfile found, reading it
|
|
POLLJSON=$( cat ${DAVTOKENFILENAME} )
|
|
fi
|
|
export DAVTOKEN_USER=$( echo "${POLLJSON}" | grep -oP '(?<="loginName":")[^"]+(?=")' )
|
|
export DAVTOKEN_PASS=$( echo "${POLLJSON}" | grep -oP '(?<="appPassword":")[^"]+(?=")' )
|
|
}
|
|
|
|
# Custom `select` implementation that allows *empty* input.
|
|
# Pass the choices as individual arguments.
|
|
# Output is the chosen item, or "", if the user just pressed ENTER.
|
|
# Example:
|
|
# choice=$(selectWithDefault 'one' 'two' 'three')
|
|
selectWithDefault() {
|
|
|
|
local item i=0 numItems=$#
|
|
|
|
# Print numbered menu items, based on the arguments passed.
|
|
for item; do # Short for: for item in "$@"; do
|
|
printf '%s\n' "$((++i))) $item"
|
|
done >&2 # Print to stderr, as `select` does.
|
|
|
|
# Prompt the user for the index of the desired item.
|
|
while :; do
|
|
printf %s "${PS3-#? }" >&2 # Print the prompt string to stderr, as `select` does.
|
|
read -r index
|
|
# Make sure that the input is either empty or that a valid index was entered.
|
|
[[ -z $index ]] && break # empty input
|
|
(( index >= 1 && index <= numItems )) 2>/dev/null || { echo "Invalid selection. Please try again." >&2; continue; }
|
|
break
|
|
done
|
|
|
|
# Output the selected item, if any.
|
|
[[ -n $index ]] && printf %s "${@: index:1}"
|
|
|
|
}
|
|
selectExample() {
|
|
# Print the prompt message and call the custom select function.
|
|
echo "Include audits (default is 'Nope')?"
|
|
optionsAudits=('Yep' 'Nope')
|
|
opt=$(selectWithDefault "${optionsAudits[@]}")
|
|
|
|
# Process the selected item.
|
|
case $opt in
|
|
'Yep') includeAudits=true; ;;
|
|
''|'Nope') includeAudits=false; ;; # $opt is '' if the user just pressed ENTER
|
|
esac
|
|
}
|
|
|
|
# This is not a runnig script-file. No Logik to execute. Its used for includes in other scripts.
|