Guest User

Fedora live

a guest
Jul 2nd, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.96 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. BASEDIR='/home/live/kickstart'
  4.  
  5. lnk=`cat <<-'EOF'
  6. BEGIN {
  7.     FS="";
  8. }
  9.  
  10. {
  11.     s="";
  12.     cnt=0;
  13.     q=0;
  14.     sep=substr($0, 1, 1);
  15.     for (i=1; i<=NF; i++) {
  16.     chr=substr($0, i, 1);
  17.     if (chr==sep) {
  18.         q=1-q;
  19.         cnt++;
  20.     } else {
  21.         if (cnt==3) s=s chr;
  22.     }
  23.     }
  24.     s=s "\n";
  25. }
  26.  
  27. END {
  28.     printf("%s", s);
  29. }
  30. EOF`
  31.  
  32. handle_chown() {
  33.     u="$1"
  34.     g="$2"
  35.     for ((j=0; j<${#user_src[@]}; j++)); do
  36.     if [ x"${user_src[j]}" = x"$u" -o x"${user_src[j]}" = x'*' ]; then
  37.         u="${user_dst[j]}"
  38.         break
  39.     fi
  40.     done
  41.     for ((j=0; j<${#group_src[@]}; j++)); do
  42.     if [ x"${group_src[j]}" = x"$g" -o x"${group_src[j]}" = x'*' ]; then
  43.         g="${group_dst[j]}"
  44.         break
  45.     fi
  46.     done
  47.     echo "${4:-}chown $u:$g '$3'"
  48. }
  49.  
  50. walk() {
  51.     ls -UA1 |\
  52.     while read -r name; do
  53.         read -r perm user group <<<"`stat -c '0%a %U %G' "$name"`"
  54.         if [ -h "$name" ]; then
  55.         target="`stat -c '%N' "$name" | awk "$lnk"`"
  56.         echo "ln -s '$target' '$1/$name'"
  57.         elif cd "$name" &>/dev/null; then
  58.         echo "if [ ! -d '$1/$name' ]; then"
  59.         echo "  mkdir -p '$1/$name'"
  60.         echo "  chmod $perm '$1/$name'"
  61.         handle_chown "$user" "$group" "$1/$name" '  '
  62.         echo "fi"
  63.         walk "$1/$name"
  64.         cd ..
  65.         elif [ -f "$name" ]; then
  66.         echo "base64 -di >'$1/$name' <<'End_Of_File'"
  67.         base64 -w76 <"$name"
  68.         echo 'End_Of_File'
  69.         echo "chmod $perm '$1/$name'"
  70.         handle_chown "$user" "$group" "$1/$name"
  71.         fi
  72.     done
  73. }
  74.  
  75. insert() {
  76.     if [ $# -lt 2 -o $# -gt 3 ]; then
  77.     echo '# Previous line ignored!'
  78.     echo
  79.     return 0
  80.     fi
  81.     unset group_src group_dst user_src user_dst
  82.     if [ $# -eq 3 ]; then
  83.     i=1
  84.     userptr=0
  85.     groupptr=0
  86.     while a="`cut -d, -f$i <<<"$3"`"; [ ! -z "$a" ]; do
  87.         read -r a1 a2 <<<"`sed -r 's/->/ /' <<<"$a"`"
  88.         if [ x"${a1:0:1}" = x':' ]; then
  89.         group_src[groupptr]="${a1:1}"
  90.         group_dst[groupptr++]="${a2:1}"
  91.         else
  92.         user_src[userptr]="$a1"
  93.         user_dst[userptr++]="$a2"
  94.         fi
  95.         ((i++))
  96.     done
  97.     fi
  98.     echo '%post'
  99.     DEST="${2%/}"
  100.     pushd "$1" &>/dev/null
  101.     walk "$DEST"
  102.     popd &>/dev/null
  103.     echo '%end'
  104. }
  105.  
  106. parser() {
  107.     if [ $# -ne 1 ]; then
  108.     echo "Too many or missing '*.kst' files" &>2
  109.     exit 1
  110.     fi
  111.     OUT='live.ks'
  112.     while read -r; do
  113.     echo "$REPLY"
  114.     [ x"$REPLY" = x ] && continue
  115.     [ "${REPLY:0:1}" != '#' ] && continue
  116.     [ ${#REPLY} -eq 1 ] && continue
  117.     case "${REPLY:1:1}" in
  118.         ':')    eval echo \"${REPLY:2}\";;
  119.         '>')    param="`sed -r "s/([^ ]+) +([^ ]+) +([^ ]+)/\1 \2 '\3'/" <<<"${REPLY:2}"`"
  120.             eval insert "$param";;
  121.     esac
  122.     done <"$1" >"$OUT"
  123. }
  124.  
  125. pushd "$BASEDIR" &>/dev/null
  126. rm -Rf rep
  127. cp -a repo rep
  128. createrepo rep
  129. parser *.kst
  130. DISTRIB=`cut -d' ' -f1 /etc/system-release`
  131. RELEASE=`cut -d' ' -f3 /etc/system-release`
  132. su -c  "setenforce 0
  133.     livecd-creator --verbose\
  134.         --config=\"live.ks\"\
  135.         --fslabel=\"$DISTRIB-$RELEASE-live.i686\"\
  136.         --cache=\"/var/cache/live\"
  137.     echo \"Exit code: $?\"
  138.     setenforce 1"
  139. popd &>/dev/null
  140. sync
  141. exit 0
Add Comment
Please, Sign In to add comment