filesystem: Move post-install code to some files. Add pacman post install tasks.

This commit is contained in:
Alexpux 2014-09-30 00:58:40 +04:00
parent b436fb2668
commit a20fb2ba46
8 changed files with 315 additions and 292 deletions

View File

@ -0,0 +1,96 @@
maybe_create_devs ()
{
local DEVDIR=/dev
# Check for ${DEVDIR} directory
if [ -e "${DEVDIR}" -a ! -d "${DEVDIR}" ]
then
# No mercy. Try to remove.
rm -f "${DEVDIR}"
if [ -e "${DEVDIR}" -a ! -d "${DEVDIR}" ]
then
echo
echo "${DEVDIR} is existant but not a directory."
echo "Please fix that manually, otherwise you WILL get problems."
echo
exit 1
fi
fi
# Create it if necessary
mkdir -m 755 "${DEVDIR}" 2> /dev/null
if [ ! -e "${DEVDIR}" ]
then
echo
echo "Creating ${DEVDIR} directory failed."
echo "Please fix that manually, otherwise you WILL get problems."
echo
exit 1
fi
# Check for ${DEVDIR}/shm directory (for POSIX semaphores and POSIX shared mem)
if [ -e "${DEVDIR}/shm" -a ! -d "${DEVDIR}/shm" ]
then
# No mercy. Try to remove.
rm -f "${DEVDIR}/shm"
if [ -e "${DEVDIR}/shm" -a ! -d "${DEVDIR}/shm" ]
then
echo
echo "${DEVDIR}/shm is existant but not a directory."
echo "POSIX semaphores and POSIX shared memory will not work"
echo
fi
fi
# Create it if necessary
if [ ! -e "${DEVDIR}/shm" ]
then
mkdir -m 1777 "${DEVDIR}/shm"
if [ ! -e "${DEVDIR}/shm" ]
then
echo
echo "Creating ${DEVDIR}/shm directory failed."
echo "POSIX semaphores and POSIX shared memory will not work"
echo
fi
else
chmod 1777 "${DEVDIR}/shm"
fi
# Check for ${DEVDIR}/mqueue directory (for POSIX message queues)
if [ -e "${DEVDIR}/mqueue" -a ! -d "${DEVDIR}/mqueue" ]
then
# No mercy. Try to remove.
rm -f "${DEVDIR}/mqueue"
if [ -e "${DEVDIR}/mqueue" -a ! -d "${DEVDIR}/mqueue" ]
then
echo
echo "${DEVDIR}/mqueue is existant but not a directory."
echo "POSIX message queues will not work"
echo
fi
fi
# Create it if necessary
if [ ! -e "${DEVDIR}/mqueue" ]
then
mkdir -m 1777 "${DEVDIR}/mqueue"
if [ ! -e "${DEVDIR}/mqueue" ]
then
echo
echo "Creating ${DEVDIR}/mqueue directory failed."
echo "POSIX message queues will not work"
echo
fi
else
chmod 1777 "${DEVDIR}/mqueue"
fi
# Install /dev/fd, /dev/std{in,out,err}. The bash builtin test was compiled
# to assume these exist, so use /bin/test to really check.
/usr/bin/test -h /dev/stdin || ln -sf /proc/self/fd/0 /dev/stdin
/usr/bin/test -h /dev/stdout || ln -sf /proc/self/fd/1 /dev/stdout
/usr/bin/test -h /dev/stderr || ln -sf /proc/self/fd/2 /dev/stderr
/usr/bin/test -h /dev/fd || ln -sf /proc/self/fd /dev/fd
}
maybe_create_devs

65
filesystem/02-fstab.post Normal file
View File

@ -0,0 +1,65 @@
maybe_create_fstab ()
{
local FSTAB="${SYSCONFDIR}/fstab"
local FSTABDIR="${SYSCONFDIR}/fstab.d"
# Create fstab file if it doesn't exist.
if [ -e "${FSTAB}" -a ! -f "${FSTAB}" ]
then
# Try to move
mv -f "${FSTAB}" "${FSTAB}.orig"
if [ -e "${FSTAB}" -a ! -f "${FSTAB}" ]
then
echo
echo "${FSTAB} is existant but not a file."
echo "Since this file is specifying the mount points, this might"
echo "result in unexpected trouble. Please fix that manually."
echo
fi
fi
if [ ! -e "${FSTAB}" ]
then
# Create fstab default header
cat > ${FSTAB} << EOF
# For a description of the file format, see the Users Guide
# http://cygwin.com/cygwin-ug-net/using.html#mount-table
# DO NOT REMOVE NEXT LINE. It remove cygdrive prefix from path
none / cygdrive binary,posix=0,noacl,user 0 0
EOF
MAYBE_FIRST_START=true
fi
# Check for ${FSTABDIR} directory
if [ -e "${FSTABDIR}" -a ! -d "${FSTABDIR}" ]
then
# No mercy. Try to remove.
rm -f "${FSTABDIR}"
if [ -e "${FSTABDIR}" -a ! -d "${FSTABDIR}" ]
then
echo
echo "${FSTABDIR} is existant but not a directory."
echo "Please fix that manually."
echo
exit 1
fi
fi
# Create it if necessary
if [ ! -e "${FSTABDIR}" ]
then
mkdir -m 1777 "${FSTABDIR}"
if [ ! -e "${FSTABDIR}" ]
then
echo
echo "Creating ${FSTABDIR} directory failed."
echo "Please fix that manually."
echo
exit 1
fi
fi
}
maybe_create_fstab

