#! /opt/bin/dash # # make public copies of some files # # all secret seeds are replaced with "123456789" TOP="/home/perry/src/fog/os" # with -d option just show differences, no copy # case "$1" in "-d") diff="1"; shift;; *) diff="";; esac check() { # show diffs dest="$1" while read f; do if [ -z "$f" ]; then continue; fi from="$TOP/$f" cmd="diff $from $dest/" echo "$cmd" eval "$cmd" done } copy() { # copy dest="$1" if [ -n "$diff" ]; then check "$dest"; return; fi echo "copy $dest" while read f; do if [ -z "$f" ]; then continue; fi from="$TOP/$f" cmd="cp -p $from $dest/" #echo " $cmd" eval "$cmd" done } link() { # copy/link python files dest="$1" if [ -n "$diff" ]; then return; fi echo "link $dest" while read f; do if [ -z "$f" ]; then continue; fi from="$TOP/$f" cmd="cp -p $from python/" #echo " $cmd" eval "$cmd" cmd="rm -f $dest/$dest.py && ln -s ../python/$dest.py $dest/" #echo " $cmd" eval "$cmd" done } mod() { # copy/modify dest="$1"; e1="$2"; e2="$3" if [ -n "$diff" ]; then check "$dest"; return; fi echo "mod $dest extra: $e1 $e2" while read f; do if [ -z "$f" ]; then continue; fi from="$TOP/$f" to="$dest/"$(basename "$f") #echo "mod $from $to extra: $e1 $e2" if [ -n "$e2" ]; then sed -e 's/\( s[12]*\)="........."/\1="123456789"/g' -e "$e1" -e "$e2" "$from" > "$to" elif [ -n "$e1" ]; then sed -e 's/\( s[12]*\)="........."/\1="123456789"/g' -e "$e1" "$from" > "$to" else sed -e 's/\( s[12]*\)="........."/\1="123456789"/g' "$from" > "$to" fi chmod 755 "$to" touch -r "$from" "$to" done } #--- # just update specified list if [ "$#" -gt 0 ]; then for what do echo "cgi/${what}-check\ncgi/${what}-post" | copy "$what" echo "cgi/${what}\nprog/${what}/post.sh" | mod "$what" done exit fi #--- # standard list and special cases LIST="checksum fsck malloc paging-linear-translate paging-multilevel-translate paging-policy process-run\ relocation scheduler segmentation ssd vsfs" SPECIAL="disk mlfq raid" #--- # copy check, post, and python for what in $LIST $SPECIAL do echo "cgi/${what}-check\ncgi/${what}-post" | copy "$what" echo "python.ORIG/${what}.py" | link "$what" done # echo "cgi/scheduler-public\ncgi/scheduler-public-post\nprog/scheduler/post-public.sh" | copy "scheduler" #--- # modify cgi and post.sh for what in $LIST $SPECIAL do echo "cgi/${what}\nprog/${what}/post.sh" | mod "$what" done #--- # copy python diffs if [ -z "$diff" ]; then cmd="cp -p $TOP/diff DIFF" echo "$cmd" eval "$cmd" fi #-- skip: # special cases, remove non-standard options #-- echo "cgi/disk\nprog/disk/post.sh" | mod "disk" 's/ -d / /' #-- echo "cgi/mlfq\nprog/mlfq/post.sh" | mod "mlfq" 's/ opt=.*//' 's/ $opt//' #-- echo "cgi/raid\nprog/raid/post.sh" | mod "raid" 's/ -d / /'