init_rootfs.sh 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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,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/os-release << "EOF"
  43. DISTRIB_ID="Milis Linux"
  44. DISTRIB_RELEASE="2.0"
  45. DISTRIB_CODENAME="HAN"
  46. DISTRIB_DESCRIPTION="Milis Linux Operating System"
  47. EOF
  48. cat > $ROOTDIR/etc/passwd << "EOF"
  49. root:x:0:0:root:/root:/bin/bash
  50. bin:x:1:1:bin:/dev/null:/bin/false
  51. daemon:x:6:6:Daemon User:/dev/null:/bin/false
  52. messagebus:x:18:18:D-Bus Message Daemon User:/var/run/dbus:/bin/false
  53. nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
  54. EOF
  55. cat > $ROOTDIR/etc/shadow << "EOF"
  56. root:JINC7Qk9605P2:17405:0:99999:7:::
  57. bin:x:17367:0:99999:7:::
  58. daemon:x:17367:0:99999:7:::
  59. messagebus:x:17367:0:99999:7:::
  60. nobody:x:17367:0:99999:7:::
  61. EOF
  62. cat > $ROOTDIR/etc/gshadow << "EOF"
  63. root:x::
  64. bin:x::daemon
  65. sys:x::
  66. kmem:x::
  67. tape:x::
  68. tty:x::
  69. daemon:x::
  70. floppy:x::
  71. disk:x::
  72. network:x::
  73. dialout:x::
  74. audio:x::
  75. video:x::
  76. utmp:x::
  77. usb:x::
  78. cdrom:x::
  79. adm:x::
  80. messagebus:x::
  81. input:x::
  82. mail:x::
  83. kvm:x::
  84. wheel:x::
  85. nogroup:x::
  86. users:x::
  87. EOF
  88. chmod 400 $ROOTDIR/etc/shadow
  89. chmod 400 $ROOTDIR/etc/gshadow
  90. cat > $ROOTDIR/etc/group << "EOF"
  91. root:x:0:
  92. bin:x:1:daemon
  93. sys:x:2:
  94. kmem:x:3:
  95. tape:x:4:
  96. tty:x:5:
  97. daemon:x:6:
  98. floppy:x:7:
  99. disk:x:8:
  100. network:x:23:
  101. dialout:x:10:
  102. audio:x:11:
  103. video:x:12:
  104. utmp:x:13:
  105. usb:x:14:
  106. cdrom:x:15:
  107. adm:x:16:
  108. messagebus:x:18:
  109. input:x:24:
  110. mail:x:34:
  111. kvm:x:61:
  112. wheel:x:97:
  113. nogroup:x:99:
  114. users:x:999:
  115. EOF
  116. # profil ayarları
  117. cat > $ROOTDIR/etc/profile << "EOF"
  118. # Begin /etc/profile
  119. # Written for Beyond Linux From Scratch forked for Milis Linux 2.0 2019
  120. # System wide environment variables and startup programs.
  121. # System wide aliases and functions should go in /etc/bashrc. Personal
  122. # environment variables and startup programs should go into
  123. # ~/.bash_profile. Personal aliases and functions should go into
  124. # ~/.bashrc.
  125. # Functions to help us manage paths. Second argument is the name of the
  126. # path variable to be modified (default: PATH)
  127. pathremove () {
  128. local IFS=':'
  129. local NEWPATH
  130. local DIR
  131. local PATHVARIABLE=${2:-PATH}
  132. for DIR in ${!PATHVARIABLE} ; do
  133. if [ "$DIR" != "$1" ] ; then
  134. NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
  135. fi
  136. done
  137. export $PATHVARIABLE="$NEWPATH"
  138. }
  139. pathprepend () {
  140. pathremove $1 $2
  141. local PATHVARIABLE=${2:-PATH}
  142. export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
  143. }
  144. pathappend () {
  145. pathremove $1 $2
  146. local PATHVARIABLE=${2:-PATH}
  147. export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
  148. }
  149. export -f pathremove pathprepend pathappend
  150. # Set the initial path
  151. export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/milis/bin:/usr/milis/mps/bin:/usr/local/bin
  152. # Setup some environment variables.
  153. export HISTSIZE=1000
  154. export HISTIGNORE="&:[bf]g:exit"
  155. # Set some defaults for graphical systems
  156. #export XDG_DATA_DIRS=${XDG_DATA_DIRS:-/usr/share/}
  157. #export XDG_CONFIG_DIRS=${XDG_CONFIG_DIRS:-/etc/xdg/}
  158. #export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/tmp/xdg-$USER}
  159. # Setup a red prompt for root and a green one for users.
  160. NORMAL="\[\e[0m\]"
  161. RED="\[\e[1;31m\]"
  162. GREEN="\[\e[1;32m\]"
  163. if [[ $EUID == 0 ]] ; then
  164. PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
  165. else
  166. PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
  167. fi
  168. for script in /etc/profile.d/*.sh ; do
  169. if [ -r $script ] ; then
  170. . $script
  171. fi
  172. done
  173. unset script RED GREEN NORMAL
  174. # End /etc/profile
  175. EOF
  176. mkdir -p $ROOTDIR/etc/profile.d
  177. cat > $ROOTDIR/etc/profile.d/bash_completion.sh << "EOF"
  178. # Begin /etc/profile.d/bash_completion.sh
  179. # Import bash completion scripts
  180. # If the bash-completion package is installed, use its configuration instead
  181. if [ -f /usr/share/bash-completion/bash_completion ]; then
  182. # Check for interactive bash and that we haven't already been sourced.
  183. if [ -n "${BASH_VERSION-}" -a -n "${PS1-}" -a -z "${BASH_COMPLETION_VERSINFO-}" ]; then
  184. # Check for recent enough version of bash.
  185. if [ ${BASH_VERSINFO[0]} -gt 4 ] || \
  186. [ ${BASH_VERSINFO[0]} -eq 4 -a ${BASH_VERSINFO[1]} -ge 1 ]; then
  187. [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] && \
  188. . "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
  189. if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then
  190. # Source completion code.
  191. . /usr/share/bash-completion/bash_completion
  192. fi
  193. fi
  194. fi
  195. else
  196. # bash-completions are not installed, use only bash completion directory
  197. if shopt -q progcomp; then
  198. for script in /etc/bash_completion.d/* ; do
  199. if [ -r $script ] ; then
  200. . $script
  201. fi
  202. done
  203. fi
  204. fi
  205. # End /etc/profile.d/bash_completion.sh
  206. EOF
  207. cat > $ROOTDIR/etc/profile.d/dircolors.sh << "EOF"
  208. # Setup for /bin/ls and /bin/grep to support color, the alias is in /etc/bashrc.
  209. if [ -f "/etc/dircolors" ] ; then
  210. eval $(dircolors -b /etc/dircolors)
  211. fi
  212. if [ -f "$HOME/.dircolors" ] ; then
  213. eval $(dircolors -b $HOME/.dircolors)
  214. fi
  215. alias ls='ls --color=auto'
  216. alias grep='grep --color=auto'
  217. EOF
  218. cat > $ROOTDIR/etc/profile.d/readline.sh << "EOF"
  219. # Setup the INPUTRC environment variable.
  220. if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then
  221. INPUTRC=/etc/inputrc
  222. fi
  223. export INPUTRC
  224. EOF
  225. cat > $ROOTDIR/etc/profile.d/umask.sh << "EOF"
  226. # By default, the umask should be set.
  227. if [ "$(id -gn)" = "$(id -un)" -a $EUID -gt 99 ] ; then
  228. umask 002
  229. else
  230. umask 022
  231. fi
  232. EOF
  233. cat > $ROOTDIR/etc/profile.d/i18n.sh << "EOF"
  234. # Set up i18n variables
  235. export LANG=tr_TR.UTF-8
  236. EOF
  237. cat > $ROOTDIR/etc/resolv.conf << "EOF"
  238. # Begin /etc/resolv.conf
  239. domain <Your Domain Name>
  240. nameserver <IP address of your primary nameserver>
  241. nameserver <IP address of your secondary nameserver>
  242. # End /etc/resolv.conf
  243. EOF
  244. cat > $ROOTDIR/etc/hosts << "EOF"
  245. # Begin /etc/hosts
  246. 127.0.0.1 localhost
  247. ::1 localhost ip6-localhost ip6-loopback
  248. ff02::1 ip6-allnodes
  249. ff02::2 ip6-allrouters
  250. # End /etc/hosts
  251. EOF
  252. cat > $ROOTDIR/etc/shells << "EOF"
  253. # Begin /etc/shells
  254. /bin/sh
  255. /bin/bash
  256. # End /etc/shells
  257. EOF
  258. echo "milis" > $ROOTDIR/etc/hostname
  259. touch $ROOTDIR/var/log/{btmp,lastlog,faillog,wtmp}
  260. chgrp -v utmp $ROOTDIR/var/log/lastlog
  261. chmod -v 664 $ROOTDIR/var/log/lastlog
  262. chmod -v 600 $ROOTDIR/var/log/btmp
  263. # talimatname yolu
  264. mkdir -p $ROOTDIR/usr/milis/talimatname
  265. # mps
  266. #mkdir -p $ROOTDIR/var/lib/mps/db
  267. #mkdir -p $ROOTDIR/var/log/mps/kur
  268. #mkdir -p $ROOTDIR/var/log/mps/sil