8
filesystem/03-mtab.post Normal file
View File

@ -0,0 +1,8 @@
maybe_create_mtab ()
{
local MTAB="${SYSCONFDIR}/mtab"
# Create /etc/mtab as symlink to /proc/mounts
[ ! -L "${MTAB}" ] && ln -sf /proc/mounts ${MTAB}
}
maybe_create_mtab

33
filesystem/04-passwd.post Normal file
View File

@ -0,0 +1,33 @@
maybe_create_passwd ()
{
# Create default /etc/passwd and /etc/group files
local created_passwd=no
local created_group=no
if [ ! -e /etc/passwd -a ! -L /etc/passwd ] ; then
mkpasswd.exe -l -c > /etc/passwd
chmod 644 /etc/passwd
created_passwd=yes
MAYBE_FIRST_START=true
fi
if [ ! -e /etc/group -a ! -L /etc/group ] ; then
mkgroup.exe -l -c > /etc/group
chmod 644 /etc/group
created_group=yes
MAYBE_FIRST_START=true
fi
cp -fp /etc/group /tmp/group.mkgroup && \
( [ -w /etc/group ] || chmod --silent a+w /etc/group ; ) && \
echo "root:S-1-5-32-544:0:" > /etc/group && \
sed -e '/root:S-1-5-32-544:0:/d' /tmp/group.mkgroup >> /etc/group && \
chmod --silent --reference=/etc/passwd /etc/group
rm -f /tmp/group.mkgroup
# Deferred to be sure root group entry exists
[ "$created_passwd" = "yes" ] && chgrp --silent root /etc/passwd
[ "$created_group" = "yes" ] && chgrp --silent root /etc/group
}
maybe_create_passwd

View File

