Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-07-25 23:44:48 +03:00
1 parent 639362fbf5
commit bdd69f0aad
101 files changed
+22691 -531

No files matched your search

+92 -4
View File
@@ -3,8 +3,11 @@ set -euo pipefail
PROGRAM=${0##*/}
SERVICE_NAME=echoion.service
UPDATER_SERVICE_NAME=echoion-updater.service
UPDATER_TIMER_NAME=echoion-updater.timer
SERVICE_USER=echoion
RECORD_NAME=.echoion-install
JSON_RECORD_NAME=install.json
MANAGED_MARKER=.echoion-managed
die() {
@@ -54,7 +57,11 @@ safe_unit_path() {
[[ $unit == /* && $unit != *'/../'* && $unit != *'/./'* ]] || return 1
case $scope:$unit in
system:/etc/systemd/system/echoion.service) return 0 ;;
system:/etc/systemd/system/echoion-updater.service) return 0 ;;
system:/etc/systemd/system/echoion-updater.timer) return 0 ;;
user:/*/systemd/user/echoion.service) return 0 ;;
user:/*/systemd/user/echoion-updater.service) return 0 ;;
user:/*/systemd/user/echoion-updater.timer) return 0 ;;
*) return 1 ;;
esac
}
@@ -144,8 +151,17 @@ relocatable=0
service_scope=none
service_unit=
service_unit_sha256=
updater_service_unit=
updater_service_unit_sha256=
updater_timer_unit=
updater_timer_unit_sha256=
updater_helper=
updater_helper_sha256=
config_dir=
state_dir=
cache_dir=
logs_dir=
incoming_dir=
mode=
data_layout=
launcher=
@@ -175,8 +191,17 @@ while IFS='=' read -r key value; do
service_scope) service_scope=$value ;;
service_unit) service_unit=$value ;;
service_unit_sha256) service_unit_sha256=$value ;;
updater_service_unit) updater_service_unit=$value ;;
updater_service_unit_sha256) updater_service_unit_sha256=$value ;;
updater_timer_unit) updater_timer_unit=$value ;;
updater_timer_unit_sha256) updater_timer_unit_sha256=$value ;;
updater_helper) updater_helper=$value ;;
updater_helper_sha256) updater_helper_sha256=$value ;;
config_dir) config_dir=$value ;;
state_dir) state_dir=$value ;;
cache_dir) cache_dir=$value ;;
logs_dir) logs_dir=$value ;;
incoming_dir) incoming_dir=$value ;;
mode) mode=$value ;;
data_layout) data_layout=$value ;;
launcher) launcher=$value ;;
@@ -208,10 +233,17 @@ case $relocatable in
1)
[[ $record_prefix == . && $mode == portable && $data_layout == self-contained ]] ||
die "relocatable install record is incomplete or unsafe"
[[ $config_dir == config && $state_dir == data ]] ||
[[ $config_dir == config && ( $state_dir == state || $state_dir == data ) ]] ||
die "relocatable install record has unsafe mutable paths"
config_dir=$prefix/config
state_dir=$prefix/data
state_dir=$prefix/$state_dir
if [[ -n $cache_dir || -n $logs_dir || -n $incoming_dir ]]; then
[[ $cache_dir == cache && $logs_dir == logs && $incoming_dir == incoming ]] ||
die "relocatable install record has unsafe auxiliary paths"
cache_dir=$prefix/cache
logs_dir=$prefix/logs
incoming_dir=$prefix/incoming
fi
;;
*) die "install record has an invalid relocatable value" ;;
esac
@@ -236,6 +268,44 @@ if [[ $service_scope != none ]]; then
[[ -f $service_unit ]] || die "registered service unit is missing: $service_unit"
[[ $(sha256_file "$service_unit") == "$service_unit_sha256" ]] ||
die "service unit was modified; refusing to remove it: $service_unit"
for updater_record in service timer; do
if [[ $updater_record == service ]]; then
updater_unit=$updater_service_unit
updater_hash=$updater_service_unit_sha256
else
updater_unit=$updater_timer_unit
updater_hash=$updater_timer_unit_sha256
fi
if [[ -n $updater_unit || -n $updater_hash ]]; then
[[ -n $updater_unit && -n $updater_hash ]] ||
die "updater $updater_record record is incomplete"
safe_unit_path "$service_scope" "$updater_unit" ||
die "updater $updater_record record has an unsafe unit path"
[[ -f $updater_unit ]] ||
die "registered updater unit is missing: $updater_unit"
[[ $(sha256_file "$updater_unit") == "$updater_hash" ]] ||
die "updater unit was modified; refusing to remove it: $updater_unit"
fi
done
fi
updater_helper_path=
updater_bundle_path=
if [[ -n $updater_helper ]]; then
[[ $updater_helper =~ ^libexec/updater/[A-Za-z0-9][A-Za-z0-9._-]{0,63}/bin/echoion-updater$ &&
$updater_helper_sha256 =~ ^[0-9a-f]{64}$ ]] ||
die "privileged updater helper record is incomplete or unsafe"
updater_helper_path=$prefix/$updater_helper
updater_bundle_path=$prefix/${updater_helper%/bin/echoion-updater}
[[ -d $updater_bundle_path && ! -L $updater_bundle_path ]] ||
die "recorded privileged updater bundle is missing or unsafe: $updater_bundle_path"
[[ -f $updater_helper_path && ! -L $updater_helper_path &&
-x $updater_helper_path ]] ||
die "recorded privileged updater helper is missing or unsafe: $updater_helper_path"
[[ $(sha256_file "$updater_helper_path") == "$updater_helper_sha256" ]] ||
die "privileged updater helper was modified; refusing to remove it: $updater_helper_path"
elif [[ -n $updater_helper_sha256 ]]; then
die "privileged updater helper record is incomplete"
fi
launcher_path=
@@ -279,13 +349,21 @@ if [[ $purge -eq 1 && $created_system_user == 1 ]]; then
fi
if [[ $service_scope != none ]]; then
if ! systemctl_for "$service_scope" disable --now "$SERVICE_NAME"; then
service_names=("$SERVICE_NAME")
[[ -z $updater_timer_unit ]] || service_names+=("$UPDATER_TIMER_NAME")
if [[ -n $updater_service_unit ]] &&
! systemctl_for "$service_scope" stop "$UPDATER_SERVICE_NAME"; then
die "could not stop $UPDATER_SERVICE_NAME; runtime was not removed"
fi
if ! systemctl_for "$service_scope" disable --now "${service_names[@]}"; then
die "could not stop and disable $SERVICE_NAME; runtime was not removed"
fi
fi
rm -f -- "$prefix/current"
rm -rf -- "$prefix/versions"
[[ -z $updater_bundle_path ]] || rm -rf -- "$updater_bundle_path"
rmdir -- "$prefix/libexec/updater" "$prefix/libexec" 2>/dev/null || true
if [[ $purge -eq 1 ]]; then
if [[ $config_dir == "$state_dir" ]]; then
@@ -293,6 +371,14 @@ if [[ $purge -eq 1 ]]; then
else
rm -rf -- "$config_dir" "$state_dir"
fi
if [[ $data_layout == self-contained ]]; then
for auxiliary in "$cache_dir" "$logs_dir" "$incoming_dir"; do
[[ -z $auxiliary || $auxiliary == "$prefix/cache" ||
$auxiliary == "$prefix/logs" || $auxiliary == "$prefix/incoming" ]] ||
die "refusing unsafe self-contained auxiliary path: '$auxiliary'"
[[ -z $auxiliary ]] || rm -rf -- "$auxiliary"
done
fi
fi
if [[ $purge -eq 1 && $created_system_user == 1 && $service_account_present -eq 1 ]]; then
@@ -301,11 +387,13 @@ fi
if [[ $service_scope != none ]]; then
rm -f -- "$service_unit"
[[ -z $updater_service_unit ]] || rm -f -- "$updater_service_unit"
[[ -z $updater_timer_unit ]] || rm -f -- "$updater_timer_unit"
systemctl_for "$service_scope" daemon-reload || warn "systemd daemon-reload failed"
fi
[[ -z $launcher_path ]] || rm -f -- "$launcher_path"
rm -f -- "$record" "$prefix/install.sh" "$prefix/uninstall.sh"
rm -f -- "$record" "$prefix/$JSON_RECORD_NAME" "$prefix/install.sh" "$prefix/uninstall.sh"
rmdir -- "$prefix" 2>/dev/null || true
printf 'Echoion runtime removed from %s.\n' "$prefix"