summaryrefslogtreecommitdiffstats
path: root/bin/osib
blob: 89d954f951a1ec02585632f7da1de3b1141d49bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash

ROOT_DIR=$(readlink -f $(dirname $(readlink -f $0))/..)
SELF=$(readlink -f $0)

print_usage() {
  echo "Toolkit for creating systemd based initramfs images (osid)"
  echo "Usage: $(basename $SELF) [OPTIONS] CMD"
  echo "Options:"
  echo -e "  --rebuild-all, -r \t force recreation of build env"
  echo -e "  --rebuild-cpio    \t force recreation of cpio base"
  echo -e "  --rebuild-sqfs    \t force recreation of sqfs base"
  echo -e "  --help, -h        \t print help"
  echo "Commands (CMD):"
  echo -e "  clean          \t clean build dir"
  echo -e "  initramfs      \t create only initramfs"
  echo -e "  iso            \t create iso"
}


rebuild_cpio=0
rebuild_sqfs=0
build_initramfs=0
build_iso=0
clean=0

if [ "x$1" = "x" ]; then
   print_usage
   exit 0
elif [ "x$(whoami)" != "xroot" ]; then
   echo "ERROR: You need root rights to run $SELF."
   echo "       (required for creating dev files)"
   exit 1
fi

while [ "x$1" != "x" ]; do
  arg=$1
  if [ "x$arg" = "x--rebuild-all"  -o "x$arg" = "x-r" ]; then
     rebuild_cpio=1
     rebuild_sqfs=1
  elif [ "x$arg" = "x--rebuild-cpio" ]; then
     rebuild_cpio=1
  elif [ "x$arg" = "x--rebuild-sqfs"  -o "x$arg" = "x-s" ]; then
     rebuild_sqfs=1
  elif [ "x$arg" = "x--help"  -o "x$arg" = "x-h" ]; then
      print_usage
      exit 0
  elif [ "x$arg" = "xiso" ]; then
      build_initramfs=1
      build_iso=1
  elif [ "x$arg" = "xinitramfs" ]; then
      build_initramfs=1
  elif [ "x$arg" = "xclean" ]; then
      clean=1
  else
      echo "ERROR: Unkown argument ($arg)."
      print_usage
      exit 1
  fi
  shift
done

if [ $rebuild_cpio -eq 1 ]; then
    rm -rf ${ROOT_DIR}/build/cpio-base
fi

if [ $rebuild_sqfs -eq 1 ]; then
    rm -rf ${ROOT_DIR}/build/sqfs-base
fi

if [ $clean -eq 1 ]; then
    rm -rf ${ROOT_DIR}/build
fi


if [ $build_initramfs -eq 1 ]; then
    ${ROOT_DIR}/inc/build.initramfs.sh && exit 0
fi

if [ $build_iso -eq 1 ]; then
    ${ROOT_DIR}/inc/build.iso.sh
fi

exit 0