@ -0,0 +1,54 @@
maybe_create_home ()
{
# Set the user id
USER="$(id -un)"
# Default to removing the write permission for group and other
# (files normally created with mode 777 become 755; files created with
# mode 666 become 644)
umask 022
# Here is how HOME is set, in order of priority, when starting from Windows
# 1) From existing HOME in the Windows environment, translated to a Posix path
# 2) from /etc/passwd, if there is an entry with a non empty directory field
# 3) from HOMEDRIVE/HOMEPATH
# 4) / (root)
# If the home directory doesn't exist, create it.
if [ ! -d "${HOME}" ]; then
if mkdir -p "${HOME}"; then
echo "Copying skeleton files."
echo "These files are for the users to personalise their msys2 experience."
echo
echo "They will never be overwritten nor automatically updated."
echo
cd /etc/skel || echo "WARNING: Failed attempt to cd into /etc/skel!"
local f=
/usr/bin/find . -type f | while read f; do
local fDest=${f#.}
if [ ! -e "${HOME}${fDest}" -a ! -L "${HOME}${fDest}" ]; then
/usr/bin/install -D -p -v "${f}" "${HOME}/${fDest}"
fi
done
else
echo "${HOME} could not be created."
{ [ -d "${TEMP}" ] && HOME="${TEMP}"; } ||
{ [ -d "${TMP}" ] && HOME="${TMP}"; } ||
{ [ -d /tmp ] && HOME=/tmp; } ||
HOME=/
echo "Setting HOME to ${HOME}."
fi
fi
# Start MSYS in selected folder
# c:\msys\usr\bin\bash -c "cd '%curdir'; export
# CHERE_INVOKING=1; exec /usr/bin/bash --login -i"
#
# Make sure we start in home unless invoked by CHERE
if [ ! -z "${CHERE_INVOKING}" ]; then
unset CHERE_INVOKING
else
cd "${HOME}" || echo "WARNING: Failed attempt to cd into ${HOME}!"
fi
}
maybe_create_home

View File

@ -0,0 +1,27 @@
maybe_create_winetc ()
{
local FILES="hosts protocols services networks"
local WINSYS32HOME="$(/usr/bin/cygpath -S -w)"
local WINETC="${WINSYS32HOME}\\drivers\\etc"
if [ ! -d "${WINETC}" ]; then
echo "Directory ${WINETC} does not exist; exiting" >&2
echo "If directory name is garbage you need to update your msys package" >&2
exit 1
fi
local mketc=
for mketc in ${FILES}
do
if [ ! -e "/etc/${mketc}" -a ! -L "/etc/${mketc}" ]
then
# Windows only uses the first 8 characters
local WFILE="${WINETC}\\$(expr substr "${mketc}" 1 8)"
/usr/bin/cp -p -v "${WFILE}" "/etc/${mketc}"
fi
done
/usr/bin/chmod 1777 /tmp 2>/dev/null
}
maybe_create_winetc

View File

@ -2,7 +2,7 @@
pkgname=filesystem
pkgver=2014.09
pkgrel=1
pkgrel=2
pkgdesc='Base filesystem'
arch=('i686' 'x86_64')
license=('GPL')
@ -32,7 +32,13 @@ source=('bash.bash_logout'
'profile.tzset.sh'
'regen-info.sh'
'shells'
'start')
'start'
01-devices.post
02-fstab.post
03-mtab.post
04-passwd.post
05-home-dir.post
06-windows-files.post)
md5sums=('3b95f37af49beb642c8fe174dd1f63fc'
'b5596462c700d433ac187260d96de22b'
'9ffd57721725e961ffd5e311d6c2f374'
@ -48,12 +54,18 @@ md5sums=('3b95f37af49beb642c8fe174dd1f63fc'
'd0fd81bd0300bf47cbcb8e5892b8136c'
'292ad5cdd78abac9d694cc06819a96fc'
'b316f2870e4acefc09a814e34edf6da5'
'58fd998f90e496f4dc7d9528df52a615'
'd6311038a296fdca01a9b778a95d89da'
'118fa00617d4d0b2eb337dd565d44494'
'39c1d2412eb62864c8c07cb2557c7da3'
'3b6753667b61800db1a30c614efd1ee1'
'bb51026508581e55bbefe36e2b799108'
'900c95162b9c3f7a29912408e0579852')
'900c95162b9c3f7a29912408e0579852'
'7df6a2d0c05e49bf9224fdfbc240a730'
'92143d4dc539ee6344c81489b640a90c'
'c3c57aa78cdb6cd5dea1e51b12cdbc1d'
'619c7a402a7590e0f7aac994f3c15e54'
'b80fcdfaa3942a09d473286b8397114c'
'fef301aa9d3357ca034fbb3adf77f0f0')
build() {
cd ${srcdir}
@ -72,10 +84,14 @@ package() {
mkdir -p tmp
# setup /etc
install -d etc/{fstab.d,skel,profile.d}
install -d etc/{fstab.d,skel,profile.d,post-install}
for f in bash.bashrc bash.bash_logout fstab shells profile; do
install -m644 ${srcdir}/${f} etc/
done
for f in ${srcdir}/*.post; do
install -m644 ${f} etc/post-install/
done
# user configuration file skeletons
install -m755 ${srcdir}/dot.bashrc etc/skel/.bashrc

View File

@ -84,293 +84,6 @@ print_flags ()
(( $1 & 0x0100 )) && echo -n ",notexec"
}
maybe_create_fstab ()
{
local FSTAB="${SYSCONFDIR}/fstab"
local FSTABDIR="${SYSCONFDIR}/fstab.d"
# Create fstab file if it doesn't exist.
if [ -e "${FSTAB}" -a ! -f "${FSTAB}" ]
then
# Try to move
mv -f "${FSTAB}" "${FSTAB}.orig"
if [ -e "${FSTAB}" -a ! -f "${FSTAB}" ]
then
echo
echo "${FSTAB} is existant but not a file."
echo "Since this file is specifying the mount points, this might"
echo "result in unexpected trouble. Please fix that manually."
echo
fi
fi
if [ ! -e "${FSTAB}" ]
then
# Create fstab default header
cat > ${FSTAB} << EOF
# For a description of the file format, see the Users Guide
# http://cygwin.com/cygwin-ug-net/using.html#mount-table
# DO NOT REMOVE NEXT LINE. It remove cygdrive prefix from path
none / cygdrive binary,posix=0,noacl,user 0 0
EOF
MAYBE_FIRST_START=true
fi
# Check for ${FSTABDIR} directory
if [ -e "${FSTABDIR}" -a ! -d "${FSTABDIR}" ]
then
# No mercy. Try to remove.
rm -f "${FSTABDIR}"
if [ -e "${FSTABDIR}" -a ! -d "${FSTABDIR}" ]
then
echo
echo "${FSTABDIR} is existant but not a directory."
echo "Please fix that manually."
echo
exit 1
fi
fi
# Create it if necessary
if [ ! -e "${FSTABDIR}" ]
then
mkdir -m 1777 "${FSTABDIR}"
if [ ! -e "${FSTABDIR}" ]
then
echo
echo "Creating ${FSTABDIR} directory failed."
echo "Please fix that manually."
echo
exit 1
fi
fi
}
maybe_create_mtab ()
{
local MTAB="${SYSCONFDIR}/mtab"
# Create /etc/mtab as symlink to /proc/mounts
[ ! -L "${MTAB}" ] && ln -sf /proc/mounts ${MTAB}
}
maybe_create_devs ()
{
local DEVDIR=/dev
# Check for ${DEVDIR} directory
if [ -e "${DEVDIR}" -a ! -d "${DEVDIR}" ]
then
# No mercy. Try to remove.
rm -f "${DEVDIR}"
if [ -e "${DEVDIR}" -a ! -d "${DEVDIR}" ]
then
echo
echo "${DEVDIR} is existant but not a directory."
echo "Please fix that manually, otherwise you WILL get problems."
echo
exit 1
fi
fi
# Create it if necessary
mkdir -m 755 "${DEVDIR}" 2> /dev/null
if [ ! -e "${DEVDIR}" ]
then
echo
echo "Creating ${DEVDIR} directory failed."
echo "Please fix that manually, otherwise you WILL get problems."
echo
exit 1
fi
# Check for ${DEVDIR}/shm directory (for POSIX semaphores and POSIX shared mem)
if [ -e "${DEVDIR}/shm" -a ! -d "${DEVDIR}/shm" ]
then
# No mercy. Try to remove.
rm -f "${DEVDIR}/shm"
if [ -e "${DEVDIR}/shm" -a ! -d "${DEVDIR}/shm" ]
then
echo
echo "${DEVDIR}/shm is existant but not a directory."
echo "POSIX semaphores and POSIX shared memory will not work"
echo
fi
fi
# Create it if necessary
if [ ! -e "${DEVDIR}/shm" ]
then
mkdir -m 1777 "${DEVDIR}/shm"
if [ ! -e "${DEVDIR}/shm" ]
then
echo
echo "Creating ${DEVDIR}/shm directory failed."
echo "POSIX semaphores and POSIX shared memory will not work"
echo
fi
else
chmod 1777 "${DEVDIR}/shm"
fi
# Check for ${DEVDIR}/mqueue directory (for POSIX message queues)
if [ -e "${DEVDIR}/mqueue" -a ! -d "${DEVDIR}/mqueue" ]
then
# No mercy. Try to remove.
rm -f "${DEVDIR}/mqueue"
if [ -e "${DEVDIR}/mqueue" -a ! -d "${DEVDIR}/mqueue" ]
then
echo
echo "${DEVDIR}/mqueue is existant but not a directory."
echo "POSIX message queues will not work"
echo
fi
fi
# Create it if necessary
if [ ! -e "${DEVDIR}/mqueue" ]
then
mkdir -m 1777 "${DEVDIR}/mqueue"
if [ ! -e "${DEVDIR}/mqueue" ]
then
echo
echo "Creating ${DEVDIR}/mqueue directory failed."
echo "POSIX message queues will not work"
echo
fi
else
chmod 1777 "${DEVDIR}/mqueue"
fi
# Install /dev/fd, /dev/std{in,out,err}. The bash builtin test was compiled
# to assume these exist, so use /bin/test to really check.
/usr/bin/test -h /dev/stdin || ln -sf /proc/self/fd/0 /dev/stdin
/usr/bin/test -h /dev/stdout || ln -sf /proc/self/fd/1 /dev/stdout
/usr/bin/test -h /dev/stderr || ln -sf /proc/self/fd/2 /dev/stderr
/usr/bin/test -h /dev/fd || ln -sf /proc/self/fd /dev/fd
}
maybe_create_passwd ()
{
# Create default /etc/passwd and /etc/group files
local created_passwd=no
local created_group=no
if [ ! -e /etc/passwd -a ! -L /etc/passwd ] ; then
mkpasswd.exe -l -c > /etc/passwd
chmod 644 /etc/passwd
created_passwd=yes
MAYBE_FIRST_START=true
fi
if [ ! -e /etc/group -a ! -L /etc/group ] ; then
mkgroup.exe -l -c > /etc/group
chmod 644 /etc/group
created_group=yes
MAYBE_FIRST_START=true
fi
cp -fp /etc/group /tmp/group.mkgroup && \
( [ -w /etc/group ] || chmod --silent a+w /etc/group ; ) && \
echo "root:S-1-5-32-544:0:" > /etc/group && \
sed -e '/root:S-1-5-32-544:0:/d' /tmp/group.mkgroup >> /etc/group && \
chmod --silent --reference=/etc/passwd /etc/group
rm -f /tmp/group.mkgroup
# Deferred to be sure root group entry exists
[ "$created_passwd" = "yes" ] && chgrp --silent root /etc/passwd
[ "$created_group" = "yes" ] && chgrp --silent root /etc/group
}
maybe_create_winetc ()
{
local FILES="hosts protocols services networks"
local WINSYS32HOME="$(/usr/bin/cygpath -S -w)"
local WINETC="${WINSYS32HOME}\\drivers\\etc"
if [ ! -d "${WINETC}" ]; then
echo "Directory ${WINETC} does not exist; exiting" >&2
echo "If directory name is garbage you need to update your msys package" >&2
exit 1
fi
local mketc=
for mketc in ${FILES}
do
if [ ! -e "/etc/${mketc}" -a ! -L "/etc/${mketc}" ]
then
# Windows only uses the first 8 characters
local WFILE="${WINETC}\\$(expr substr "${mketc}" 1 8)"
/usr/bin/cp -p -v "${WFILE}" "/etc/${mketc}"
fi
done
/usr/bin/chmod 1777 /tmp 2>/dev/null
}
maybe_create_home ()
{
# Set the user id
USER="$(id -un)"
# Default to removing the write permission for group and other
# (files normally created with mode 777 become 755; files created with
# mode 666 become 644)
umask 022
# Here is how HOME is set, in order of priority, when starting from Windows
# 1) From existing HOME in the Windows environment, translated to a Posix path
# 2) from /etc/passwd, if there is an entry with a non empty directory field
# 3) from HOMEDRIVE/HOMEPATH
# 4) / (root)
# If the home directory doesn't exist, create it.
if [ ! -d "${HOME}" ]; then
if mkdir -p "${HOME}"; then
echo "Copying skeleton files."
echo "These files are for the users to personalise their msys2 experience."
echo
echo "They will never be overwritten nor automatically updated."
echo
cd /etc/skel || echo "WARNING: Failed attempt to cd into /etc/skel!"
local f=
/usr/bin/find . -type f | while read f; do
local fDest=${f#.}
if [ ! -e "${HOME}${fDest}" -a ! -L "${HOME}${fDest}" ]; then
/usr/bin/install -D -p -v "${f}" "${HOME}/${fDest}"
fi
done
else
echo "${HOME} could not be created."
{ [ -d "${TEMP}" ] && HOME="${TEMP}"; } ||
{ [ -d "${TMP}" ] && HOME="${TMP}"; } ||
{ [ -d /tmp ] && HOME=/tmp; } ||
HOME=/
echo "Setting HOME to ${HOME}."
fi
fi
# Start MSYS in selected folder
# c:\msys\usr\bin\bash -c "cd '%curdir'; export
# CHERE_INVOKING=1; exec /usr/bin/bash --login -i"
#
# Make sure we start in home unless invoked by CHERE
if [ ! -z "${CHERE_INVOKING}" ]; then
unset CHERE_INVOKING
else
cd "${HOME}" || echo "WARNING: Failed attempt to cd into ${HOME}!"
fi
}
# Call functions
maybe_create_fstab
maybe_create_mtab
maybe_create_devs
maybe_create_passwd
maybe_create_winetc
maybe_create_home
# Shell dependent settings
profile_d ()
{
@ -380,6 +93,10 @@ profile_d ()
done
}
for postinst in $(export LC_COLLATE=C; echo /etc/post-install/*.post); do
[ -e "${postinst}" ] && . "${postinst}"
done
if [ ! "x${BASH_VERSION}" = "x" ]; then
HOSTNAME="$(/usr/bin/hostname)"
profile_d sh
@ -480,6 +197,13 @@ if [ "$MAYBE_FIRST_START" = "true" ]; then
/usr/bin/mkdir -p /etc/xml
/usr/bin/xmlcatalog --noout --create /etc/xml/catalog
fi
if [ ! -d /etc/pacman.d/gnupg ]
then
/usr/bin/pacman-key --init
/usr/bin/pacman-key --populate msys2 || true
/usr/bin/pacman-key --refresh-keys || true
fi
clear
echo