Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- BASEDIR='/home/live/kickstart'
- lnk=`cat <<-'EOF'
- BEGIN {
- FS="";
- }
- {
- s="";
- cnt=0;
- q=0;
- sep=substr($0, 1, 1);
- for (i=1; i<=NF; i++) {
- chr=substr($0, i, 1);
- if (chr==sep) {
- q=1-q;
- cnt++;
- } else {
- if (cnt==3) s=s chr;
- }
- }
- s=s "\n";
- }
- END {
- printf("%s", s);
- }
- EOF`
- handle_chown() {
- u="$1"
- g="$2"
- for ((j=0; j<${#user_src[@]}; j++)); do
- if [ x"${user_src[j]}" = x"$u" -o x"${user_src[j]}" = x'*' ]; then
- u="${user_dst[j]}"
- break
- fi
- done
- for ((j=0; j<${#group_src[@]}; j++)); do
- if [ x"${group_src[j]}" = x"$g" -o x"${group_src[j]}" = x'*' ]; then
- g="${group_dst[j]}"
- break
- fi
- done
- echo "${4:-}chown $u:$g '$3'"
- }
- walk() {
- ls -UA1 |\
- while read -r name; do
- read -r perm user group <<<"`stat -c '0%a %U %G' "$name"`"
- if [ -h "$name" ]; then
- target="`stat -c '%N' "$name" | awk "$lnk"`"
- echo "ln -s '$target' '$1/$name'"
- elif cd "$name" &>/dev/null; then
- echo "if [ ! -d '$1/$name' ]; then"
- echo " mkdir -p '$1/$name'"
- echo " chmod $perm '$1/$name'"
- handle_chown "$user" "$group" "$1/$name" ' '
- echo "fi"
- walk "$1/$name"
- cd ..
- elif [ -f "$name" ]; then
- echo "base64 -di >'$1/$name' <<'End_Of_File'"
- base64 -w76 <"$name"
- echo 'End_Of_File'
- echo "chmod $perm '$1/$name'"
- handle_chown "$user" "$group" "$1/$name"
- fi
- done
- }
- insert() {
- if [ $# -lt 2 -o $# -gt 3 ]; then
- echo '# Previous line ignored!'
- echo
- return 0
- fi
- unset group_src group_dst user_src user_dst
- if [ $# -eq 3 ]; then
- i=1
- userptr=0
- groupptr=0
- while a="`cut -d, -f$i <<<"$3"`"; [ ! -z "$a" ]; do
- read -r a1 a2 <<<"`sed -r 's/->/ /' <<<"$a"`"
- if [ x"${a1:0:1}" = x':' ]; then
- group_src[groupptr]="${a1:1}"
- group_dst[groupptr++]="${a2:1}"
- else
- user_src[userptr]="$a1"
- user_dst[userptr++]="$a2"
- fi
- ((i++))
- done
- fi
- echo '%post'
- DEST="${2%/}"
- pushd "$1" &>/dev/null
- walk "$DEST"
- popd &>/dev/null
- echo '%end'
- }
- parser() {
- if [ $# -ne 1 ]; then
- echo "Too many or missing '*.kst' files" &>2
- exit 1
- fi
- OUT='live.ks'
- while read -r; do
- echo "$REPLY"
- [ x"$REPLY" = x ] && continue
- [ "${REPLY:0:1}" != '#' ] && continue
- [ ${#REPLY} -eq 1 ] && continue
- case "${REPLY:1:1}" in
- ':') eval echo \"${REPLY:2}\";;
- '>') param="`sed -r "s/([^ ]+) +([^ ]+) +([^ ]+)/\1 \2 '\3'/" <<<"${REPLY:2}"`"
- eval insert "$param";;
- esac
- done <"$1" >"$OUT"
- }
- pushd "$BASEDIR" &>/dev/null
- rm -Rf rep
- cp -a repo rep
- createrepo rep
- parser *.kst
- DISTRIB=`cut -d' ' -f1 /etc/system-release`
- RELEASE=`cut -d' ' -f3 /etc/system-release`
- su -c "setenforce 0
- livecd-creator --verbose\
- --config=\"live.ks\"\
- --fslabel=\"$DISTRIB-$RELEASE-live.i686\"\
- --cache=\"/var/cache/live\"
- echo \"Exit code: $?\"
- setenforce 1"
- popd &>/dev/null
- sync
- exit 0
Add Comment
Please, Sign In to add comment