OS: move service scripts into libexec

This commit is contained in:
Pascal Vizeli
2018-11-29 16:01:16 +00:00
parent bc3cc20629
commit ae0a2fe264
12 changed files with 8 additions and 7 deletions

View File

@@ -1,47 +0,0 @@
#!/bin/sh
set -e
# Load configs
CONFIG_FILE=/mnt/data/hassos.json
# Read configs
PROFILES_DIR="$(jq --raw-output '.apparmor // empty' ${CONFIG_FILE})"
if [ -z "${PROFILES_DIR}" ]; then
exit 0
fi
PROFILES_DIR="/mnt/data/${PROFILES_DIR}"
CACHE_DIR="${PROFILES_DIR}/cache"
REMOVE_DIR="${PROFILES_DIR}/remove"
# Check folder structure
mkdir -p ${PROFILES_DIR}
mkdir -p ${CACHE_DIR}
mkdir -p ${REMOVE_DIR}
# Load/Update exists/new profiles
for profile in ${PROFILES_DIR}/*; do
if [ ! -f ${profile} ]; then
continue
fi
# Load Profile
if ! apparmor_parser -r -W -L ${CACHE_DIR} ${profile}; then
echo "[Error]: Can't load profile ${profile}"
fi
done
# Cleanup old profiles
for profile in ${REMOVE_DIR}/*; do
if [ ! -f ${profile} ]; then
continue
fi
# Unload Profile
if apparmor_parser -R -W -L ${CACHE_DIR} ${profile}; then
if rm ${profile}; then
continue
fi
fi
echo "[Error]: Can't remove profile ${profile}"
done

View File

@@ -1,41 +0,0 @@
#!/bin/sh
set -e
DEVICE_CHILD="$(findfs LABEL="hassos-data")"
DEVICE_ROOT="/dev/$(lsblk -no pkname ${DEVICE_CHILD})"
PART_NUM="${DEVICE_CHILD: -1}"
if sfdisk -dq ${DEVICE_ROOT} | grep -q 'label: gpt'; then
# Need resize
if [ $(sgdisk -E ${DEVICE_ROOT}) -le 2048 ]; then
echo "[INFO] No resize of data partition needed"
exit 0
fi
# Resize & Reload partition
echo "[INFO] Update hassos-data partition ${PART_NUM}"
sgdisk -e ${DEVICE_ROOT}
sgdisk -d ${PART_NUM} -n ${PART_NUM}:0:0 -c ${PART_NUM}:"hassos-data" -t ${PART_NUM}:"0FC63DAF-8483-4772-8E79-3D69D8477DE4" -u ${PART_NUM}:"a52a4597-fa3a-4851-aefd-2fbe9f849079" ${DEVICE_ROOT}
sgdisk -v ${DEVICE_ROOT}
else
# Need resize
UNUSED=$(sfdisk -Fq ${DEVICE_ROOT} | cut -d " " -f 3 | tail -1)
if [ -z "${UNUSED}" ] || [ ${UNUSED} -le 2048 ]; then
echo "[INFO] No resize of data partition needed"
exit 0
fi
echo ", +" | sfdisk -N ${PART_NUM} ${DEVICE_ROOT} --force
sfdisk -V ${DEVICE_ROOT}
fi
partx -u ${DEVICE_ROOT}
# Resize filesystem
echo "[INFO] Resize hassos-data filesystem"
e2fsck -y ${DEVICE_CHILD}
resize2fs -f ${DEVICE_CHILD}
echo "[INFO] Finish hassos-data resizing"

View File

@@ -1,21 +0,0 @@
#!/bin/sh
set -e
MACHINE_ID=$(cat /etc/machine-id)
CURRENT_LOGS=/var/log/journal/${MACHINE_ID}
# Loop all logs folder and move
for log_folder in /var/log/journal/*; do
# Not a log folder
if [ ! -d ${log_folder} ]; then
continue
fi
# Current log folder
if (echo ${log_folder} | grep ${MACHINE_ID}); then
continue
fi
rm -rf ${log_folder}
done

View File

@@ -1,27 +0,0 @@
#!/bin/sh
set -e
function mark_good() {
rauc status mark-good
exit 0
}
function mark_bad() {
rauc status mark-bad
systemctl reboot
}
#### Check system ####
# Docker state
if systemctl -q is-failed docker; then
mark_bad
fi
# Docker state
if systemctl -q is-failed hassos-supervisor; then
mark_bad
fi
mark_good

View File

@@ -1,70 +0,0 @@
#!/bin/sh
set -e
#### Options ####
TYPE=""
MOUNT=""
DEVICE=""
SIZE=0
#### Parse arguments ####
while [ "$1" != "" ]; do
key=$1
case $key in
-t|--type)
TYPE=$2
shift
;;
-s|--size)
SIZE=$2
shift
;;
-m|--mount)
MOUNT=$2
shift
;;
*)
echo "[Error] $0 : Argument '$1' unknown"
exit 1
;;
esac
shift
done
# Valide Type
if [ "$TYPE" != "swap" ] && [ "$TYPE" != "fs" ]; then
echo "[Error] Type unknown!"
exit 1
fi
# Lookup device
if [ "$TYPE" = "swap" ]; then
DEVICE="/dev/zram0"
elif [ "$MOUNT" = "var" ]; then
DEVICE="/dev/zram1"
elif [ "$MOUNT" = "tmp" ]; then
DEVICE="/dev/zram2"
else
echo "[Error] No device for lookup!"
exit 1
fi
# Calc 20% of memory for ZRAM swap partition
if [ "$TYPE" = "swap" ] && [ "$SIZE" -eq "0" ]; then
SIZE="$(awk '/MemTotal/{ print $2 * 0.20 }' /proc/meminfo)K"
fi
# Init device
zramctl "$DEVICE" -s "$SIZE" -a lz4
# Swap
if [ "$TYPE" = "swap" ]; then
mkswap -L "hassos-zramswap" "$DEVICE"
fi
# FileSystem
if [ "$TYPE" = "fs" ]; then
mkfs.ext4 -L "hassos-$MOUNT" -O ^has_journal "$DEVICE"
fi