init_rootfs.sh 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. if [ -z $1 ];then
  2. echo "kokdizin parametresi eksik!"
  3. exit 1
  4. else
  5. ROOTDIR=$1
  6. fi
  7. [ ! -d $ROOTDIR ] && mkdir -pv $ROOTDIR
  8. mkdir -pv $ROOTDIR/{boot,etc/{opt,sysconfig},home,mnt,opt}
  9. mkdir -pv $ROOTDIR/{media/{floppy,cdrom},srv,var}
  10. install -dv -m 0750 $ROOTDIR/root
  11. install -dv -m 1777 $ROOTDIR/tmp $ROOTDIR/var/tmp
  12. mkdir -pv $ROOTDIR/usr/{,local/}{bin,include,lib,lib/firmware,src}
  13. mkdir -pv $ROOTDIR/usr/{,local/}share/{color,dict,doc,info,locale,man}
  14. mkdir -pv $ROOTDIR/usr/{,local/}share/{misc,terminfo,zoneinfo}
  15. mkdir -pv $ROOTDIR/usr/{,local/}share/man/man{1..8}
  16. ln -sf /usr/bin $ROOTDIR/bin
  17. ln -sf /usr/bin $ROOTDIR/usr/sbin
  18. ln -sf /usr/bin $ROOTDIR/sbin
  19. ln -sf /usr/lib $ROOTDIR/lib
  20. ln -sf /usr/lib $ROOTDIR/lib64
  21. ln -sf /usr/lib $ROOTDIR/usr/lib64
  22. mkdir -pv $ROOTDIR/var/{log,mail,spool}
  23. ln -sv /run $ROOTDIR/var/run
  24. ln -sv /run/lock $ROOTDIR/var/lock
  25. mkdir -pv $ROOTDIR/var/{opt,cache,lib/{color,misc,locate},local}
  26. install -vdm755 $ROOTDIR/usr/lib/pkgconfig
  27. ln -sv /proc/self/mounts $ROOTDIR/etc/mtab
  28. cat > $ROOTDIR/etc/fstab << "EOF"
  29. # Static information about the filesystems.
  30. # See fstab(5) for details.
  31. # <file system> <dir> <type> <options> <dump> <pass>
  32. EOF
  33. cat > $ROOTDIR/etc/issue << "EOF"
  34. Milis Linux \r (\l)
  35. EOF
  36. cat > $ROOTDIR/etc/lsb-release << "EOF"
  37. DISTRIB_ID="Milis Linux"
  38. DISTRIB_RELEASE="2.0"
  39. DISTRIB_CODENAME="HAN"
  40. DISTRIB_DESCRIPTION="Milis Linux Operating System"
  41. EOF
  42. cat > $ROOTDIR/etc/passwd << "EOF"
  43. root:x:0:0:root:/root:/bin/bash
  44. bin:x:1:1:bin:/dev/null:/bin/false
  45. daemon:x:6:6:Daemon User:/dev/null:/bin/false
  46. messagebus:x:18:18:D-Bus Message Daemon User:/var/run/dbus:/bin/false
  47. nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
  48. EOF
  49. cat > $ROOTDIR/etc/shadow << "EOF"
  50. root:JINC7Qk9605P2:17405:0:99999:7:::
  51. bin:x:17367:0:99999:7:::
  52. daemon:x:17367:0:99999:7:::
  53. messagebus:x:17367:0:99999:7:::
  54. nobody:x:17367:0:99999:7:::
  55. EOF
  56. cat > $ROOTDIR/etc/gshadow << "EOF"
  57. root:x::
  58. bin:x::
  59. sys:x::
  60. kmem:x::
  61. tape:x::
  62. tty:x::
  63. daemon:x::
  64. floppy:x::
  65. disk:x::
  66. lp:x::
  67. dialout:x::
  68. audio:x::
  69. video:x::
  70. utmp:x::
  71. usb:x::
  72. cdrom:x::
  73. adm:x::
  74. messagebus:x::
  75. input:x::
  76. mail:x::
  77. kvm:x::
  78. wheel:x::
  79. nogroup:x::
  80. users:x::
  81. EOF
  82. chmod 400 $ROOTDIR/etc/shadow
  83. chmod 400 $ROOTDIR/etc/gshadow
  84. cat > $ROOTDIR/etc/group << "EOF"
  85. root:x:0:
  86. bin:x:1:daemon
  87. sys:x:2:
  88. kmem:x:3:
  89. tape:x:4:
  90. tty:x:5:
  91. daemon:x:6:
  92. floppy:x:7:
  93. disk:x:8:
  94. lp:x:9:
  95. dialout:x:10:
  96. audio:x:11:
  97. video:x:12:
  98. utmp:x:13:
  99. usb:x:14:
  100. cdrom:x:15:
  101. adm:x:16:
  102. messagebus:x:18:
  103. input:x:24:
  104. mail:x:34:
  105. kvm:x:61:
  106. wheel:x:97:
  107. nogroup:x:99:
  108. users:x:999:
  109. EOF
  110. # profil ayarları
  111. cat > $ROOTDIR/etc/profile << "EOF"
  112. # Begin /etc/profile
  113. # Written for Beyond Linux From Scratch forked for Milis Linux
  114. # System wide environment variables and startup programs.
  115. # System wide aliases and functions should go in /etc/bashrc. Personal
  116. # environment variables and startup programs should go into
  117. # ~/.bash_profile. Personal aliases and functions should go into
  118. # ~/.bashrc.
  119. # Functions to help us manage paths. Second argument is the name of the
  120. # path variable to be modified (default: PATH)
  121. pathremove () {
  122. local IFS=':'
  123. local NEWPATH
  124. local DIR
  125. local PATHVARIABLE=${2:-PATH}
  126. for DIR in ${!PATHVARIABLE} ; do
  127. if [ "$DIR" != "$1" ] ; then
  128. NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
  129. fi
  130. done
  131. export $PATHVARIABLE="$NEWPATH"
  132. }
  133. pathprepend () {
  134. pathremove $1 $2
  135. local PATHVARIABLE=${2:-PATH}
  136. export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
  137. }
  138. pathappend () {
  139. pathremove $1 $2
  140. local PATHVARIABLE=${2:-PATH}
  141. export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
  142. }
  143. export -f pathremove pathprepend pathappend
  144. # Set the initial path
  145. export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/milis/bin:/usr/milis/mps/bin
  146. # Setup some environment variables.
  147. export HISTSIZE=1000
  148. export HISTIGNORE="&:[bf]g:exit"
  149. # Set some defaults for graphical systems
  150. export XDG_DATA_DIRS=${XDG_DATA_DIRS:-/usr/share/}
  151. export XDG_CONFIG_DIRS=${XDG_CONFIG_DIRS:-/etc/xdg/}
  152. #export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/tmp/xdg-$USER}
  153. # Setup a red prompt for root and a green one for users.
  154. NORMAL="\[\e[0m\]"
  155. RED="\[\e[1;31m\]"
  156. GREEN="\[\e[1;32m\]"
  157. if [[ $EUID == 0 ]] ; then
  158. PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
  159. else
  160. PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
  161. fi
  162. for script in /etc/profile.d/*.sh ; do
  163. if [ -r $script ] ; then
  164. . $script
  165. fi
  166. done
  167. unset script RED GREEN NORMAL
  168. # End /etc/profile
  169. EOF
  170. mkdir -p $ROOTDIR/etc/profile.d
  171. cat > $ROOTDIR/etc/profile.d/bash_completion.sh << "EOF"
  172. # Begin /etc/profile.d/bash_completion.sh
  173. # Import bash completion scripts
  174. # If the bash-completion package is installed, use its configuration instead
  175. if [ -f /usr/share/bash-completion/bash_completion ]; then
  176. # Check for interactive bash and that we haven't already been sourced.
  177. if [ -n "${BASH_VERSION-}" -a -n "${PS1-}" -a -z "${BASH_COMPLETION_VERSINFO-}" ]; then
  178. # Check for recent enough version of bash.
  179. if [ ${BASH_VERSINFO[0]} -gt 4 ] || \
  180. [ ${BASH_VERSINFO[0]} -eq 4 -a ${BASH_VERSINFO[1]} -ge 1 ]; then
  181. [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] && \
  182. . "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
  183. if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then
  184. # Source completion code.
  185. . /usr/share/bash-completion/bash_completion
  186. fi
  187. fi
  188. fi
  189. else
  190. # bash-completions are not installed, use only bash completion directory
  191. if shopt -q progcomp; then
  192. for script in /etc/bash_completion.d/* ; do
  193. if [ -r $script ] ; then
  194. . $script
  195. fi
  196. done
  197. fi
  198. fi
  199. # End /etc/profile.d/bash_completion.sh
  200. EOF
  201. cat > $ROOTDIR/etc/profile.d/dircolors.sh << "EOF"
  202. # Setup for /bin/ls and /bin/grep to support color, the alias is in /etc/bashrc.
  203. if [ -f "/etc/dircolors" ] ; then
  204. eval $(dircolors -b /etc/dircolors)
  205. fi
  206. if [ -f "$HOME/.dircolors" ] ; then
  207. eval $(dircolors -b $HOME/.dircolors)
  208. fi
  209. alias ls='ls --color=auto'
  210. alias grep='grep --color=auto'
  211. EOF
  212. cat > $ROOTDIR/etc/profile.d/readline.sh << "EOF"
  213. # Setup the INPUTRC environment variable.
  214. if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then
  215. INPUTRC=/etc/inputrc
  216. fi
  217. export INPUTRC
  218. EOF
  219. cat > $ROOTDIR/etc/profile.d/umask.sh << "EOF"
  220. # By default, the umask should be set.
  221. if [ "$(id -gn)" = "$(id -un)" -a $EUID -gt 99 ] ; then
  222. umask 002
  223. else
  224. umask 022
  225. fi
  226. EOF
  227. cat > $ROOTDIR/etc/profile.d/i18n.sh << "EOF"
  228. # Set up i18n variables
  229. export LANG=tr_TR.UTF-8
  230. EOF
  231. # saat ayarları
  232. cat > $ROOTDIR/etc/sysconfig/clock << "EOF"
  233. # Begin /etc/sysconfig/clock
  234. UTC=2
  235. # Set this to any options you might need to give to hwclock,
  236. # such as machine hardware clock type for Alphas.
  237. CLOCKPARAMS=
  238. # End /etc/sysconfig/clock
  239. EOF
  240. # mouse ayarları
  241. cat > $ROOTDIR/etc/sysconfig/mouse << "EOF"
  242. MDEVICE="/dev/input/mice"
  243. PROTOCOL="imps2"
  244. EOF
  245. # ağ ayarları
  246. cat > $ROOTDIR/etc/sysconfig/template.ifconfig.eth0 << "EOF"
  247. ONBOOT=yes
  248. IFACE=eth0
  249. SERVICE=ipv4-static
  250. IP=192.168.1.2
  251. GATEWAY=192.168.1.1
  252. PREFIX=24
  253. BROADCAST=192.168.1.255
  254. EOF
  255. cat > $ROOTDIR/etc/resolv.conf << "EOF"
  256. # Begin /etc/resolv.conf
  257. domain <Your Domain Name>
  258. nameserver <IP address of your primary nameserver>
  259. nameserver <IP address of your secondary nameserver>
  260. # End /etc/resolv.conf
  261. EOF
  262. cat > $ROOTDIR/etc/hosts << "EOF"
  263. # Begin /etc/hosts
  264. 127.0.0.1 localhost
  265. ::1 localhost ip6-localhost ip6-loopback
  266. ff02::1 ip6-allnodes
  267. ff02::2 ip6-allrouters
  268. # End /etc/hosts
  269. EOF
  270. cat > $ROOTDIR/etc/shells << "EOF"
  271. # Begin /etc/shells
  272. /bin/sh
  273. /bin/bash
  274. # End /etc/shells
  275. EOF
  276. echo "milis" > $ROOTDIR/etc/hostname
  277. touch $ROOTDIR/var/log/{btmp,lastlog,faillog,wtmp}
  278. chgrp -v utmp $ROOTDIR/var/log/lastlog
  279. chmod -v 664 $ROOTDIR/var/log/lastlog
  280. chmod -v 600 $ROOTDIR/var/log/btmp
  281. # talimatname yolu
  282. mkdir -p $ROOTDIR/usr/milis/talimatname
  283. # mps
  284. #mkdir -p $ROOTDIR/var/lib/mps/db
  285. #mkdir -p $ROOTDIR/var/log/mps/kur
  286. #mkdir -p $ROOTDIR/var/log/mps/sil